1 5 package SOFA.SOFAnode.TR.Connector; 6 7 import java.io.IOException ; 8 import java.rmi.RemoteException ; 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 19 public class TR2InOutRMIStub implements CNTR2InOut { 20 21 private CNTR2InOutRemote target; 22 23 public TR2InOutRMIStub (String url) throws java.rmi.RemoteException { 24 try { 25 target = (CNTR2InOutRemote) java.rmi.Naming.lookup(url); 26 } catch (java.net.MalformedURLException e) { 27 throw new java.rmi.RemoteException ("Can't create CNTR2InOutRemote.\n" + url + "\n", e); 28 } catch (java.rmi.NotBoundException e) { 29 throw new java.rmi.RemoteException ("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 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 e) { 52 throw new ConnectorTransportException("Remote exception in the 'TR2InOutRMIStub.getBundle'.", e); 53 } catch (java.io.IOException 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 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 e) { 73 throw new ConnectorTransportException("Remote exception in the 'TR2InOutRMIStub.list'.", e); 74 } catch (java.io.IOException e) { 75 throw new ConnectorTransportException("IOException in the 'TR2InOutRMIStub.list'.", e); 76 } 77 } 78 } 79 | Popular Tags |