| 1 | // |
| 2 | // (c) Copyright, Moebius Solutions, 2002 |
| 3 | // |
| 4 | // All Rights Reserved |
| 5 | // |
| 6 | // This material may be reproduced by or for the U. S. Government |
| 7 | // pursuant to the copyright license under the clause at |
| 8 | // DFARS 252.227-7013 (OCT 1988). |
| 9 | // |
| 10 | /* |
| 11 | * $Id: JniDoParamsVisitor.java,v 1.1.1.5 2004/05/25 20:23:29 hastings Exp $ |
| 12 | */ |
| 13 | package com.moesol.generator; |
| 14 | |
| 15 | import java.io.*; |
| 16 | import com.moesol.generator.core.*; |
| 17 | import com.moesol.generator.printer.*; |
| 18 | import com.moesol.generator.visitor.*; |
| 19 | |
| 20 | public class JniDoParamsVisitor implements ParamTypeVisitor{ |
| 21 | public JniDoParamsVisitor(Writer out, TranslationContext ctx) { |
| 22 | this.out = out; |
| 23 | m_trans_ctx = ctx; |
| 24 | } |
| 25 | public void visitParamType(Class c, int nparam, Class paramType) throws ApplyException { |
| 26 | try { |
| 27 | out.write(", "); |
| 28 | out.write(getTranslatedParam(paramType)); |
| 29 | out.write(" p"); |
| 30 | out.write(Integer.toString(nparam)); |
| 31 | } catch (IOException e) { |
| 32 | throw new ApplyException(e); |
| 33 | } |
| 34 | } |
| 35 | public void visitParamSeparator(Class c) throws ApplyException { |
| 36 | } |
| 37 | |
| 38 | /* TODO refactor */ |
| 39 | String getTranslatedParam(Class paramType) throws IOException, ApplyException { |
| 40 | StringWriter sw = new StringWriter(); |
| 41 | JavaTypePrinter.getInstance().print(paramType, sw); |
| 42 | String trans = m_trans_ctx.getProperty("jni.do.type." + sw.toString()); |
| 43 | if (trans != null) { |
| 44 | // found a translation |
| 45 | return trans; |
| 46 | } |
| 47 | |
| 48 | sw = new StringWriter(); |
| 49 | JniTypePrinter.getInstance().print(paramType, sw); |
| 50 | return sw.toString(); |
| 51 | } |
| 52 | |
| 53 | private Writer out; |
| 54 | private TranslationContext m_trans_ctx; |
| 55 | } |