KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: DeplDockRMISkel.java,v 1.1.1.1 2003/02/11 16:19:40 bures Exp $ */
2 package SOFA.Connector.Boot;
3
4 import SOFA.Connector.ConnectorTransportException;
5
6 /** RMI skeleton for depldock connector.
7   *
8   * @author Petr Hnetynka
9   */

10 public class DeplDockRMISkel extends java.rmi.server.UnicastRemoteObject JavaDoc implements CNDeplDockRemote, SOFA.Connector.Linkable {
11   
12   private CNDeplDock tgt = null;
13   
14   public DeplDockRMISkel(String JavaDoc url) throws java.rmi.RemoteException JavaDoc, java.net.MalformedURLException JavaDoc, java.rmi.NotBoundException JavaDoc {
15     super();
16     String JavaDoc rmihost = System.getProperty("sofa.rmihost", "localhost");
17     String JavaDoc rmiport = System.getProperty("sofa.rmiport", "1099");
18     SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock rg = (SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock) java.rmi.Naming.lookup("//"+rmihost+":"+rmiport+"/RgRMIDock");
19     rg.rebind("/SOFA/Connectors/Boot/DeplDockRMISkel/"+url, this);
20 // java.rmi.Naming.rebind("rmi://"+rmihost+":"+rmiport+"/SOFA/Connectors/Boot/DeplDockRMISkel/"+url, this);
21
}
22
23   public void link(Object JavaDoc target) {
24     tgt = (CNDeplDock) target;
25   }
26   
27   public byte[][] describeUnderlyingEnvironment() throws java.rmi.RemoteException JavaDoc {
28     SOFA.SOFAnode.Run.Deployment.TechnologyDescriptor[] td = tgt.describeUnderlyingEnvironment();
29     byte[][] ret = new byte [td.length] [];
30     try {
31       for (int i=0; i<td.length; i++) {
32         cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
33         td[i]._write(os);
34         ret[i] = os.toByteArray();
35       }
36     } catch (java.io.IOException JavaDoc e) {
37       throw new ConnectorTransportException("Can't serialize in the describeUnderlyingEnvironment.", e);
38     }
39     return ret;
40   }
41
42   public byte[] instantiate(byte[] dd, String JavaDoc name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException JavaDoc {
43     SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl ddr = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl();
44     try {
45       ddr._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(dd));
46     } catch (java.io.IOException JavaDoc e) {
47       throw new ConnectorTransportException("Can't serialize in the instantiate.", e);
48     }
49     
50     SOFA.Connector.Reference ref = tgt.instantiate(ddr, name);
51     
52     ref = removeLocal(ref);
53     cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
54     try {
55       os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
56       ref._write(os);
57     } catch (java.io.IOException JavaDoc e) {
58       throw new ConnectorTransportException("Can't serialize in the instantiate.", e);
59     }
60     return os.toByteArray();
61   }
62
63   public byte[] getReference(String JavaDoc name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException JavaDoc {
64   
65     SOFA.Connector.Reference ref = tgt.getReference(name);
66     
67     ref = removeLocal(ref);
68     cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null;
69     try {
70       os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
71       ref._write(os);
72     } catch (java.io.IOException JavaDoc e) {
73       throw new ConnectorTransportException("Can't serialize in the getReference.", e);
74     }
75     return os.toByteArray();
76   }
77
78
79   public String JavaDoc[] namesOfAllRunningComponents() {
80     return tgt.namesOfAllRunningComponents();
81   }
82   
83   public String JavaDoc[] namesOfAllRunningApplications() {
84     return tgt.namesOfAllRunningApplications();
85   }
86
87   public void removeComponent(String JavaDoc name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException JavaDoc {
88     tgt.removeComponent(name);
89   }
90
91   /** Remove LOCAL profile from reference. */
92   public static SOFA.Connector.Reference removeLocal(SOFA.Connector.Reference ref) {
93     boolean b = false;
94     for(int i=0; i<ref.profiles.length; i++) {
95       if (ref.profiles[i] instanceof SOFA.Connector.ECG.Profiles.LocalProfile) {
96         b = true;
97       }
98     }
99     if (b) {
100       SOFA.Connector.TaggedProfile[] p = new SOFA.Connector.TaggedProfile [ref.profiles.length];
101       int j = 0;
102       for (int i=0; i<ref.profiles.length; i++) {
103         if (!(ref.profiles[i] instanceof SOFA.Connector.ECG.Profiles.LocalProfile)) {
104           p[j] = ref.profiles[i];
105           j++;
106         }
107       }
108       ref.profiles = p;
109     }
110     return ref;
111   }
112 }
113
Popular Tags