KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CDL > CompRepository


1 /* $Id: CompRepository.java,v 1.3 2004/09/10 14:16:48 hnetynka Exp $ */
2 package SOFA.SOFAnode.Made.CDL;
3 import java.io.IOException JavaDoc;
4 import java.rmi.Naming JavaDoc;
5 import java.rmi.RemoteException JavaDoc;
6
7 import SOFA.SOFAnode.Made.TIR.ArchitectureDef;
8 import SOFA.SOFAnode.Made.TIR.CDLContainer;
9 import SOFA.SOFAnode.Made.TIR.CDLRepository;
10 import SOFA.SOFAnode.Made.TIR.ConstantDef;
11 import SOFA.SOFAnode.Made.TIR.Contained;
12 import SOFA.SOFAnode.Made.TIR.Container;
13 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
14 import SOFA.SOFAnode.Made.TIR.EnumDef;
15 import SOFA.SOFAnode.Made.TIR.EnumMember;
16 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
17 import SOFA.SOFAnode.Made.TIR.FrameDef;
18 import SOFA.SOFAnode.Made.TIR.Identification;
19 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
20 import SOFA.SOFAnode.Made.TIR.ModuleDef;
21 import SOFA.SOFAnode.Made.TIR.ProfileDef;
22 import SOFA.SOFAnode.Made.TIR.ProviderDef;
23 import SOFA.SOFAnode.Made.TIR.Repository;
24 import SOFA.SOFAnode.Made.TIR.StructDef;
25 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
26 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
27 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
28 import SOFA.SOFAnode.Made.TIR.TypedefDef;
29 import SOFA.SOFAnode.Made.TIR.UnionDef;
30 import SOFA.SOFAnode.Made.TIR.WorkRepository;
31
32 class CompRepository extends CompContainerIm {
33   class CompRepExcept extends Exception JavaDoc {
34     public CompRepExcept() { super(); }
35     public CompRepExcept(String JavaDoc s) { super(s); }
36   }
37   
38   public Repository defRepository;
39   public WorkRepository workRepository;
40   public CDLRepository cdlRepository; // work CDLRepository
41
public ProfileDef profile;
42   
43   public Scopename aktScope;
44
45   public List defaultTypes;
46
47   public String JavaDoc searchError;
48
49   public boolean useProtocols; // save protocols, protocols must exist
50
public boolean testProtocols; // test protocols --- Stano (testProtocols implies useProtocols
51

52   public SOFA.SOFAnode.Util.BehaviorProtocolChecker protocolChecker;
53   
54   public CompRepository(Scopename aktScope) throws Exception JavaDoc {
55     super(ObjectsKind.o_Repository);
56     this.aktScope = aktScope;
57
58     String JavaDoc rmiport = System.getProperty("tir.rmiport","1099");
59     String JavaDoc rmihost = System.getProperty("tir.rmihost","localhost");
60     defRepository = (Repository) Naming.lookup("//"+rmihost+":"+rmiport+"/Repository");
61     
62     boolean ok = false;
63     int i = 0;
64     
65     String JavaDoc profName = System.getProperty("cdl.profile",null);
66     while (!ok) {
67       try {
68         if (profName==null)
69           profile = null;
70         else {
71           profile = defRepository.getProfiles().lookup(profName);
72           if (profile == null)
73             throw new CDLExceptBadName("Profile with name "+profName+" doesn't exist.");
74         }
75         ok = true;
76       } catch (TIRExceptLock e) {
77         if (i == Consts.repeatCount)
78           throw new CDLExceptLock("Repository is locked.");
79         else {
80           i++;
81           System.err.println("Repository is locked. Waiting for next attempt.");
82           Thread.sleep(Consts.repeatDelay);
83         }
84       }
85     }
86     
87     ok = false;
88     i = 0;
89     while (!ok) {
90       try {
91         if (System.getProperty("cdl.debug","no").compareTo("yes")==0) {
92           System.out.println(java.util.Calendar.getInstance().getTime().getTime());
93           workRepository = defRepository.beginChanges(profile);
94           System.out.println(java.util.Calendar.getInstance().getTime().getTime());
95         } else {
96           workRepository = defRepository.beginChanges(profile);
97         }
98         profile = workRepository.profile();
99         ok = true;
100       } catch (TIRExceptLock e) {
101         if (i == Consts.repeatCount)
102           throw new CDLExceptLock("Repository is locked.");
103         else {
104           i++;
105           System.err.println("Repository is locked. Waiting for next attempt.");
106           Thread.sleep(Consts.repeatDelay);
107         }
108       }
109     }
110
111     cdlRepository = (CDLRepository) workRepository.lookup("cdl","");
112    
113     useProtocols = false;
114     testProtocols = false;
115     String JavaDoc prot = System.getProperty("cdl.protocols","no");
116     if (prot.compareTo("yes")==0)
117       useProtocols = true;
118     prot = System.getProperty("cdl.testprotocols","no");
119     if (prot.compareTo("yes")==0) {
120       useProtocols = true;
121       testProtocols = true;
122     }
123     
124     defaultTypes = new List();
125     searchError = null;
126
127     protocolChecker = SOFA.SOFAnode.Util.BehaviorProtocolCheckerFactory.getChecker(System.getProperty("cdl.protocolChecker",null));
128   }
129
130   /** for compiler launched from external programs (Netbeans) */
131   public CompRepository(Scopename aktScope, Repository defRep, WorkRepository workRep, boolean useProt, boolean testProt) throws Exception JavaDoc {
132     super(ObjectsKind.o_Repository);
133     this.aktScope = aktScope;
134
135     defRepository = defRep;
136     
137     workRepository = workRep;
138     profile = workRepository.profile();
139     cdlRepository = (CDLRepository) workRepository.lookup("cdl","");
140    
141     useProtocols = useProt;
142     testProtocols = testProt;
143     if (testProt) {
144       useProtocols = true;
145       System.setProperty("cdl.protocols","yes");
146       System.setProperty("cdl.testprotocols","yes");
147     } else {
148       System.setProperty("cdl.testprotocols","no");
149       if (useProtocols)
150         System.setProperty("cdl.protocols","yes");
151       else
152         System.setProperty("cdl.protocols","no");
153     }
154     
155     defaultTypes = new List();
156     searchError = null;
157
158     protocolChecker = SOFA.SOFAnode.Util.BehaviorProtocolCheckerFactory.getChecker(System.getProperty("cdl.protocolChecker",null));
159   }
160
161   public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote {
162     CompContained[] cont = contents();
163     for (int i=0;i<cont.length;i++) {
164       switch (cont[i].objectKind()) {
165       case ObjectsKind.o_Module:
166         cont[i].checkConsist(null,rep);
167         break;
168       case ObjectsKind.o_Interface:
169         cont[i].checkConsist(null,rep);
170         break;
171       case ObjectsKind.o_Frame:
172         try {
173           cont[i].checkConsist(null,rep);
174         } catch (CDLExceptCheck e) {
175           throw new CDLExceptCheck(e.getMessage()+" in frame "+cont[i].fullName());
176         }
177         break;
178       case ObjectsKind.o_Provider:
179         cont[i].checkConsist(null,rep);
180       }
181     }
182   }
183
184 /* private void readDefaults() throws CDLExceptLock, CDLExceptRemote {
185     try {
186       String fileName = System.getProperty("cdl.defaultfile","cdldef");
187       BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
188       String str;
189       int lineCnt = 0;
190       while ((str = in.readLine())!=null) {
191         lineCnt++;
192         str = str.trim(); // remove white spaces from begin and end
193         if (str.length()==0) // empty line
194           continue;
195         if (str.charAt(0)=='#') // full line coment
196           continue;
197         int i;
198         if ((i = str.indexOf('#'))!=-1) { // comment in line
199           str = str.substring(0,i);
200           str = str.trim();
201         }
202         if (str.indexOf(' ')==-1) {
203           System.err.println("Error in file "+fileName+" at line "+lineCnt+".");
204           continue;
205         }
206         StringBuffer name = new StringBuffer();
207         StringBuffer version = new StringBuffer();
208         i = 0;
209         while (str.charAt(i)!=' ') {
210           name.append(str.charAt(i));
211           i++;
212         }
213         while (str.charAt(i)==' ')
214           i++;
215         while (str.length() > i || str.charAt(i)!=' ') {
216           version.append(str.charAt(i));
217           i++;
218         }
219         if (name.charAt(0)!=':') {
220           System.err.println("You must set absolute name (line: "+lineCnt+").");
221           continue;
222         }
223         DefaultTypes t = new DefaultTypes(name.toString(),version.toString());
224         boolean exist = false;
225         boolean cycle = true;
226         int c = 0;
227         while (cycle) {
228           try {
229             exist = t.test(defRepository);
230             cycle = false;
231           } catch (CDLExceptLock e) {
232             try {
233               Thread.sleep(2000);
234             } catch (InterruptedException e1) {;}
235             c++;
236             if (c == 10)
237               throw new CDLExceptLock("Repository is locked.");
238           }
239         }
240         if (exist)
241           defaultTypes.add(t);
242         else
243           System.err.println("Object at line "+lineCnt+" in "+fileName+" doesn't exist.");
244       }
245     } catch (IOException e) {
246       System.err.println("Error when reading default types: "+e.getMessage());
247     }
248   } */

249
250   public CompReffer searchReffer(String JavaDoc name, String JavaDoc version) throws CDLExceptLock, CDLExceptRemote {
251     if (name!=null && name.length()!=0) {
252       // convert name&ver to FullID
253
FullID id = null;
254       if (name.charAt(0)==':') {
255         if (aktScope.length()==0)
256           id = new FullID ("::"+name , version);
257         else
258           id = new FullID (aktScope.toString()+"::"+name , version);
259       } else {
260         id = new FullID (name, version);
261       }
262       return searchReffer(id);
263     } else
264       return null;
265   }
266
267 /* static boolean isContainer(int kind) {
268     if (kind == ObjectsKind.o_Module) return true;
269     if (kind == ObjectsKind.o_AModule) return true;
270     if (kind == ObjectsKind.o_Provider) return true;
271     if (kind == ObjectsKind.o_Interface) return true;
272     if (kind == ObjectsKind.o_Struct) return true;
273     if (kind == ObjectsKind.o_Union) return true;
274     if (kind == ObjectsKind.o_Architecture) return true;
275     if (kind == ObjectsKind.o_Exception) return true;
276     if (kind == ObjectsKind.o_Frame) return true;
277     return false;
278   }*/

279
280 /* static boolean isDefContainer(int kind) {
281     if (kind == DefinitionKind.dk_Module) return true;
282     if (kind == DefinitionKind.dk_AModule) return true;
283     if (kind == DefinitionKind.dk_Provider) return true;
284     if (kind == DefinitionKind.dk_Interface) return true;
285     if (kind == DefinitionKind.dk_Struct) return true;
286     if (kind == DefinitionKind.dk_Union) return true;
287     if (kind == DefinitionKind.dk_Architecture) return true;
288     if (kind == DefinitionKind.dk_Exception) return true;
289     if (kind == DefinitionKind.dk_Frame) return true;
290     return false;
291   }*/

292
293   public CompReffer searchReffer(FullID id) throws CDLExceptLock, CDLExceptRemote {
294     return searchReffer(id, 0);
295   }
296
297   /** .
298     * @param cancelNameSpace how many namespace have to be skiped in searching
299     */

300   public CompReffer searchReffer(FullID id, int cancelNameSpace) throws CDLExceptLock, CDLExceptRemote {
301     int i,j;
302     long numPath = 0;
303 // long tmb = java.util.Calendar.getInstance().getTime().getTime();
304
if (!id.isAbsolute) {
305       // set absolute path to "id"
306
FullID nid = new FullID(true);
307       aktScope.names.toFirst();
308       for(i=0;i<aktScope.length()-cancelNameSpace;i++) {
309         nid.sn.addScope((String JavaDoc)aktScope.names.aktual());
310     aktScope.names.toNext();
311       }
312       numPath = aktScope.length();
313       id.sn.names.toFirst();
314       for(i=0;i<id.sn.length();i++) {
315         nid.sn.addScope((String JavaDoc)id.sn.names.aktual());
316     id.sn.names.toNext();
317       }
318       nid.name = id.name;
319       nid.setVersion(id.version);
320       id = nid;
321     }
322 // long tme = java.util.Calendar.getInstance().getTime().getTime();
323
// Output.out.println("#####"+Long.toString(tme-tmb)+" ms "+id.toString());
324

325     switch (id.isin) {
326       case IDKind.none : return searchRefferDefault(id, numPath);
327       case IDKind.version : return searchRefferVersion(id, numPath);
328       case IDKind.tag : return searchRefferTag(id, numPath);
329     }
330     return null;
331   }
332
333   private CompReffer searchRefferVersion(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote {
334     int i,j;
335
336     try {
337        // searching in new objects
338
CompContainer con = this;
339     id.sn.names.toFirst();
340     for(i=0;i<id.sn.names.size();i++) {
341       CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
342       if (a==null || a.length==0)
343         throw new CompRepExcept();
344       if (a.length==1) {
345         if (a[0].isContainer()) con = (CompContainer) a[0];
346         else throw new CompRepExcept();
347       } else {
348         boolean found = false;
349         for(j=0;j<a.length;j++) {
350           if (a[j].getIdent().version.compareTo(id.version)==0) {
351             if ( ! a[j].isContainer()) throw new CompRepExcept();
352             found = true;
353             con = (CompContainer) a[j];
354             break;
355           }
356         }
357         if (!found) throw new CompRepExcept();
358       }
359       id.sn.names.toNext();
360     }
361     CompContained sec = con.lookup(id.name, id.version);
362     if (sec!=null) {
363       CompReffer ret = new CompReffer();
364       ret.what = sec.objectKind();
365       ret.ref = new FullID(true);
366       ret.ref.name = new String JavaDoc(id.name);
367       ret.ref.version = new String JavaDoc(id.version);
368       ret.ref.isin = IDKind.version;
369       ret.isNew = true;
370       id.sn.names.toFirst();
371       for(j=0;j<id.sn.names.size();j++) {
372         ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
373         id.sn.names.toNext();
374       }
375       if (ret.what == ObjectsKind.o_Frame)
376         ret.isSystem = ((CompFrame)sec).isSystem;
377       if (ret.what == ObjectsKind.o_Architecture)
378         ret.isSystem = ((CompArchitecture)sec).isSystem;
379       return ret;
380     }
381        // end of searching in new objects
382
} catch (CompRepExcept e) {;}
383     
384        // search in normal repository
385
try {
386       Container con = cdlRepository;
387       id.sn.names.toFirst();
388       for(i=0;i<id.sn.names.size();i++) {
389         Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
390         if (a==null || a.length==0)
391           throw new CompRepExcept();
392         if (a.length==1) {
393           //if (isDefContainer(a[0].get_def_kind().value())) con = (Container) a[0];
394
if (a[0] instanceof Container) con = (Container) a[0];
395           else throw new CompRepExcept();
396         } else {
397           boolean found = false;
398           for(j=0;j<a.length;j++) {
399             if (a[j].get_identification().version().compareTo(id.version)==0) {
400               if ( !(a[j] instanceof Container)) throw new CompRepExcept();
401               found = true;
402               con = (Container) a[j];
403               break;
404             }
405           }
406           if (!found) throw new CompRepExcept();
407         }
408         id.sn.names.toNext();
409       }
410       Contained sec = con.lookup(id.name, id.version);
411       if (sec!=null) {
412         CompReffer ret = new CompReffer();
413         ret.what = sec.get_def_kind().value();
414         ret.ref = new FullID(true);
415         ret.ref.name = new String JavaDoc(id.name);
416         ret.ref.version = new String JavaDoc(id.version);
417         ret.ref.isin = IDKind.version;
418         ret.isNew = false;
419         id.sn.names.toFirst();
420         for(j=0;j<id.sn.names.size();j++) {
421           ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
422           id.sn.names.toNext();
423         }
424     if (ret.what == DefinitionKind.dk_Frame)
425       ret.isSystem = ((FrameDef)sec).is_system();
426     if (ret.what == DefinitionKind.dk_Architecture)
427       ret.isSystem = ((ArchitectureDef)sec).is_system();
428         return ret;
429       }
430       
431     } catch (TIRExceptLock e) {
432       throw new CDLExceptLock("Repository is locked.");
433     } catch (RemoteException JavaDoc e) {
434       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
435     } catch (CompRepExcept e) {;}
436       // end of search in normal repository
437

438       // search in Template Repository
439
// currently no interfaces to TR
440

441     // search in higher name scope (if possible)
442
if (numPath > 0) {
443       id.sn.names.toFirst();
444       for(i=1; i<numPath; i++)
445         id.sn.names.toNext();
446       id.sn.names.removeAkt();
447       return searchRefferVersion(id, numPath-1);
448     } else {
449       searchError = id.name + ":" + id.version + " doesn't exist";
450       return null;
451     }
452   }
453
454   private CompReffer searchRefferTag(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote {
455     int i,j;
456
457     try {
458        // searching in new objects
459
CompContainer con = this;
460     id.sn.names.toFirst();
461     for(i=0;i<id.sn.names.size();i++) {
462       CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
463       if (a==null || a.length==0)
464         throw new CompRepExcept();
465       if (a.length==1) {
466         if (a[0].isContainer()) con = (CompContainer) a[0];
467         else throw new CompRepExcept();
468       } else {
469         throw new CompRepExcept();
470       }
471       id.sn.names.toNext();
472     }
473     CompContained sec = con.lookupTag(id.name, id.tag);
474     if (sec!=null) {
475       CompReffer ret = new CompReffer();
476       ret.what = sec.objectKind();
477       ret.ref = new FullID(true);
478       ret.ref.name = new String JavaDoc(id.name);
479       ret.ref.version = new String JavaDoc(sec.getIdent().version);
480       ret.ref.isin = IDKind.version;
481       ret.isNew = true;
482       id.sn.names.toFirst();
483       for(j=0;j<id.sn.names.size();j++) {
484         ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
485         id.sn.names.toNext();
486       }
487       if (ret.what == ObjectsKind.o_Frame)
488         ret.isSystem = ((CompFrame)sec).isSystem;
489       if (ret.what == ObjectsKind.o_Architecture)
490         ret.isSystem = ((CompArchitecture)sec).isSystem;
491       return ret;
492     }
493        // end of searching in new objects
494
} catch (CompRepExcept e) {;}
495     
496        // search in normal repository
497
try {
498       Container con = cdlRepository;
499       id.sn.names.toFirst();
500       for(i=0;i<id.sn.names.size();i++) {
501         Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
502         if (a==null || a.length==0)
503           throw new CompRepExcept();
504         if (a.length==1) {
505           if (a[0] instanceof Container) con = (Container) a[0];
506           else throw new CompRepExcept();
507         } else {
508           throw new CompRepExcept();
509         }
510         id.sn.names.toNext();
511       }
512       Contained sec = con.lookup_tag(id.name, id.tag);
513       if (sec!=null) {
514         CompReffer ret = new CompReffer();
515         ret.what = sec.get_def_kind().value();
516         ret.ref = new FullID(true);
517         ret.ref.name = new String JavaDoc(id.name);
518         ret.ref.version = new String JavaDoc(sec.get_identification().version());
519         ret.ref.isin = IDKind.version;
520         ret.isNew = false;
521         id.sn.names.toFirst();
522         for(j=0;j<id.sn.names.size();j++) {
523           ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
524           id.sn.names.toNext();
525         }
526     if (ret.what == DefinitionKind.dk_Frame)
527       ret.isSystem = ((FrameDef)sec).is_system();
528     if (ret.what == DefinitionKind.dk_Architecture)
529       ret.isSystem = ((ArchitectureDef)sec).is_system();
530         return ret;
531       }
532       
533     } catch (TIRExceptLock e) {
534       throw new CDLExceptLock("Repository is locked.");
535     } catch (RemoteException JavaDoc e) {
536       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
537     } catch (CompRepExcept e) {;}
538       // end of search in normal repository
539

540       // search in Template Repository
541
// currently no interfaces to TR
542
// search in higher name scope (if possible)
543
if (numPath > 0) {
544       id.sn.names.toFirst();
545       for(i=1; i<numPath; i++)
546         id.sn.names.toNext();
547       id.sn.names.removeAkt();
548       return searchRefferTag(id, numPath-1);
549     } else {
550       searchError = id.name + ":" + id.version + " doesn't exist";
551       return null;
552     }
553   }
554
555   private CompReffer searchRefferDefault(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote {
556     // first search in new objects
557
int i,j;
558
559 // long tmb = java.util.Calendar.getInstance().getTime().getTime();
560
try {
561
562     CompContainer con = this;
563     id.sn.names.toFirst();
564     for(i=0;i<id.sn.names.size();i++) {
565       CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
566       if (a==null || a.length==0)
567         throw new CompRepExcept();
568       if (a.length==1) {
569         if (a[0].isContainer()) con = (CompContainer) a[0];
570         else throw new CompRepExcept();
571       } else {
572         throw new CompRepExcept();
573       }
574       id.sn.names.toNext();
575     }
576     CompContained[] sec = con.lookup(id.name);
577     if (sec!=null && sec.length!=0) {
578       if (sec.length==1) {
579         CompReffer ret = new CompReffer();
580         ret.what = sec[0].objectKind();
581         ret.ref = new FullID(true);
582         ret.ref.name = new String JavaDoc(id.name);
583         ret.ref.version = new String JavaDoc(sec[0].getIdent().version);
584         ret.ref.isin = IDKind.version;
585         ret.isNew = true;
586         id.sn.names.toFirst();
587         for(j=0;j<id.sn.names.size();j++) {
588           ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
589           id.sn.names.toNext();
590         }
591         if (ret.what == ObjectsKind.o_Frame)
592           ret.isSystem = ((CompFrame)sec[0]).isSystem;
593         if (ret.what == ObjectsKind.o_Architecture)
594           ret.isSystem = ((CompArchitecture)sec[0]).isSystem;
595          
596         return ret;
597       } else {
598         searchError = "it never should be here";
599         return null;
600       }
601     }
602        // end of searching in new objects
603
} catch (CompRepExcept e) {;}
604     
605     // searching in profiles
606
try {
607       if (profile != null) {
608         Identification idl = profile.lookup(id.langToString());
609         if (idl != null) {
610           CompReffer ret = new CompReffer();
611           ret.ref = new FullID(true);
612           ret.ref.name = new String JavaDoc(idl.name());
613           ret.ref.version = new String JavaDoc(idl.version());
614           ret.ref.isin = IDKind.version;
615           ret.isNew = false;
616           id.sn.names.toFirst();
617           for(j=0;j<id.sn.names.size();j++) {
618             ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
619             id.sn.names.toNext();
620           }
621           try { // searching object with idl in identification for obtaining its kind
622
Container con = cdlRepository;
623             id.sn.names.toFirst();
624             for(i=0;i<id.sn.names.size();i++) {
625               Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
626               if (a==null || a.length==0) {
627                 throw new CompRepExcept();
628               }
629               if (a.length==1) {
630                 if (a[0] instanceof Container) con = (Container) a[0];
631                 else {
632                   throw new CompRepExcept();
633                 }
634               } else {
635                 boolean found = false;
636                 for(j=0;j<a.length;j++) {
637                   if (a[j].get_identification().version().compareTo(idl.version())==0) {
638                     if ( !(a[j] instanceof Container)) {
639                       throw new CompRepExcept();
640                     }
641                     found = true;
642                     con = (Container) a[j];
643                     break;
644                   }
645                 }
646                 if (!found) {
647                   throw new CompRepExcept();
648                 }
649               }
650               id.sn.names.toNext();
651             }
652             Contained sec = con.lookup_lastinbranch(id.name, "");
653             if (sec!=null) {
654               ret.what = sec.get_def_kind().value();
655             }
656             if (ret.what == DefinitionKind.dk_Frame)
657           ret.isSystem = ((FrameDef)sec).is_system();
658         if (ret.what == DefinitionKind.dk_Architecture)
659           ret.isSystem = ((ArchitectureDef)sec).is_system();
660           } catch (TIRExceptLock e) {
661             throw new CDLExceptLock("Repository is locked.");
662           } catch (RemoteException JavaDoc e) {
663             throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
664           } catch (CompRepExcept e) {
665         searchError = "error in profile";
666             return null;
667           }
668           return ret;
669         }
670       }
671     } catch (TIRExceptLock e) {
672       throw new CDLExceptLock("Repository is locked.");
673     } catch (RemoteException JavaDoc e) {
674       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
675     }
676     // end of search in profiles
677

678     // search for head version in normal repository
679
try {
680       Container con = cdlRepository;
681       id.sn.names.toFirst();
682       for(i=0;i<id.sn.names.size();i++) {
683         Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
684         if (a==null || a.length==0)
685           throw new CompRepExcept();
686         if (a.length==1) {
687           if (a[0] instanceof Container) con = (Container) a[0];
688           else throw new CompRepExcept();
689         } else {
690           Contained last = con.lookup_lastinbranch((String JavaDoc) id.sn.names.aktual(),"");
691           if (last == null)
692             throw new CompRepExcept();
693           else
694             con = (Container) last;
695           /*boolean found = false;
696           for(j=0;j<a.length;j++) {
697             if (a[j].get_identification().version().compareTo(id.version)==0) {
698               if ( !(a[j] instanceof Container)) throw new CompRepExcept();
699               found = true;
700               con = (Container) a[j];
701               break;
702             }
703           }
704           if (!found) throw new CompRepExcept();*/

705         }
706         id.sn.names.toNext();
707       }
708       Contained sec = con.lookup_lastinbranch(id.name, "");
709       if (sec!=null) {
710         CompReffer ret = new CompReffer();
711         ret.what = sec.get_def_kind().value();
712         ret.ref = new FullID(true);
713         ret.ref.name = new String JavaDoc(id.name);
714         ret.ref.version = new String JavaDoc(sec.get_identification().version());
715         ret.ref.isin = IDKind.version;
716         ret.isNew = false;
717         id.sn.names.toFirst();
718         for(j=0;j<id.sn.names.size();j++) {
719           ret.ref.sn.addScope(new String JavaDoc((String JavaDoc)id.sn.names.aktual()));
720           id.sn.names.toNext();
721         }
722     if (ret.what == DefinitionKind.dk_Frame)
723       ret.isSystem = ((FrameDef)sec).is_system();
724     if (ret.what == DefinitionKind.dk_Architecture)
725       ret.isSystem = ((ArchitectureDef)sec).is_system();
726         return ret;
727       }
728       
729     } catch (TIRExceptLock e) {
730       throw new CDLExceptLock("Repository is locked.");
731     } catch (RemoteException JavaDoc e) {
732       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
733     } catch (CompRepExcept e) {;}
734
735     // search in higher name scope (if possible)
736
if (numPath > 0) {
737       id.sn.names.toFirst();
738       for(i=1; i<numPath; i++)
739         id.sn.names.toNext();
740       id.sn.names.removeAkt();
741
742       CompReffer ret = searchRefferDefault(id, numPath-1);
743   
744 // long tme = java.util.Calendar.getInstance().getTime().getTime();
745
// Output.out.println("@@@@@"+Long.toString(tme-tmb)+" ms "+id.toString());
746

747       return ret;
748     } else {
749       searchError = id.name + ":" + id.version + " doesn't exist";
750       return null;
751     }
752   }
753
754   public CompModule searchExistNewMod(String JavaDoc name) {
755     Scopename fullname = new Scopename();
756     int i;
757     aktScope.names.toFirst();
758     for (i=0;i<aktScope.length();i++) {
759       fullname.addScope((String JavaDoc)aktScope.names.aktual());
760       aktScope.names.toNext();
761     }
762     fullname.addScope(name);
763
764     CompContainer con = this;
765     fullname.names.toFirst();
766     for(i=0;i<fullname.names.size()-1;i++) {
767       CompContained[] a = con.lookup((String JavaDoc) fullname.names.aktual());
768       if (a==null || a.length==0)
769         return null;
770       if (a.length==1) {
771         if (a[0].isContainer()) con = (CompContainer) a[0];
772         else {
773           return null;
774         }
775       } else {
776         return null;
777       }
778       fullname.names.toNext();
779     }
780 <