1 6 7 package SOFA.SOFAnet.TR.Local; 8 9 import SOFA.SOFAnode.TR.*; 10 import SOFA.SOFAnode.InOut.Bundle; 11 import SOFA.SOFAnet.TR.TRInterface; 12 import SOFA.SOFAnode.TR.Impl.*; 13 import java.rmi.RemoteException ; 14 import java.io.IOException ; 15 import java.io.ByteArrayOutputStream ; 16 import java.io.ByteArrayInputStream ; 17 18 23 public class TRWrapper implements TRInterface 24 { 25 private TRImpl tr; 26 27 28 public TRWrapper(String dir) throws TRException 29 { 30 try 31 { 32 tr = new TRImpl(dir); 33 } 34 catch (RemoteException e) 35 { 36 throw new TRException ("TR init failed", e); 37 } 38 } 39 40 public boolean contains(ComponentInfo descrs) 41 { 42 return tr.contains(descrs); 43 } 44 45 public boolean containsComponent(ComponentInfo comp, boolean inferiors) 46 { 47 return tr.containsComponent(comp, inferiors); 48 } 49 50 public void deleteComponents(ComponentInfo[] comps, boolean interfaces, boolean inferiors) throws TRException 51 { 52 tr.deleteComponents(comps, interfaces, inferiors); 53 } 54 55 public Bundle getBundle(ComponentInfo[] descs, ComponentInfo[] comps, boolean inferiors) throws TRException 56 { 57 return tr.getBundle(descs, comps, inferiors); 58 } 59 60 public byte[] getMemoryBundle(ComponentInfo[] descs, ComponentInfo[] comps, boolean inferiors) throws TRException 61 { 62 BundleImpl bundle = (BundleImpl) tr.getBundle(descs, comps, inferiors); 63 64 byte[] ret = null; 65 66 try 67 { 68 ByteArrayOutputStream os = new ByteArrayOutputStream (); 69 bundle._write(os); 70 os.close(); 71 ret = os.toByteArray(); 72 } 73 catch (IOException e) 74 { 75 throw new TRException("Serialization of bundle while getting bundle in TRWrapper failed", e); 76 } 77 78 return ret; 79 } 80 81 public Bundle list() 82 { 83 return tr.list(); 84 } 85 86 public void storeBundle(Bundle bundle) throws TRException 87 { 88 tr.storeBundle(bundle); 89 } 90 91 public void storeMemoryBundle(byte[] memoryBundle) throws TRException 92 { 93 BundleImpl bundle = new BundleImpl(); 94 try 95 { 96 bundle._read(new ByteArrayInputStream (memoryBundle)); 97 } 98 catch (IOException e) 99 { 100 throw new TRException("Serialization of bundle while storing bundle in TRWrapper failed", e); 101 } 102 103 tr.storeBundle(bundle); 104 } 105 } 106 | Popular Tags |