KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > TIR > Impl > IdentificationImpl


1 /* $Id: IdentificationImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.io.DataInputStream JavaDoc;
4 import java.io.DataOutputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.rmi.RemoteException JavaDoc;
7 import java.rmi.server.UnicastRemoteObject JavaDoc;
8
9 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
10 import SOFA.SOFAnode.Made.TIR.Identification;
11
12 public class IdentificationImpl extends UnicastRemoteObject JavaDoc implements Identification, SIdentification {
13   public String JavaDoc nm; // name
14
public String JavaDoc ver; // version
15
public String JavaDoc[] tg; // tag
16
public String JavaDoc brtg; // branchTag
17
public AbsoluteNameImpl abs;
18   public AbsoluteNameImpl langabs;
19
20   public String JavaDoc lang; // identification of description language
21

22   Lock nextLock; // lock for getting next version
23
long lockId; // id of locking "transaction"
24
long nextNBranch; // number of next branch
25
boolean hasNext; // has new version
26

27   // name must be absolute name (::aaa::bbb:ccc)
28
public IdentificationImpl(String JavaDoc lng, String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc {
29     super();
30     lang = new String JavaDoc(lng);
31     abs = new AbsoluteNameImpl(name);
32     langabs = new AbsoluteNameImpl(lng, abs);
33     if (abs.size() != 0) {
34       nm = new String JavaDoc(abs.elementAt(abs.size()-1));
35     } else {
36       nm = "";
37     }
38     ver = new String JavaDoc(version);
39     brtg = ""; tg = new String JavaDoc [0];
40     nextLock = new Lock(false);
41     lockId = -1L;
42     hasNext = false;
43     nextNBranch = 1;
44   }
45
46   // name must be absolute name (::aaa::bbb:ccc)
47
public IdentificationImpl(String JavaDoc lng, String JavaDoc name, String JavaDoc version, String JavaDoc branchTag) throws RemoteException JavaDoc {
48     super();
49     lang = new String JavaDoc(lng);
50     abs = new AbsoluteNameImpl(name);
51     langabs = new AbsoluteNameImpl(lng, abs);
52     if (abs.size() != 0) {
53       nm = new String JavaDoc(abs.elementAt(abs.size()-1));
54     } else {
55       nm = "";
56     }
57     ver = new String JavaDoc(version);
58     brtg = new String JavaDoc(branchTag); tg = new String JavaDoc [0];
59     nextLock = new Lock(false);
60     lockId = -1L;
61     hasNext = false;
62     nextNBranch = 1;
63   }
64
65   public IdentificationImpl() throws RemoteException JavaDoc {
66     nm = "";
67     ver = "";
68     lang = "";
69     tg = new String JavaDoc [0];
70     brtg = "";
71     abs = new AbsoluteNameImpl("");
72     langabs = null;
73     nextLock = new Lock(false);
74     lockId = -1L;
75     hasNext = false;
76     nextNBranch = 1;
77   }
78
79   public IdentificationImpl(Identification i) throws RemoteException JavaDoc {
80     nm = new String JavaDoc(i.name());
81     ver = new String JavaDoc(i.version());
82     brtg = new String JavaDoc(i.branchTag());
83     String JavaDoc[] t = i.tag();
84     int j;
85     tg = new String JavaDoc [t.length];
86     for(j=0;j<t.length;j++)
87       tg[j] = new String JavaDoc(t[j]);
88     abs = new AbsoluteNameImpl(i.absolute_name().name());
89     nextLock = new Lock(false);
90     lockId = -1L;
91     hasNext = ((SIdentification)i).hasNextVersion();
92     nextNBranch = ((SIdentification)i).nextNumBranch();
93
94     lang = new String JavaDoc(((SIdentification)i).language());
95     
96     langabs = new AbsoluteNameImpl(lang, abs);
97   }
98
99   public String JavaDoc language() throws RemoteException JavaDoc {
100     return lang;
101   }
102
103   public boolean is_equal(Identification id) throws RemoteException JavaDoc {
104     if ((nm.compareTo(id.name())==0) && (ver.compareTo(id.version())==0)
105         && abs.isEqual(id.absolute_name()) && (lang.compareTo(((SIdentification)id).language())==0))
106       return true;
107     else
108       return false;
109   }
110   
111   public boolean is_name_equal(Identification id) throws RemoteException JavaDoc {
112     if ((nm.compareTo(id.name())==0)&& abs.isEqual(id.absolute_name()))
113       return true;
114     else
115       return false;
116   }
117
118   public boolean is_name_equal(String JavaDoc name) throws RemoteException JavaDoc {
119     if (name.compareTo(abs.name())==0)
120       return true;
121     else
122       return false;
123   }
124
125   public String JavaDoc name() {
126     return nm;
127   }
128
129   public AbsoluteName absolute_name() {
130     return abs;
131   }
132
133   public AbsoluteName lang_absolute_name() throws RemoteException JavaDoc {
134     return langabs;
135   }
136
137   public String JavaDoc version() {
138     return ver;
139   }
140
141   public void version(String JavaDoc v) {
142     if (v==null)
143       ver = "";
144     ver = v;
145   }
146
147   public void tag(String JavaDoc t) {
148     if (t!=null) {
149       int i, len = tg.length;
150       for (i=0;i<len;i++) {
151         if (tg[i].compareTo(t)==0)
152           return;
153       }
154       String JavaDoc[] newt = new String JavaDoc [len+1];
155       for (i=0;i<len;i++) {
156         newt[i] = tg[i];
157       }
158       newt[i] = new String JavaDoc(t);
159       tg = newt;
160     }
161   }
162
163   public String JavaDoc[] tag() {
164     String JavaDoc t[] = new String JavaDoc [tg.length];
165     for (int i=0;i<tg.length;i++)
166       t[i] = new String JavaDoc(tg[i]);
167     return t;
168   }
169
170   public String JavaDoc branchTag() {
171     return brtg;
172   }
173
174   public void save(DataOutputStream JavaDoc out) throws TIRExceptStorage {
175     try {
176       Storage.writeString(out, nm);
177       Storage.writeString(out, abs.toString());
178       Storage.writeString(out, lang);
179       Storage.writeString(out, ver);
180       out.writeInt(tg.length);
181       for (int i=0; i<tg.length;i++)
182         Storage.writeString(out, tg[i]);
183       Storage.writeString(out, brtg);
184       out.writeLong(nextNBranch);
185       if (nextLock.isLocked())
186         out.writeBoolean(false);
187       else
188         out.writeBoolean(hasNext);
189     } catch (IOException JavaDoc e) {
190       throw new TIRExceptStorage("Access error in saving identification "+nm);
191     }
192   }
193
194   public void load(DataInputStream JavaDoc in) throws TIRExceptStorage {
195     try {
196       nm = Storage.readString(in);
197       abs = new AbsoluteNameImpl(Storage.readString(in));
198       lang = Storage.readString(in);
199       langabs = new AbsoluteNameImpl(lang, abs);
200       ver = Storage.readString(in);
201       int i, len = in.readInt();
202       tg = new String JavaDoc [len];
203       for(i=0;i<len;i++)
204         tg[i] = Storage.readString(in);
205       brtg = Storage.readString(in);
206       nextNBranch = in.readLong();
207       hasNext = in.readBoolean();
208     } catch (IOException JavaDoc e) {
209       throw new TIRExceptStorage("Access error");
210     }
211   }
212
213   public boolean is_equal(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc {
214     if (name.compareTo(abs.name())==0 && (ver.compareTo(version)==0))
215       return true;
216     else
217       return false;
218   }
219
220   public String JavaDoc toString() {
221     return new String JavaDoc(nm+"?"+ver);
222   }
223
224   public boolean isLocked() throws RemoteException JavaDoc {
225     return nextLock.isLocked();
226   }
227
228   public long lockFor() throws RemoteException JavaDoc {
229     return lockId;
230   }
231   
232   public boolean lock(long lockFor) throws RemoteException JavaDoc {
233     boolean a = nextLock.lock();
234     if (a)
235       this.lockId = lockFor;
236     return a;
237   }
238   
239   public void unlock() throws RemoteException JavaDoc {
240     lockId = -1L;
241     nextLock.unlock();
242   }
243   
244   public long nextNumBranch() throws RemoteException JavaDoc {
245     return nextNBranch;
246   }
247
248   public void incNextNumBranch() throws RemoteException JavaDoc { nextNBranch++; }
249   public boolean hasNextVersion() throws RemoteException JavaDoc { return hasNext; }
250   public void setNextVersion() throws RemoteException JavaDoc { hasNext = true; }
251
252   public boolean is_short_equal(Identification id) throws RemoteException JavaDoc {
253     if ((nm.compareTo(id.name())==0) && (ver.compareTo(id.version())==0))
254       return true;
255     else
256       return false;
257   }
258   
259   public boolean is_short_equal(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc {
260     if ((nm.compareTo(name)==0) && (ver.compareTo(version)==0))
261       return true;
262     else
263       return false;
264   }
265   
266   public boolean is_short_name_equal(Identification id) throws RemoteException JavaDoc {
267     if ((nm.compareTo(id.name())==0))
268       return true;
269     else
270       return false;
271   }
272
273   public boolean is_short_name_equal(String JavaDoc name) throws RemoteException JavaDoc {
274     if (nm.compareTo(name)==0)
275       return true;
276     else
277       return false;
278   }
279
280   public boolean is_local() throws RemoteException JavaDoc {
281     String JavaDoc sofaNodeName = System.getProperty("sofanode.name","");
282
283     //test same node
284
StringBuffer JavaDoc ip = new StringBuffer JavaDoc();
285     int i = 0;
286     while ((i<ver.length()) && (ver.charAt(i)!='!')) {
287       ip.append(ver.charAt(i));
288       i++;
289     }
290   
291     if (sofaNodeName.compareTo(ip.toString())==0)
292       return true;
293     else
294       return false;
295   }
296 }
297
Popular Tags