KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > EEM > Actions > JImplWriterDirectorBase


1 /*
2  * JImplWriterDirectorBase.java
3  *
4  * Created on 13. duben 2002, 21:08
5  */

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 /**
21  *
22  * @author ghort
23  * @version
24  */

25 public class JImplWriterDirectorBase implements JWriterDirector {
26     protected SOFA.Connector.Property[] params;
27     protected String JavaDoc provIfaceCDL;
28
29     /** Creates new JImplWriterDirectorBase */
30     public JImplWriterDirectorBase(String JavaDoc 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 JavaDoc targetCall(OperationDef method, String JavaDoc params) throws JWriterDirectorException {
40         try {
41             StringBuffer JavaDoc ret=new StringBuffer JavaDoc();
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 JavaDoc e) {
47             throw new JWriterDirectorException("Cannot access TIR.",e);
48         }
49     }
50     
51     protected String JavaDoc declareRet(OperationDef method, String JavaDoc 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 JavaDoc 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 JavaDoc assignRet(OperationDef method, String JavaDoc 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 JavaDoc e) {
75             throw new JWriterDirectorException("Cannot access TIR.",e);
76         }
77     }
78
79     protected String JavaDoc returnRet(OperationDef method, String JavaDoc 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 JavaDoc e) {
88             throw new JWriterDirectorException("Cannot access TIR.",e);
89         }
90     }
91
92     protected String JavaDoc 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 JavaDoc linkImpl() {
105         String JavaDoc 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 JavaDoc[] getImplements() throws JWriterDirectorException {
114         return null;
115     }
116      
117     public String JavaDoc getClassBody() throws JWriterDirectorException {
118         return linkImpl()+"\n"+managerTieImpl();
119     }
120      
121     public String JavaDoc getExtends() throws JWriterDirectorException {
122         return null;
123     }
124      
125     public String JavaDoc getMethodDef(OperationDef mt) throws JWriterDirectorException {
126         return JIfaceNormal.getMethodDef(mt);
127     }
128
129     public String JavaDoc 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