KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * RMISkeletonGen.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.JWriterDirectorException;
10 import SOFA.Connector.EEG.EEM.Actions.JIfaceCN;
11 import SOFA.Connector.EEG.EEM.Actions.JIfaceCNRMI;
12 import SOFA.Connector.EEG.EEM.Actions.JImplWriterDirectorBase;
13 import SOFA.SOFAnode.Made.TIR.OperationDef;
14
15 /**
16  *
17  * @author ghort
18  * @version
19  */

20 public class RMISkeletonGen extends JImplWriterDirectorBase {
21
22     /** Creates new RMISkeletonGen */
23     public RMISkeletonGen(String JavaDoc provIfaceCDL, SOFA.Connector.Property[] params) {
24         super(provIfaceCDL,params);
25     }
26
27     public String JavaDoc getExtends() {
28         return "java.rmi.server.UnicastRemoteObject";
29     }
30
31     public String JavaDoc[] getImplements() {
32         return new String JavaDoc[] {"SOFA.Connector.EEG.Types.Skeleton"};
33     }
34     
35     public String JavaDoc getClassBody() {
36         return managerTieImpl() + "\n" + linkImpl() + "\n" +
37             "\tprotected String rmiURL;\n\n"+
38             "\tpublic RMISkeleton() throws SOFA.Connector.ConnectorException, java.rmi.RemoteException {\n"+
39             "\t\tsuper();\n"+
40             "\t\ttry {\n"+
41             "\t\t\tString rmihost = System.getProperty(\"sofa.rmihost\", \"localhost\");\n"+
42             "\t\t\tString rmiport = System.getProperty(\"sofa.rmiport\", \"1099\");\n"+
43                         "\t\t\tSOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock rg = (SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock) java.rmi.Naming.lookup(\"//\"+rmihost+\":\"+rmiport+\"/RgRMIDock\");\n"+
44                         "\t\t\tString xID = new java.rmi.server.UID().toString();\n"+
45                         "\t\t\trg.rebind(\"/SOFA/Connectors/EEG/EEM/Elements/RMISkeleton/\"+xID, this);\n"+
46             "\t\t\trmiURL=\"rmi://\"+rmihost+\":\"+rmiport+\"/SOFA/Connectors/EEG/EEM/Elements/RMISkeleton/\"+xID;\n"+
47 // "\t\t\tjava.rmi.Naming.rebind(rmiURL,this);\n"+
48
"\t\t} catch (Exception e) {\n"+
49             "\t\t\tthrow new SOFA.Connector.ConnectorException(\"Can't bind RMISkeleton to '\"+rmiURL+\"'.\",e);\n"+
50             "\t\t}\n"+
51             "\t}\n\n"+
52             "\tpublic SOFA.Connector.TaggedProfile[] getProfiles() {\n"+
53             "\t\treturn new SOFA.Connector.TaggedProfile[] { new SOFA.Connector.ECG.Profiles.RMIProfile(rmiURL) };\n"+
54             "\t}\n\n"+
55                         "\tpublic String getFcItfName() throws java.rmi.RemoteException { return this.target.getFcItfName(); }\n\n"+
56                         "\tpublic byte[] getFcItfOwner() throws java.rmi.RemoteException {\n"+
57                         "\t\tSOFA.Connector.Reference ref = ((SOFA.Connector.RoleBase) this.target.getFcItfOwner()).getSOFAReference();\n"+
58                         "\t\tref = SOFA.Connector.Boot.DeplDockRMISkel.removeLocal(ref);\n"+
59                         "\t\tcz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;\n"+
60                         "\t\ttry {\n"+
61                         "\t\t\tos = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();\n"+
62                         "\t\t\tref._write(os);\n"+
63                         "\t\t} catch (java.io.IOException e) {\n"+
64                         "\t\t\tthrow new SOFA.Connector.ConnectorTransportException(\"Can't serialize in the \\\"getFcItfOwner\\\".\", e);\n"+
65                         "\t\t}\n"+
66                         "\t\treturn os.toByteArray();\n"+
67                         "\t}\n\n";
68     }
69
70     public String JavaDoc getMethodDef(OperationDef mt) throws JWriterDirectorException {
71         return JIfaceCNRMI.getMethodDef(mt);
72     }
73
74     public String JavaDoc getMethodBody(OperationDef method) throws JWriterDirectorException {
75         return
76             "\t\t"+declareRet(method,"ret")+"\n"+
77             "\t\t"+assignRet(method,"ret")+targetCall(method,JIfaceCN.targetCallParams(method))+";\n"+
78             "\t\t"+returnRet(method,"ret");
79     }
80 }
81
Popular Tags