1 6 7 package SOFA.Connector.EEG.EEM.Actions; 8 9 import SOFA.Connector.EEG.CodeWriter.CDL2JavaMapping; 10 import SOFA.Connector.EEG.CodeWriter.CodeWriterException; 11 import SOFA.Connector.EEG.CodeWriter.JWriterDirector; 12 import SOFA.Connector.EEG.CodeWriter.JWriterDirectorException; 13 import SOFA.SOFAnode.Made.TIR.CDLType; 14 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 15 import SOFA.SOFAnode.Made.TIR.OperationDef; 16 import SOFA.SOFAnode.Made.TIR.ParamMode; 17 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 18 import SOFA.SOFAnode.Made.TIR.PrimitiveKind; 19 20 25 public class JImplWriterDirectorBase implements JWriterDirector { 26 protected SOFA.Connector.Property[] params; 27 protected String provIfaceCDL; 28 29 30 public JImplWriterDirectorBase(String provIfaceCDL, SOFA.Connector.Property[] params) { 31 this.provIfaceCDL=provIfaceCDL; 32 this.params=params; 33 } 34 35 public JImplWriterDirectorBase(SOFA.Connector.Property[] params) { 36 this.params=params; 37 } 38 39 protected String targetCall(OperationDef method, String params) throws JWriterDirectorException { 40 try { 41 StringBuffer ret=new StringBuffer (); 42 ret.append("this.target."+method.get_identification().name()+"("); 43 ret.append(params); 44 ret.append(")"); 45 return ret.toString(); 46 } catch (java.rmi.RemoteException e) { 47 throw new JWriterDirectorException("Cannot access TIR.",e); 48 } 49 } 50 51 protected String declareRet(OperationDef method, String retName) throws JWriterDirectorException { 52 try { 53 CDLType retType=method.result(); 54 if (!(retType.get_def_kind().value()==DefinitionKind.dk_Primitive && 55 ((PrimitiveDef)retType).kind().value()==PrimitiveKind.pk_void)) { 56 return CDL2JavaMapping.getTypeName(retType,ParamMode.PARAM_IN)+" "+retName+";"; 57 } 58 return ""; 59 } catch (java.rmi.RemoteException e) { 60 throw new JWriterDirectorException("Cannot access TIR.",e); 61 } catch (CodeWriterException e) { 62 throw new JWriterDirectorException("Cannot map type.",e); 63 } 64 } 65 66 protected String assignRet(OperationDef method, String retName) throws JWriterDirectorException { 67 try { 68 CDLType retType=method.result(); 69 if (!(retType.get_def_kind().value()==DefinitionKind.dk_Primitive && 70 ((PrimitiveDef)retType).kind().value()==PrimitiveKind.pk_void)) { 71 return retName+"="; 72 } 73 return ""; 74 } catch (java.rmi.RemoteException e) { 75 throw new JWriterDirectorException("Cannot access TIR.",e); 76 } 77 } 78 79 protected String returnRet(OperationDef method, String retName) throws JWriterDirectorException { 80 try { 81 CDLType retType=method.result(); 82 if (!(retType.get_def_kind().value()==DefinitionKind.dk_Primitive && 83 ((PrimitiveDef)retType).kind().value()==PrimitiveKind.pk_void)) { 84 return "return "+retName+";"; 85 } 86 return "return;"; 87 } catch (java.rmi.RemoteException e) { 88 throw new JWriterDirectorException("Cannot access TIR.",e); 89 } 90 } 91 92 protected String managerTieImpl() { 93 return "\tprotected SOFA.Connector.EEG.ConnectorManagerInterface manager;\n"+ 94 "\n"+ 95 "\tpublic void setManagerTie(SOFA.Connector.EEG.ConnectorManagerInterface manager) {\n"+ 96 "\t\tthis.manager=manager;\n"+ 97 "\t}\n"+ 98 "\n"+ 99 "\tpublic SOFA.Connector.EEG.ConnectorManagerInterface getManagerTie() {\n"+ 100 "\t\treturn manager;\n"+ 101 "\t}\n"; 102 } 103 104 protected String linkImpl() { 105 String reqIface=SOFA.Connector.Property.findFirst(params,"reqIfaceMapped"); 106 return "\tprotected "+reqIface+" target;\n"+ 107 "\n"+ 108 "\tpublic void link(Object target) {\n"+ 109 "\t\tthis.target=("+reqIface+")target;\n"+ 110 "\t}\n"; 111 } 112 113 public String [] getImplements() throws JWriterDirectorException { 114 return null; 115 } 116 117 public String getClassBody() throws JWriterDirectorException { 118 return linkImpl()+"\n"+managerTieImpl(); 119 } 120 121 public String getExtends() throws JWriterDirectorException { 122 return null; 123 } 124 125 public String getMethodDef(OperationDef mt) throws JWriterDirectorException { 126 return JIfaceNormal.getMethodDef(mt); 127 } 128 129 public String getMethodBody(OperationDef method) throws JWriterDirectorException { 130 return 131 "\t\t"+declareRet(method,"ret")+"\n"+ 132 "\t\t"+assignRet(method,"ret")+targetCall(method,JIfaceNormal.targetCallParams(method))+";\n"+ 133 "\t\t"+returnRet(method,"ret"); 134 } 135 136 public boolean defaultImplements() { 137 return true; 138 } 139 } 140 | Popular Tags |