KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > EEM > Elements > CORBASkeletonGen


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

6
7 package SOFA.Connector.EEG.EEM.Elements;
8
9 import SOFA.Connector.EEG.CodeWriter.CDL2JavaMapping;
10 import SOFA.Connector.EEG.CodeWriter.CodeWriterException;
11 import SOFA.Connector.EEG.CodeWriter.JWriterDirectorException;
12 import SOFA.Connector.EEG.EEM.Actions.JIfaceCN;
13 import SOFA.Connector.EEG.EEM.Actions.JIfaceCNCORBA;
14 import SOFA.Connector.EEG.EEM.Actions.JImplWriterDirectorBase;
15 import SOFA.SOFAnode.Made.TIR.OperationDef;
16 import SOFA.SOFAnode.Made.TIR.ParamDescr;
17 import SOFA.SOFAnode.Made.TIR.ParamMode;
18 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
19
20 /**
21  *
22  * @author ghort
23  * @version
24  */

25 public class CORBASkeletonGen extends JImplWriterDirectorBase {
26
27     /** Creates new CORBASkeletonGen */
28     public CORBASkeletonGen(String JavaDoc provIfaceCDL, SOFA.Connector.Property[] params) {
29         super(provIfaceCDL,params);
30     }
31
32     public String JavaDoc getExtends() {
33         String JavaDoc corbaIface=SOFA.Connector.Property.findFirst(params,"provIfaceMapped");
34         return corbaIface+"POA";
35     }
36
37     public String JavaDoc[] getImplements() {
38         return new String JavaDoc[] {"SOFA.Connector.EEG.Types.Skeleton"};
39     }
40
41     public boolean defaultImplements() {
42         return false;
43     }
44     
45     public String JavaDoc getClassBody() {
46         return managerTieImpl() + "\n" + linkImpl() + "\n" +
47             "\tprotected String corbaIOR;\n"+
48             "\tprotected org.omg.CORBA.Object corbaObject;\n\n"+
49             "\tpublic CORBASkeleton() throws SOFA.Connector.ConnectorException {\n"+
50             "\t\tsuper();\n"+
51             "\t\ttry {\n"+
52             "\t\t\tcorbaObject=SOFA.Util.CORBAAccess.activate_object(this);\n"+
53             "\t\t\tcorbaIOR=SOFA.Util.CORBAAccess.object_to_string(corbaObject);\n"+
54             "\t\t} catch (Exception e) {\n"+
55             "\t\t\tthrow new SOFA.Connector.ConnectorException(\"Can't bind CORBASkeleton to '\"+corbaIOR+\"'.\",e);\n"+
56             "\t\t}\n"+
57             "\t}\n\n"+
58             "\tpublic SOFA.Connector.TaggedProfile[] getProfiles() {\n"+
59             "\t\treturn new SOFA.Connector.TaggedProfile[] { new SOFA.Connector.ECG.Profiles.CORBAProfile(corbaIOR) };\n"+
60             "\t}\n";
61     }
62
63     public String JavaDoc getMethodDef(OperationDef mt) throws JWriterDirectorException {
64         return JIfaceCNCORBA.getMethodDef(mt);
65     }
66
67     public String JavaDoc getMethodBody(OperationDef method) throws JWriterDirectorException {
68         try {
69             String JavaDoc ret="";
70
71             int i;
72             ParamDescr[] params=method.params();
73
74             for (i=0;i<params.length;i++) {
75                 int mode=params[i].mode().value();
76                 if (mode==ParamMode.PARAM_INOUT || mode==ParamMode.PARAM_OUT) {
77                     String JavaDoc holderName=CDL2JavaMapping.getTypeName(params[i].type(),mode);
78                     ret+="\t\t"+holderName+" "+params[i].name()+"=new "+holderName+"(); "+params[i].name()+".value=_corbaholder_"+params[i].name()+".value;\n";
79                 }
80             }
81
82             ret+="\t\t"+declareRet(method,"ret")+"\n"+
83                 "\t\t"+assignRet(method,"ret")+targetCall(method,JIfaceCN.targetCallParams(method))+";\n";
84
85             for (i=0;i<params.length;i++) {
86                 int mode=params[i].mode().value();
87                 if (mode==ParamMode.PARAM_INOUT || mode==ParamMode.PARAM_OUT) {
88                     ret+="\t\t_corbaholder_"+params[i].name()+".value="+params[i].name()+".value;\n";
89                 }
90             }
91             
92             ret+="\t\t"+returnRet(method,"ret")+"\n";
93
94             return ret;
95
96         } catch (java.rmi.RemoteException JavaDoc e) {
97             throw new JWriterDirectorException("Cannot access TIR.",e);
98         } catch (TIRExceptLock e) {
99             throw new JWriterDirectorException("Cannot access TIR.",e);
100         } catch (CodeWriterException e) {
101             throw new JWriterDirectorException("Cannot map operation to Java.",e);
102         }
103     }
104 }
105
Popular Tags