KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > TR > Connector > TR2InOutRMIStub


1 /**
2  * TR2InOutRMIStub.java is a part of the SOFA project.
3  * This file was created by pepan on 19.3.2003.
4  */

5 package SOFA.SOFAnode.TR.Connector;
6
7 import java.io.IOException JavaDoc;
8 import java.rmi.RemoteException JavaDoc;
9
10 import SOFA.Connector.ConnectorTransportException;
11 import SOFA.SOFAnode.InOut.Bundle;
12 import SOFA.SOFAnode.TR.ComponentInfo;
13 import SOFA.SOFAnode.TR.TRException;
14 import SOFA.SOFAnode.TR.Impl.BundleImpl;
15
16 /**
17  * @author Petr Panuska
18  */

19 public class TR2InOutRMIStub implements CNTR2InOut {
20
21   private CNTR2InOutRemote target;
22
23   public TR2InOutRMIStub (String JavaDoc url) throws java.rmi.RemoteException JavaDoc {
24     try {
25       target = (CNTR2InOutRemote) java.rmi.Naming.lookup(url);
26     } catch (java.net.MalformedURLException JavaDoc e) {
27       throw new java.rmi.RemoteException JavaDoc("Can't create CNTR2InOutRemote.\n" + url + "\n", e);
28     } catch (java.rmi.NotBoundException JavaDoc e) {
29       throw new java.rmi.RemoteException JavaDoc("Can't create CNTR2InOutRemote.\n" + url + "\n", e);
30     }
31   }
32
33   public void storeBundle (Bundle bundle) throws TRException {
34     byte[] ret = null;
35     try {
36       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
37       ((BundleImpl) bundle)._write(os);
38       ret = os.toByteArray();
39       target.storeBundle(ret);
40     } catch (IOException JavaDoc e) {
41       throw new ConnectorTransportException("Can't serialize in the 'TR2InOutRMIStub.getBundle'.", e);
42     }
43   }
44
45   public Bundle getBundle (ComponentInfo[] descs, ComponentInfo[] comps, boolean inferiors) throws TRException {
46     try {
47       byte[] s = target.getBundle(descs, comps, inferiors);
48       BundleImpl bundle = new BundleImpl();
49       bundle._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(s));
50       return bundle;
51     } catch (java.rmi.RemoteException JavaDoc e) {
52       throw new ConnectorTransportException("Remote exception in the 'TR2InOutRMIStub.getBundle'.", e);
53     } catch (java.io.IOException JavaDoc e) {
54       throw new ConnectorTransportException("IOException in the 'TR2InOutRMIStub.getBundle'.", e);
55     }
56   }
57
58   public boolean contains (ComponentInfo descrs) {
59     try {
60       return target.contains(descrs);
61     } catch (RemoteException JavaDoc e) {
62       throw new ConnectorTransportException("Remote exception in the 'TR2InOutRMIStub.contains'.", e);
63     }
64   }
65
66   public Bundle list () {
67     try {
68       byte[] s = target.list();
69       BundleImpl bundle = new BundleImpl();
70       bundle._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(s));
71       return bundle;
72     } catch (java.rmi.RemoteException JavaDoc e) {
73       throw new ConnectorTransportException("Remote exception in the 'TR2InOutRMIStub.list'.", e);
74     } catch (java.io.IOException JavaDoc e) {
75       throw new ConnectorTransportException("IOException in the 'TR2InOutRMIStub.list'.", e);
76     }
77   }
78 }
79
Popular Tags