KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: DCUPComponentManagerRMIStub.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
6 import SOFA.Component.ComponentLifecycleException;
7 import SOFA.Component.NamingException;
8 import SOFA.Component.DCUP.DCUPComponentManager;
9 import SOFA.Connector.ConnectorTransportException;
10 import SOFA.SOFAnode.Run.Storage;
11
12 public class DCUPComponentManagerRMIStub implements DCUPComponentManager {
13
14   private CNDCUPComponentManagerRemoteInterface tgt = null;
15
16   public DCUPComponentManagerRMIStub(String JavaDoc name) throws RemoteException JavaDoc {
17     try {
18       tgt = (CNDCUPComponentManagerRemoteInterface) java.rmi.Naming.lookup(name);
19     } catch (Exception JavaDoc e) {
20       throw new RemoteException JavaDoc("Can't find skeleton", e);
21     }
22   }
23
24   public void createComponent(Storage stateStore) throws ComponentLifecycleException {
25     try {
26       tgt.createComponent(stateStore);
27     } catch (RemoteException JavaDoc e){
28       throw new ConnectorTransportException("Remote exception in the \"createComponent\".", e);
29     }
30   }
31
32   public void destroyComponent(Storage stateStore) throws ComponentLifecycleException {
33
34     try {
35       tgt.destroyComponent(stateStore);
36     } catch (RemoteException JavaDoc e){
37       throw new ConnectorTransportException("Remote exception in the \"destroyComponent\".", e);
38     }
39   }
40
41   public void storeComponent(Storage stateStore) throws ComponentLifecycleException {
42     try {
43       tgt.storeComponent(stateStore);
44     } catch (RemoteException JavaDoc e){
45       throw new ConnectorTransportException("Remote exception in the \"storeComponent\".", e);
46     }
47   }
48
49   public void restoreComponent(Storage stateStore) throws ComponentLifecycleException {
50     try {
51       tgt.restoreComponent(stateStore);
52     } catch (RemoteException JavaDoc e){
53       throw new ConnectorTransportException("Remote exception in the \"restoreComponent\".", e);
54     }
55   }
56
57
58   public void registerSubcomponent(java.lang.String JavaDoc name, SOFA.Connector.Reference target) throws SOFA.Component.NamingException, SOFA.Component.InstantiationException {
59     try {
60       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
61       target._write(os);
62       
63       tgt.registerSubcomponent(name, os.toByteArray());
64
65     } catch (RemoteException JavaDoc e){
66       throw new ConnectorTransportException("Remote exception in the \"registerSubcomponent\".", e);
67     } catch (java.io.IOException JavaDoc e) {
68       throw new ConnectorTransportException("IOException in the \"registerSubcomponent\".", e);
69     }
70   }
71   
72   public void unregisterSubcomponent(java.lang.String JavaDoc name) throws SOFA.Component.NamingException {
73     try {
74       tgt.unregisterSubcomponent(name);
75     } catch (RemoteException JavaDoc e){
76       throw new ConnectorTransportException("Remote exception in the \"unregisterSubcomponent\".", e);
77     }
78   }
79
80
81   public void updateComponent( SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor newDeploymentDescriptor, Storage stateStore) throws ComponentLifecycleException {
82     try {
83       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
84       newDeploymentDescriptor._write(os);
85
86       tgt.updateComponent(os.toByteArray(), stateStore);
87     } catch (RemoteException JavaDoc e){
88       throw new ConnectorTransportException("Remote exception in the \"updateComponent\".", e);
89     } catch (java.io.IOException JavaDoc e) {
90       throw new ConnectorTransportException("IOException in the \"updateComponent\".", e);
91     }
92   }
93
94   public SOFA.Connector.Reference getProvisionReference(String JavaDoc name) throws NamingException {
95     try {
96       byte [] s = tgt.getProvisionReference(name);
97       
98       SOFA.Connector.Reference ref = new SOFA.Connector.Reference ();
99       ref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(s));
100       return ref;
101     } catch (java.rmi.RemoteException JavaDoc e) {
102       throw new ConnectorTransportException("Remote exception in the \"getProvisionReference\".", e);
103     } catch (java.io.IOException JavaDoc e) {
104       throw new ConnectorTransportException("IOException in the \"getProvisionReference\".", e);
105     }
106   }
107   
108   public void setRequirement(String JavaDoc name, SOFA.Connector.Reference ref) throws SOFA.Component.InstantiationException, NamingException {
109     try {
110       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
111       ref._write(os);
112
113       tgt.setRequirement(name, os.toByteArray());
114     } catch (java.rmi.RemoteException JavaDoc e) {
115       throw new ConnectorTransportException("Remote exception in the \"setRequirement\".", e);
116     } catch (java.io.IOException JavaDoc e) {
117       throw new ConnectorTransportException("IOException in the \"setRequirement\".", e);
118     }
119   }
120   
121   public void connectSubsumable() throws NamingException, SOFA.Component.InstantiationException {
122     try {
123       tgt.connectSubsumable();
124     } catch (java.rmi.RemoteException JavaDoc e) {
125       throw new ConnectorTransportException("Remote exception in the \"setRequirement\".", e);
126     }
127   }
128
129   public SOFA.SOFAnode.Run.Deployment.DeplDock getLocalDeplDock() {
130     return null;
131   }
132
133   public String JavaDoc getFullName() {
134     try {
135       return tgt.getFullName();
136     } catch (java.rmi.RemoteException JavaDoc e) {
137       throw new ConnectorTransportException("Remote exception in the \"setRequirement\".", e);
138     }
139   }
140
141   public boolean isUpdatable() {
142     try {
143       return tgt.isUpdatable();
144     } catch (java.rmi.RemoteException JavaDoc e) {
145       throw new ConnectorTransportException("Remote exception in the \"setRequirement\".", e);
146     }
147   }
148
149   public Object JavaDoc[] getFcInterfaces() {
150     try {
151       byte [][][] s = tgt.getFcInterfaces();
152       Object JavaDoc[] ret = new Object JavaDoc [s.length];
153       for (int i = 0; i<s.length; i++) {
154         String JavaDoc type = new String JavaDoc(s[i][0]);
155         SOFA.Connector.Reference ref = new SOFA.Connector.Reference ();
156         ref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(s[i][1]));
157         ret[i] = Helper.createCltConn(type, ref);
158       }
159       return ret;
160     } catch (java.rmi.RemoteException JavaDoc e) {
161       throw new ConnectorTransportException("Remote exception in the \"getFcInterfaces\".", e);
162     } catch (java.io.IOException JavaDoc e) {
163       throw new ConnectorTransportException("IOException in the \"getFcInterfaces\".", e);
164     }
165   }
166   
167   public Object JavaDoc getFcInterface(java.lang.String JavaDoc itfName) throws org.objectweb.fractal.api.NoSuchInterfaceException {
168     try {
169       byte [][] s = tgt.getFcInterface(itfName);
170       String JavaDoc type = new String JavaDoc(s[0]);
171       SOFA.Connector.Reference ref = new SOFA.Connector.Reference ();
172       ref._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(s[1]));
173       return Helper.createCltConn(type, ref);
174     } catch (java.rmi.RemoteException JavaDoc e) {
175       throw new ConnectorTransportException("Remote exception in the \"getFcInterface\".", e);
176     } catch (java.io.IOException JavaDoc e) {
177       throw new ConnectorTransportException("IOException in the \"getFcInterface\".", e);
178     }
179   }
180   
181   public org.objectweb.fractal.api.Type getFcType() {
182     return null;
183   }
184   
185   public boolean isFcSubtypeOf(org.objectweb.fractal.api.Type t) {
186     if (t instanceof SOFA.Connector.RoleBase) {
187       try {
188         SOFA.Connector.Reference ref = ((SOFA.Connector.RoleBase) t).getSOFAReference();
189         ref = DeplDockRMISkel.removeLocal(ref);
190         cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
191         try {
192           os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
193           ref._write(os);
194         } catch (java.io.IOException JavaDoc e) {
195           throw new ConnectorTransportException("Can't serialize in the \"isFcSubtypeOf\".", e);
196         }
197         return tgt.isFcSubtypeOf(os.toByteArray());
198       } catch (java.rmi.RemoteException JavaDoc e) {
199         throw new ConnectorTransportException("Remote exception in the \"isFcSubtypeOf\".", e);
200       }
201
202     } else
203       throw new ConnectorTransportException("Cannot get reference to the type");
204   }
205
206
207 }
208
Popular Tags