KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ContainerImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.rmi.RemoteException JavaDoc;
4 import java.rmi.server.UnicastRemoteObject JavaDoc;
5
6 import SOFA.SOFAnode.Made.TIR.Contained;
7 import SOFA.SOFAnode.Made.TIR.Container;
8 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
9 import SOFA.SOFAnode.Made.TIR.Identification;
10 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
11 import SOFA.SOFAnode.Made.TIR.TIRObject;
12
13 public abstract class ContainerImpl extends UnicastRemoteObject JavaDoc implements Container, TIRImplObject, SContainer {
14   protected int numOfItems;
15   protected LiItem firstChild;
16   protected LiItem lastChild;
17
18   protected boolean hasCont; /* for work object */
19
20   public ContainerImpl() throws RemoteException JavaDoc {
21     firstChild = lastChild = null;
22     numOfItems = 0;
23     hasCont = false;
24   }
25
26   /* add item to the list of childs */
27   protected void addListItem(TIRObject what) {
28     LiItem item = new LiItem(what);
29     if (firstChild == null) {
30       firstChild = lastChild = item;
31     } else {
32       LiItem akt = firstChild;
33       while (akt.next != null) akt = akt.next;
34       akt.next = item;
35       item.prev = akt;
36       lastChild = item;
37     }
38     numOfItems++;
39   }
40
41   public Contained[] contents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
42     int i;
43     Contained[] ret = new Contained [numOfItems];
44     LiItem akt = firstChild;
45     if ((type==null) || (type.value()==DefinitionKind.dk_all)) {
46       for(i=0;i<numOfItems;i++) {
47         ret[i] = (Contained) akt.obj;
48         akt = akt.next;
49       }
50       return ret;
51     }
52     if (type.value()==DefinitionKind.dk_none) {
53       return null;
54     } else {
55       int j = 0;
56       for(i=0;i<numOfItems;i++) {
57         if(akt.obj.get_def_kind().value() == type.value()) {
58           ret[j] = (Contained) akt.obj;
59       j++;
60     }
61         akt = akt.next;
62       }
63       Contained[] r = new Contained [j];
64       for(i=0;i<j;i++) {
65         r[i] = ret[i];
66       }
67       return r;
68     }
69   }
70
71   public Contained lookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
72     Contained ret = null;
73     LiItem akt = firstChild;
74     for(int i=0;i<numOfItems;i++) {
75       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_equal(id)) {
76         ret = (Contained) akt.obj;
77     break;
78       } else {
79         akt = akt.next;
80       }
81     }
82     return ret;
83   }
84
85   public Contained lookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
86                                               /* !!! change cdl in whole file */
87     Identification id = new IdentificationImpl("cdl","::"+name,version);
88     Contained ret = null;
89     LiItem akt = firstChild;
90     for(int i=0;i<numOfItems;i++) {
91       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_equal(id)) {
92         ret = (Contained) akt.obj;
93     break;
94       } else {
95         akt = akt.next;
96       }
97     }
98     return ret;
99   }
100   
101   public Contained[] lookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
102     Contained[] all = new Contained [numOfItems];
103     LiItem akt = firstChild;
104     int i,j = 0;
105     for(i=0;i<numOfItems;i++) {
106       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_name_equal(id)) {
107         all[j] = (Contained) akt.obj;
108     j++;
109       }
110       akt = akt.next;
111     }
112     Contained[] ret = new Contained [j];
113     for(i=0;i<j;i++) {
114       ret[i] = all[i];
115     }
116     return ret;
117   }
118
119   public Contained[] lookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
120     Identification id = new IdentificationImpl("cdl","::"+name,"");
121     Contained[] all = new Contained [numOfItems];
122     LiItem akt = firstChild;
123     int i,j = 0;
124     for(i=0;i<numOfItems;i++) {
125       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_name_equal(id)) {
126         all[j] = (Contained) akt.obj;
127     j++;
128       }
129       akt = akt.next;
130     }
131     Contained[] ret = new Contained [j];
132     for(i=0;i<j;i++) {
133       ret[i] = all[i];
134     }
135     return ret;
136   }
137
138   public Contained lookup_tag(String JavaDoc name, String JavaDoc tag) throws RemoteException JavaDoc, TIRExceptLock {
139     Identification idl;
140     Contained ret = null;
141     LiItem akt = firstChild;
142     int i,j = 0;
143     for(i=0;i<numOfItems;i++) {
144       if (((SIdentification) (idl = ((Contained)akt.obj).get_identification())).is_short_name_equal(name)) {
145         String JavaDoc[] t = idl.tag();
146         boolean found = false;
147         for(int k=0;k<t.length;k++) {
148           if (t[k].compareTo(tag)==0) {
149             found = true;
150             break;
151           }
152         }
153         if (found) {
154           ret = (Contained) akt.obj;
155           break;
156         }
157       }
158       akt = akt.next;
159     }
160     return ret;
161   }
162   public Contained[] lookup_branchtag(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
163     Identification idl;
164     Contained[] all = new Contained [numOfItems];
165     LiItem akt = firstChild;
166     int i,j = 0;
167     for(i=0;i<numOfItems;i++) {
168       if (((SIdentification) (idl = ((Contained)akt.obj).get_identification())).is_short_name_equal(name)) {
169         if (idl.branchTag().compareTo(brtag)==0) {
170           all[j] = (Contained) akt.obj;
171       j++;
172         }
173       }
174       akt = akt.next;
175     }
176     Contained[] ret = new Contained [j];
177     for(i=0;i<j;i++) {
178       ret[i] = all[i];
179     }
180     return ret;
181   }
182
183   public Contained lookup_lastinbranch(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
184     Identification idl;
185     Contained ret = null;
186     Contained[] branch = new Contained [numOfItems];
187     LiItem akt = firstChild;
188     if (brtag==null)
189       brtag = "";
190     int i,j = 0;
191     for(i=0;i<numOfItems;i++) {
192       if (((SIdentification) (idl = ((Contained)akt.obj).get_identification())).is_short_name_equal(name)) {
193         if (idl.branchTag().compareTo(brtag)==0) {
194           branch[j] = (Contained) akt.obj;
195       j++;
196         }
197       }
198       akt = akt.next;
199     }
200     if (j!=0) {
201       ret = branch[0];
202       String JavaDoc ver = branch[0].get_identification().version();
203       int last = ver.lastIndexOf('!');
204       long max = 0;
205       last++;
206       while ((last < ver.length())&&(Character.isDigit(ver.charAt(last)))) {
207         max *= 10;
208         max += (int) (ver.charAt(last)-'0');
209     last++;
210       }
211       for(i=1;i<j;i++) {
212         ver = branch[i].get_identification().version();
213         last = ver.lastIndexOf('!');
214         long m = 0;
215         last++;
216         while ((last < ver.length())&&(Character.isDigit(ver.charAt(last)))) {
217           m *= 10;
218           m += (int) (ver.charAt(last)-'0');
219       last++;
220         }
221
222         if (m>max) {
223           max = m;
224           ret = branch[i];
225         }
226       }
227     }
228     return ret;
229   }
230   
231   public Contained lookup_lastfromversion(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
232     Contained tt = null;
233     LiItem akt = firstChild;
234     int i;
235     for(i=0;i<numOfItems;i++) {
236       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_equal(name,version)) {
237         tt = (Contained) akt.obj;
238     break;
239       } else {
240         akt = akt.next;
241       }
242     }
243     if (tt==null)
244       return null;
245      
246     String JavaDoc brtag = tt.get_identification().branchTag();
247     Identification idl;
248     Contained ret = null;
249     Contained[] branch = new Contained [numOfItems];
250     akt = firstChild;
251     int j = 0;
252     for(i=0;i<numOfItems;i++) {
253       if (((SIdentification) (idl = ((Contained)akt.obj).get_identification())).is_short_name_equal(name)) {
254         if (idl.branchTag().compareTo(brtag)==0) {
255           branch[j] = (Contained) akt.obj;
256       j++;
257         }
258       }
259       akt = akt.next;
260     }
261     if (j!=0) {
262       ret = branch[0];
263       String JavaDoc ver = branch[0].get_identification().version();
264       int last = ver.lastIndexOf('!');
265       long max = 0;
266       last++;
267       while ((last < ver.length())&&(Character.isDigit(ver.charAt(last)))) {
268         max *= 10;
269         max += (int) (ver.charAt(last)-'0');
270     last++;
271       }
272       for(i=1;i<j;i++) {
273         ver = branch[i].get_identification().version();
274         last = ver.lastIndexOf('!');
275         long m = 0;
276         last++;
277         while ((last < ver.length())&&(Character.isDigit(ver.charAt(last)))) {
278           m *= 10;
279           m += (int) (ver.charAt(last)-'0');
280       last++;
281         }
282
283         if (m>max) {
284           max = m;
285           ret = branch[i];
286         }
287       }
288     }
289     return ret;
290   }
291
292   /* methods from iface SContainer */
293   public Contained[] scontents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
294     int i;
295     Contained[] ret = new Contained [numOfItems];
296     LiItem akt = firstChild;
297     if ((type==null) || (type.value()==DefinitionKind.dk_all)) {
298       for(i=0;i<numOfItems;i++) {
299         ret[i] = (Contained) akt.obj;
300         akt = akt.next;
301       }
302       return ret;
303     }
304     if (type.value()==DefinitionKind.dk_none) {
305       return null;
306     } else {
307       int j = 0;
308       for(i=0;i<numOfItems;i++) {
309         if(akt.obj.get_def_kind().value() == type.value()) {
310           ret[j] = (Contained) akt.obj;
311       j++;
312     }
313         akt = akt.next;
314       }
315       Contained[] r = new Contained [j];
316       for(i=0;i<j;i++) {
317         r[i] = ret[i];
318       }
319       return r;
320     }
321   }
322
323   public Contained slookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
324     Contained ret = null;
325     LiItem akt = firstChild;
326     for(int i=0;i<numOfItems;i++) {
327       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_equal(id)) {
328         ret = (Contained) akt.obj;
329     break;
330       } else {
331         akt = akt.next;
332       }
333     }
334     return ret;
335   }
336
337   public Contained slookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
338     Identification id = new IdentificationImpl("cdl","::"+name,version);
339     Contained ret = null;
340     LiItem akt = firstChild;
341     for(int i=0;i<numOfItems;i++) {
342       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_equal(id)) {
343         ret = (Contained) akt.obj;
344     break;
345       } else {
346         akt = akt.next;
347       }
348     }
349     return ret;
350   }
351   
352   public Contained[] slookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
353     Contained[] all = new Contained [numOfItems];
354     LiItem akt = firstChild;
355     int i,j = 0;
356     for(i=0;i<numOfItems;i++) {
357       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_name_equal(id)) {
358         all[j] = (Contained) akt.obj;
359     j++;
360       }
361       akt = akt.next;
362     }
363     Contained[] ret = new Contained [j];
364     for(i=0;i<j;i++) {
365       ret[i] = all[i];
366     }
367     return ret;
368   }
369
370   public Contained[] slookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
371     Identification id = new IdentificationImpl("cdl","::"+name,"");
372     Contained[] all = new Contained [numOfItems];
373     LiItem akt = firstChild;
374     int i,j = 0;
375     for(i=0;i<numOfItems;i++) {
376       if (((SIdentification) ((Contained)akt.obj).get_identification()).is_short_name_equal(id)) {
377         all[j] = (Contained) akt.obj;
378     j++;
379       }
380       akt = akt.next;
381     }
382     Contained[] ret = new Contained [j];
383     for(i=0;i<j;i++) {
384       ret[i] = all[i];
385     }
386     return ret;
387   }
388
389   public long isLockedForCreate() throws RemoteException JavaDoc {
390     return -1L; /* modules (amodules, providers) and repository must this method rewrite */
391   }
392 }
393
394
395
Popular Tags