KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > Boot > DCUPComponentManagerRMISkeleton


1 /* $Id: DCUPComponentManagerRMISkeleton.java,v 1.3 2004/05/20 14:23:50 bures Exp $ */
2 package SOFA.Connector.Boot;
3
4 import java.rmi.RemoteException JavaDoc;
5 import java.rmi.server.UnicastRemoteObject JavaDoc;
6
7 import SOFA.Component.ComponentLifecycleException;
8 import SOFA.Component.DCUP.DCUPComponentManager;
9 import SOFA.Connector.ConnectorTransportException;
10 import SOFA.Connector.Linkable;
11 import SOFA.Connector.RoleBase;
12 import SOFA.SOFAnode.Run.Storage;
13
14 public class DCUPComponentManagerRMISkeleton extends UnicastRemoteObject JavaDoc implements CNDCUPComponentManagerRemoteInterface, Linkable {
15
16   private DCUPComponentManager tgt = null;
17
18   public DCUPComponentManagerRMISkeleton(String JavaDoc name) throws RemoteException JavaDoc {
19     super();
20     try {
21       String JavaDoc rmihost = System.getProperty("sofa.rmihost", "localhost");
22       String JavaDoc rmiport = System.getProperty("sofa.rmiport", "1099");
23       SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock rg = (SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock) java.rmi.Naming.lookup("//"+rmihost+":"+rmiport+"/RgRMIDock");
24     rg.rebind("/SOFA/Connectors/Boot/DCUPComponentManagerRMISkeleton/"+name, this);
25 // java.rmi.Naming.rebind(name, this);
26
} catch (Exception JavaDoc e) {
27       throw new RemoteException JavaDoc("Can't create DCUPComponentManagerRMISkeleton", e) ;
28     }
29   }
30
31   public void link(Object JavaDoc target) {
32     tgt = (DCUPComponentManager) target;
33   }
34
35   public void createComponent(Storage stateStore) throws ComponentLifecycleException, RemoteException JavaDoc {
36     tgt.createComponent(stateStore);
37   }
38
39   public void destroyComponent(Storage stateStore) throws ComponentLifecycleException, RemoteException JavaDoc {
40     tgt.destroyComponent(stateStore);
41   }
42
43   public void storeComponent(Storage stateStore) throws ComponentLifecycleException, RemoteException JavaDoc {
44     tgt.storeComponent(stateStore);
45   }
46
47   public void restoreComponent(Storage stateStore) throws ComponentLifecycleException, RemoteException JavaDoc {
48     tgt.restoreComponent(stateStore);
49   }
50
51
52   public void updateComponent( byte[] newDeploymentDescriptor, Storage stateStore) throws ComponentLifecycleException, RemoteException JavaDoc {
53     SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl ddr = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl();
54     try {
55       ddr._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(newDeploymentDescriptor));
56     } catch (java.io.IOException JavaDoc e) {
57       throw new ConnectorTransportException("Can't serialize in the \"updateComponent\".", e);
58     }
59
60     tgt.updateComponent(ddr, stateStore);
61   }
62
63   public void registerSubcomponent(java.lang.String JavaDoc name, byte[] target) throws SOFA.Component.NamingException, SOFA.Component.InstantiationException, RemoteException JavaDoc {
64     SOFA.Connector.Reference ref = new SOFA.Connector.Reference();
65     try {
66       ref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(target));
67     } catch (java.io.IOException JavaDoc e) {
68       throw new ConnectorTransportException("Can't serialize in the \"registerSubcomponent\".", e);
69     }
70
71     tgt.registerSubcomponent(name, ref);
72   }
73   
74   public void unregisterSubcomponent(java.lang.String JavaDoc name) throws SOFA.Component.NamingException, RemoteException JavaDoc {
75     tgt.unregisterSubcomponent(name);
76   }
77   
78   public byte[] getProvisionReference(String JavaDoc name) throws SOFA.Component.NamingException, RemoteException JavaDoc {
79     SOFA.Connector.Reference ref = tgt.getProvisionReference(name);
80     
81     ref = DeplDockRMISkel.removeLocal(ref);
82     cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
83     try {
84       os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
85       ref._write(os);
86     } catch (java.io.IOException JavaDoc e) {
87       throw new ConnectorTransportException("Can't serialize in the \"getProvisionReference\".", e);
88     }
89     return os.toByteArray();
90   }
91   
92   public void setRequirement(String JavaDoc name, byte[] ref) throws SOFA.Component.InstantiationException, SOFA.Component.NamingException, RemoteException JavaDoc {
93     SOFA.Connector.Reference rref = new SOFA.Connector.Reference();
94     try {
95       rref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(ref));
96     } catch (java.io.IOException JavaDoc e) {
97       throw new ConnectorTransportException("Can't serialize in the \"registerSubcomponent\".", e);
98     }
99     tgt.setRequirement(name, rref);
100   }
101   
102   public void connectSubsumable() throws SOFA.Component.NamingException, SOFA.Component.InstantiationException, RemoteException JavaDoc {
103     tgt.connectSubsumable();
104   }
105
106   public SOFA.SOFAnode.Run.Deployment.DeplDock getLocalDeplDock() {
107     return null;
108   }
109
110   public String JavaDoc getFullName() {
111     return tgt.getFullName();
112   }
113
114   public boolean isUpdatable() {
115     return tgt.isUpdatable();
116   }
117
118   public byte[][][] getFcInterfaces() throws RemoteException JavaDoc {
119     Object JavaDoc[] obs = tgt.getFcInterfaces();
120     byte[][][] ret = new byte [obs.length][2][];
121     for (int i=0; i<obs.length; i++) {
122       SOFA.Connector.Reference ref = ((RoleBase) obs[i]).getSOFAReference();
123       ref = DeplDockRMISkel.removeLocal(ref);
124       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
125       try {
126         os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
127         ref._write(os);
128       } catch (java.io.IOException JavaDoc e) {
129         throw new ConnectorTransportException("Can't serialize in the \"getFcInterfaces\".", e);
130       }
131       String JavaDoc s = Helper.getCDLNameOfObject(obs[i]);
132       ret[i][0] = s==null?null:s.getBytes();
133       ret[i][1] = os.toByteArray();
134     }
135     return ret;
136   }
137   
138   public byte[][] getFcInterface(java.lang.String JavaDoc itfName) throws org.objectweb.fractal.api.NoSuchInterfaceException, RemoteException JavaDoc {
139     RoleBase rb = (RoleBase) tgt.getFcInterface(itfName);
140     SOFA.Connector.Reference ref = rb.getSOFAReference();
141     
142     byte[][] ret = new byte [2][];
143     ref = DeplDockRMISkel.removeLocal(ref);
144     cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
145     try {
146       os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
147       ref._write(os);
148     } catch (java.io.IOException JavaDoc e) {
149       throw new ConnectorTransportException("Can't serialize in the \"getFcInterface\".", e);
150     }
151     String JavaDoc s = Helper.getCDLNameOfObject(rb);
152     ret[0] = s==null?null:s.getBytes();
153     ret[1] = os.toByteArray();
154     return ret;
155   }
156   
157   public byte[] getFcType() throws RemoteException JavaDoc {
158     SOFA.Connector.Reference ref = ((RoleBase) tgt.getFcType()).getSOFAReference();
159     
160     ref = DeplDockRMISkel.removeLocal(ref);
161     cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
162     try {
163       os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
164       ref._write(os);
165     } catch (java.io.IOException JavaDoc e) {
166       throw new ConnectorTransportException("Can't serialize in the \"getFcInterface\".", e);
167     }
168     return os.toByteArray();
169   }
170
171   public boolean isFcSubtypeOf(byte[] t) throws RemoteException JavaDoc {
172     SOFA.Connector.Reference rref = new SOFA.Connector.Reference();
173     try {
174       rref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(t));
175     } catch (java.io.IOException JavaDoc e) {
176       throw new ConnectorTransportException("Can't deserialize in the \"isFcSubtype\".", e);
177     }
178     try {
179       return tgt.isFcSubtypeOf((SOFA.Component.DCUP.DCUPComponentManager) DCUPComponentManagerConnector.createClt(rref));
180     } catch (SOFA.Connector.ConnectorException e) {
181       throw new ConnectorTransportException("Cannot create connector to the type.", e);
182     }
183   }
184
185 }
186
Popular Tags