KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > TR > Local > TRWrapper


1 /*
2  * TRWrapper.java
3  *
4  * Created on 19. b°ezen 2004, 17:00
5  */

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 JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.ByteArrayOutputStream JavaDoc;
16 import java.io.ByteArrayInputStream JavaDoc;
17
18 /**
19  * Wrapper of TR implementation.
20  *
21  * @author Ladislav Sobr
22  */

23 public class TRWrapper implements TRInterface
24 {
25   private TRImpl tr;
26   
27   /** Creates a new instance of TRWrapper */
28   public TRWrapper(String JavaDoc dir) throws TRException
29   {
30     try
31     {
32       tr = new TRImpl(dir);
33     }
34     catch (RemoteException JavaDoc 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 JavaDoc os = new ByteArrayOutputStream JavaDoc();
69       bundle._write(os);
70       os.close();
71       ret = os.toByteArray();
72     }
73     catch (IOException JavaDoc 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 JavaDoc(memoryBundle));
97     }
98     catch (IOException JavaDoc 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