KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CodeGen > Generator


1 /* $Id: Generator.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 import java.io.IOException JavaDoc;
5 import java.rmi.Naming JavaDoc;
6 import java.rmi.RemoteException JavaDoc;
7
8 import SOFA.SOFAnode.Made.TIR.ArchitectureDef;
9 import SOFA.SOFAnode.Made.TIR.ArrayDef;
10 import SOFA.SOFAnode.Made.TIR.AttributeDef;
11 import SOFA.SOFAnode.Made.TIR.CDLRepository;
12 import SOFA.SOFAnode.Made.TIR.CDLType;
13 import SOFA.SOFAnode.Made.TIR.ConstantDef;
14 import SOFA.SOFAnode.Made.TIR.Contained;
15 import SOFA.SOFAnode.Made.TIR.Container;
16 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
17 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
18 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
19 import SOFA.SOFAnode.Made.TIR.Identification;
20 import SOFA.SOFAnode.Made.TIR.InstDef;
21 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
22 import SOFA.SOFAnode.Made.TIR.ModuleDef;
23 import SOFA.SOFAnode.Made.TIR.OperationDef;
24 import SOFA.SOFAnode.Made.TIR.ParamDescr;
25 import SOFA.SOFAnode.Made.TIR.ProfileDef;
26 import SOFA.SOFAnode.Made.TIR.PropertyDef;
27 import SOFA.SOFAnode.Made.TIR.ProvideDef;
28 import SOFA.SOFAnode.Made.TIR.Repository;
29 import SOFA.SOFAnode.Made.TIR.RequireDef;
30 import SOFA.SOFAnode.Made.TIR.SequenceDef;
31 import SOFA.SOFAnode.Made.TIR.StringDef;
32 import SOFA.SOFAnode.Made.TIR.StructMember;
33 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
34 import SOFA.SOFAnode.Made.TIR.TIRObject;
35 import SOFA.SOFAnode.Made.TIR.TypedefDef;
36 import SOFA.SOFAnode.Made.TIR.UnionDef;
37 import SOFA.SOFAnode.Made.TIR.UnionMember;
38 import SOFA.SOFAnode.Made.TIR.WstringDef;
39
40 /** Code generator.
41   *
42   * @author Petr Hnetynka
43   */

44 public class Generator {
45    Repository defRepository;
46    CDLRepository cdlRepository;
47    ProfileDef profile;
48
49    ArchitectureDef[] archToGen; // architectures to generate
50

51    ObjectList objToGen;
52    
53   /** Creates connection to repository.
54     *
55     * @exception TIRAccessException error in access to the TIR
56     * @exception RemoteException remote exception
57     * @exception BadIDException an absolute name in <tt>argv</tt> is in bad format
58     * @param argv absolute names of architectures to generate
59     */

60   public Generator(String JavaDoc[] argv) throws RemoteException JavaDoc, TIRAccessException, BadIDException {
61     String JavaDoc rmiport = System.getProperty("sofa.rmiport","1099");
62     String JavaDoc rmihost = System.getProperty("sofa.rmihost","localhost");
63     String JavaDoc profileName = System.getProperty("tir.profile",null);
64     try {
65       defRepository = (Repository) Naming.lookup("//"+rmihost+":"+rmiport+"/Repository");
66     } catch (java.net.MalformedURLException JavaDoc e) {
67       throw new TIRAccessException(Res.res.getString("MSG_CantConnTIR")+" --> "+e.getMessage());
68     } catch (java.rmi.NotBoundException JavaDoc e) {
69       throw new TIRAccessException(Res.res.getString("MSG_CantConnTIR")+" --> "+e.getMessage());
70     }
71     try {
72       cdlRepository = (CDLRepository) defRepository.lookup("cdl","");
73       if (profileName != null) {
74         profile = defRepository.getProfiles().lookup(profileName);
75         if (profile == null)
76           throw new TIRAccessException(Res.res.getString("MSG_NoProfile"));
77       }
78     } catch (TIRExceptLock e) {
79       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
80     }
81     
82     if ((System.getProperty("codegen.typesonly","no").compareTo("yes"))==0) {
83       // arguments are types, only types will be generated (no holder, helper, ...)
84
// codegen.typesonly --- undocumented property :-)
85
ID[] objIds = stringsToIDs(argv);
86       objToGen = getObjectsByID(objIds);
87       archToGen = null;
88     } else { // normal behavior - arguments are architectures
89
ID[] archIds = stringsToIDs(argv);
90       Debug.println(archIds);
91       archToGen = getArchitectures(archIds);
92       Debug.println(archToGen);
93       objToGen = null;
94     }
95   }
96
97   /** Uses already created connection to TIR.
98     *
99     * @param rep reference to TIR
100     * @exception TIRAccessException error in access to the TIR
101     * @exception RemoteException remote exception
102     */

103   public Generator(Repository rep, ArchitectureDef[] archs) throws RemoteException JavaDoc, TIRAccessException {
104     if (rep == null)
105       throw new NullPointerException JavaDoc();
106     if (archs == null)
107       throw new NullPointerException JavaDoc();
108     defRepository = rep;
109     archToGen = archs;
110     try {
111       cdlRepository = (CDLRepository) defRepository.lookup("cdl","");
112     } catch (TIRExceptLock e) {
113       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
114     }
115   }
116
117   /** Convert string absolute names to ID objects.
118     *
119     * @param ids strings with absolute names
120     * @exception BadIDException a string with id in bad format
121     */

122   private ID[] stringsToIDs(String JavaDoc[] ids) throws BadIDException {
123     ID[] ret = new ID [ids.length];
124     for (int i=0;i<ids.length; i++) {
125       ret[i] = new ID(ids[i]);
126     }
127     return ret;
128   }
129
130   /** Return reference to specified object.
131     *
132     * @param id id of the object
133     * @exception RemoteException remote exception
134     * @exception TIRAccessException error in access to the TIR
135     * @return reference to object
136     */

137   private Contained getObjectByName(ID id) throws RemoteException JavaDoc, TIRAccessException {
138     try {
139       Container con = cdlRepository;
140       int i;
141       Contained[] a;
142       if (id.version()!=null && id.version().compareTo("")!=0) { // version is set
143
for(i=0;i<id.size()-1;i++) {
144           a = con.lookup_name(id.get(i));
145           if (a==null || a.length==0)
146             throw new TIRAccessException(id.toString()+" "+Res.res.getString("MSG_DoesntExist"));
147           if (a.length==1) {
148             con = (Container) a[0];
149           } else {
150             boolean found = false;
151             for(int j=0;j<a.length;j++) {
152               if (a[j].get_identification().version().compareTo(id.version())==0) {
153                 found = true;
154                 con = (Container) a[j];
155                 break;
156               }
157             }
158             if (!found) throw new TIRAccessException(id.toString()+" "+Res.res.getString("MSG_DoesntExist"));
159           }
160         }
161         Contained ret = con.lookup(id.get(i), id.version());
162         if (ret==null)
163           throw new TIRAccessException(id.toString()+" "+Res.res.getString("MSG_DoesntExist"));
164         return ret;
165       } else { // version is not set
166
for(i=0;i<id.size()-1;i++) {
167           a = con.lookup_name(id.get(i));
168           if (a==null || a.length==0)
169             throw new TIRAccessException(id.toString()+" "+Res.res.getString("MSG_DoesntExist"));
170           if (a.length==1) {
171             con = (Container) a[0];
172           } else { // more objects with same name
173
throw new TIRAccessException(Res.res.getString("MSG_MoreVersions")+" "+id.toString()+"\n"+Res.res.getString("MSG_UseProfile"));
174           }
175         }
176         a = con.lookup_name(id.get(i));
177         if (a==null || a.length==0)
178           throw new TIRAccessException(id.toString()+" "+Res.res.getString("MSG_DoesntExist"));
179         if (a.length==1)
180           return a[0];
181         else // more versions
182
throw new TIRAccessException(Res.res.getString("MSG_MoreVersions")+" "+id.toString()+"\n"+Res.res.getString("MSG_UseProfile"));
183       }
184       
185     } catch (TIRExceptLock e) {
186       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
187     }
188   }
189
190   /** Get architectures from ids. If version is not set, it search in profiles first.
191     *
192     * @exception RemoteException remote exception
193     * @exception TIRAccessException error in access to the TIR
194     * @param ids ids of architectures
195     */

196   private ArchitectureDef[] getArchitectures(ID[] ids) throws RemoteException JavaDoc, TIRAccessException {
197     ArchitectureDef[] ret = new ArchitectureDef [ids.length];
198     Contained a;
199     try {
200       for (int i=0;i<ids.length;i++) {
201         if (profile == null) { // profile was not set
202
a = getObjectByName(ids[i]);
203           if (a.get_def_kind().value() != DefinitionKind.dk_Architecture)
204             throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_IsNotArchitecture"));
205           ret[i] = (ArchitectureDef) a;
206         } else { // profile is set
207
if (ids[i].version()!=null && ids[i].version().compareTo("")!=0) { // version is set, search directly in objects
208
a = getObjectByName(ids[i]);
209             if (a.get_def_kind().value() != DefinitionKind.dk_Architecture)
210               throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_IsNotArchitecture"));
211             ret[i] = (ArchitectureDef) a;
212           } else { // search in profile first
213
Identification idp = profile.lookup("::cdl"+ids[i].absoluteName());
214             if (idp!=null) { // object is in profile
215
Container con = cdlRepository;
216               int k = 0;
217               for(k=0;k<ids[i].size()-1;k++) {
218                 Contained[] x = con.lookup_name(ids[i].get(k));
219                 if (x==null || x.length==0)
220                   throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_DoesntExist"));
221                 if (x.length==1) {
222                   con = (Container) x[0];
223                 } else {
224                   boolean found = false;
225                   for(int j=0;j<x.length;j++) {
226                     if (x[j].get_identification().version().compareTo(idp.version())==0) {
227                       found = true;
228                       con = (Container) x[j];
229                       break;
230                     }
231                   }
232                   if (!found) throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_DoesntExist"));
233                 }
234               }
235               a = con.lookup(ids[i].get(k), idp.version());
236               if (a==null)
237                 throw new TIRAccessException("MSG_ErrorProfile");
238               if (a.get_def_kind().value() != DefinitionKind.dk_Architecture)
239                 throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_IsNotArchitecture"));
240               ret[i] = (ArchitectureDef) a;
241             } else { // object is not in profile
242
a = getObjectByName(ids[i]);
243               if (a.get_def_kind().value() != DefinitionKind.dk_Architecture)
244                 throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_IsNotArchitecture"));
245               ret[i] = (ArchitectureDef) a;
246             }
247           }
248         }
249       }
250     } catch (TIRExceptLock e) {
251       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
252     }
253     return ret;
254   }
255
256   /** absolute name in string converts to ArrayList */
257   private java.util.ArrayList JavaDoc absNameToList(String JavaDoc name) {
258     java.util.ArrayList JavaDoc ret = new java.util.ArrayList JavaDoc(10);
259     int i;
260     int count = 0;
261     for (i=0;i<name.length();i++) {
262       if (name.charAt(i)==':' && name.charAt(i+1)==':')
263         count++;
264     }
265     int j = 0;
266     for(i=0;i<count;i++) {
267       StringBuffer JavaDoc str = new StringBuffer JavaDoc();
268       while (name.charAt(j)==':')
269         j++;
270       while (name.charAt(j)!=':' && j<name.length()) {
271         str = str.append(name.charAt(j));
272         j++;
273       }
274       ret.add(str.toString());
275     }
276     if (ret.size()==0)
277       return null;
278     return ret;
279   }
280
281   /** Find frame of instance. It goes through typedefs and arrays.
282     *
283     * @param inst instance from which frame is searched
284     * @exception RemoteException remote exception
285     */

286   CDLType getFrameOfInst(InstDef inst) throws RemoteException JavaDoc {
287     CDLType obj = inst.type();
288     int defKind = obj.get_def_kind().value();
289     while (defKind == DefinitionKind.dk_Typedef || defKind == DefinitionKind.dk_Array) {
290       if (defKind == DefinitionKind.dk_Typedef)
291         obj = ((TypedefDef) obj).original_type();
292       else
293         obj = ((ArrayDef) obj).element_type();
294       defKind = obj.get_def_kind().value();
295     }
296     return obj;
297   }
298
299   /** Returns list with all frames, which must be generated.
300     *
301     * @param obj architecture from which frames are searched
302     * @exception RemoteException remote exception
303     * @exception TIRAccessException error in access to the TIR
304     */

305   private ObjectList getAllFrames(ArchitectureDef obj) throws RemoteException JavaDoc, TIRAccessException {
306     ObjectList list = new ObjectList();
307     list.add(obj.frame());
308     Contained[] cont = null;
309     try {
310       // get instances only
311
cont = obj.contents(defRepository.get_spec_def_kind(DefinitionKind.dk_Inst));
312     } catch (TIRExceptLock e) {
313       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
314     }
315     for (int i=0; i<cont.length; i++) {
316       CDLType frame = getFrameOfInst((InstDef) cont[i]);
317       if (frame.get_def_kind().value() != DefinitionKind.dk_Frame) {
318         Identification idl = obj.get_identification();
319         throw new TIRAccessException(Res.res.getString("MSG_InstTIRError")+" "+idl.absolute_name().name()+":"+idl.version());
320       }
321       list.add(frame);
322     }
323     return list;
324   }
325
326   /** Gets list with all objects, which must be generated.
327     *
328     * @param frames list of frames from which objects are searched
329     * @exception RemoteException remote exception
330     * @exception TIRAccessException error in access to the TIR
331     */

332   private ObjectList getAllObjects(ObjectList frames) throws RemoteException JavaDoc, TIRAccessException {
333     ObjectList types = new ObjectList();
334     try {
335       int i;
336       for (i=0;i<frames.size();i++) { // add all objects from frames
337
Contained[] cont = ((Container)frames.getObject(i)).contents(null);
338         int j;
339         for (j=0;j< cont.length; j++) {
340           firstLevelOfScaning = true;
341           scanObject(cont[j], types);
342         }
343       }
344       for(i=0;i<types.size(); i++) {
345         firstLevelOfScaning = true;
346         scanObject(types.getObject(i), types);
347       }
348     } catch (TIRExceptLock e) {
349       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
350     }
351     return types;
352   }
353
354   
355   private boolean firstLevelOfScaning;
356
357   /** Add all objects that are in <tt>obj</tt> to the <tt>list</tt>.
358     *
359     * @param obj scanned object
360     * @param list add all types to this list
361     * @exception RemoteException remote exception
362     * @exception TIRAccessException error in access to the TIR
363     */

364   private void scanObject(TIRObject obj, ObjectList list) throws RemoteException JavaDoc, TIRAccessException {
365     try {
366       if (obj instanceof Contained) {
367         Debug.println("Enter scanObject with: "+((Contained)obj).get_identification().name());
368 // System.out.println(firstLevelOfScaning);
369
}
370       Debug.println(list);
371       
372       if (!firstLevelOfScaning && (obj instanceof Contained) && list.containsObject((Contained)obj)) {
373 // System.out.println("*** End (break) of \"scanObject\" method "+((Contained)obj).get_identification().name());
374
return;
375       }
376
377       firstLevelOfScaning = false;
378       
379       int i;
380       int defKind;
381       Contained[] cont;
382       Container defIn;
383       Contained cobj;
384       CDLType tp, newtp;
385       boolean scan = true;
386       switch (obj.get_def_kind().value()) {
387       case DefinitionKind.dk_Attribute:
388         cobj = (Contained) obj;
389         tp = ((AttributeDef) obj).type();
390         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
391           if (tp instanceof Contained) {
392             if (!list.containsObject((Contained) tp)) {
393               list.addObject((Contained) tp);
394             } else {
395               scan = false;
396             }
397           }
398           if (scan)
399             scanObject( tp, list);
400         }
401         break;
402       case DefinitionKind.dk_Constant:
403         cobj = (Contained) obj;
404         tp = ((ConstantDef) obj).type();
405         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
406           if (tp instanceof Contained) {
407             if (!list.containsObject((Contained) tp)) {
408               list.addObject((Contained) tp);
409             } else {
410               scan = false;
411             }
412           }
413           if (scan)
414             scanObject( tp, list);
415         }
416         Expressions.scanExpr(((ConstantDef)obj).value(),list);
417         if (! (cobj.get_defined_in() instanceof InterfaceDef)) // add only constants not within an interface
418
list.addObject(cobj);
419         break;
420       case DefinitionKind.dk_Interface:
421         cobj = (Contained) obj;
422         cont = ((Container)obj).contents(null);
423         for (i=0;i<cont.length;i++) {
424           scanObject(cont[i], list);
425         }
426         InterfaceDef[] bIfaces = ((InterfaceDef) obj).base_interfaces();
427         for (i=0;i<bIfaces.length;i++) {
428           list.addObject(bIfaces[i]);
429         }
430         list.addObject(cobj);
431         break;
432       case DefinitionKind.dk_Operation:
433         cobj = (Contained) obj;
434         tp = ((OperationDef) obj).result();
435         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
436           if (tp instanceof Contained) {
437             if (!list.containsObject((Contained) tp)) {
438               list.addObject((Contained) tp);
439             } else {
440               scan = false;
441             }
442           }
443           if (scan)
444             scanObject( tp, list);
445         }
446         ParamDescr[] par = ((OperationDef) obj).params();
447         for(i=0;i<par.length;i++) {
448           tp = par[i].type();
449           if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
450             if (tp instanceof Contained) {
451               if (!list.containsObject((Contained) tp)) {
452                 list.addObject((Contained) tp);
453               } else {
454                 scan = false;
455               }
456             }
457             if (scan)
458               scanObject( tp, list);
459           }
460         }
461         ExceptionDef[] excs = ((OperationDef) obj).exceptions();
462         Contained newcont;
463         for (i=0;i<excs.length; i++) {
464           newcont = excs[i];
465           defIn = newcont.get_defined_in();
466           while (!(defIn instanceof ModuleDef || defIn instanceof Repository)) {
467             newcont = (Contained) defIn;
468             defIn = newcont.get_defined_in();
469           }
470           list.addObject(newcont);
471           scanObject(excs[i], list);
472         }
473         break;
474       case DefinitionKind.dk_Typedef:
475         cobj = (Contained) obj;
476         tp = ((TypedefDef) obj).original_type();
477         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
478           if (tp instanceof Contained) {
479             if (!list.containsObject((Contained) tp)) {
480               list.addObject((Contained) tp);
481             } else {
482               scan = false;
483             }
484           }
485           if (scan)
486             scanObject( tp, list);
487         }
488         list.addObject(cobj);
489         break;
490       case DefinitionKind.dk_Exception:
491       case DefinitionKind.dk_Struct:
492         cobj = (Contained) obj;
493         cont = ((Container)obj).contents(null);
494         for (i=0;i<cont.length;i++) {
495           scanObject(cont[i], list);
496         }
497         defIn = cobj.get_defined_in();
498         if (defIn instanceof ModuleDef || defIn instanceof Repository ) {
499           list.addObject(cobj);
500         }
501         break;
502       case DefinitionKind.dk_Union:
503         cobj = (Contained) obj;
504         cont = ((Container)obj).contents(null);
505         for (i=0;i<cont.length;i++) {
506           scanObject(cont[i], list);
507         }
508         tp = ((UnionDef) obj).switch_type();
509         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
510           list.addObject((Contained) tp);
511           scanObject( tp, list);
512         }
513         defIn = cobj.get_defined_in();
514         if (defIn instanceof ModuleDef || defIn instanceof Repository )
515           list.addObject(cobj);
516         break;
517       case DefinitionKind.dk_Enum:
518         cobj = (Contained) obj;
519         defIn = cobj.get_defined_in();
520         if (defIn instanceof ModuleDef || defIn instanceof Repository )
521           list.addObject(cobj);
522         break;
523       case DefinitionKind.dk_Sequence:
524         tp = ((SequenceDef) obj).element_type();
525         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
526           if (tp instanceof Contained) {
527             if (!list.containsObject((Contained) tp)) {
528               list.addObject((Contained) tp);
529             } else {
530               scan = false;
531             }
532           }
533           if (scan)
534             scanObject( tp, list);
535         }
536         Expressions.scanExpr(((SequenceDef) obj).bound(),list);
537         break;
538       case DefinitionKind.dk_Array:
539         tp = ((ArrayDef) obj).element_type();
540         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
541           if (tp instanceof Contained) {
542             if (!list.containsObject((Contained) tp)) {
543               list.addObject((Contained) tp);
544             } else {
545               scan = false;
546             }
547           }
548           if (scan)
549             scanObject( tp, list);
550         }
551         Expressions.scanExpr(((ArrayDef) obj).length(),list);
552         break;
553       case DefinitionKind.dk_Frame:
554         cont = ((Container)obj).contents(null);
555         for (i=0;i<cont.length;i++) {
556           scanObject(cont[i], list);
557         }
558         break;
559       case DefinitionKind.dk_Provides:
560         list.addObject( (Contained) ((ProvideDef) obj).provide());
561         break;
562       case DefinitionKind.dk_Requires:
563         list.addObject( (Contained) ((RequireDef) obj).require());
564         break;
565       case DefinitionKind.dk_Property:
566         cobj = (Contained) obj;
567         tp = ((PropertyDef) obj).type();
568         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
569           if (tp instanceof Contained) {
570             if (!list.containsObject((Contained) tp)) {
571               list.addObject((Contained) tp);
572             } else {
573               scan = false;
574             }
575           }
576           if (scan)
577             scanObject( tp, list);
578         }
579         // list.addObject(cobj);
580
break;
581       case DefinitionKind.dk_StructMember:
582         tp = ((StructMember) obj).type();
583         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
584           if (tp instanceof Contained) {
585             newtp = tp;
586             defIn = ((Contained) newtp).get_defined_in();
587             while (!(defIn instanceof ModuleDef || defIn instanceof Repository)) {
588               newtp = (CDLType) defIn;
589               defIn = ((Contained) newtp).get_defined_in();
590             }
591             list.addObject((Contained) newtp);
592           }
593           scanObject( tp, list);
594         }
595         break;
596       case DefinitionKind.dk_UnionMember:
597         tp = ((UnionMember) obj).type();
598         if (tp.get_def_kind().value() != DefinitionKind.dk_Primitive) {
599           if (tp instanceof Contained) {
600             newtp = tp;
601             defIn = ((Contained) newtp).get_defined_in();
602             while (!(defIn instanceof ModuleDef || defIn instanceof Repository)) {
603               newtp = (CDLType) defIn;
604               defIn = ((Contained) newtp).get_defined_in();
605             }
606             list.addObject((Contained) newtp);
607           }
608           scanObject( tp, list);
609         }
610         ExprOperDef[] exprs = ((UnionMember) obj).label();
611         for (i=0;i<exprs.length;i++) {
612           Expressions.scanExpr(exprs[i],list);
613         }
614         break;
615       case DefinitionKind.dk_String:
616         Expressions.scanExpr(((StringDef) obj).bound(),list);
617         break;
618       case DefinitionKind.dk_Wstring:
619         Expressions.scanExpr(((WstringDef) obj).bound(),list);
620         break;
621       }
622
623
624       
625 // if (obj instanceof Contained)
626
// System.out.println("*** End of \"scanObject\" method "+((Contained)obj).get_identification().name());
627

628     } catch (TIRExceptLock e) {
629       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
630     }
631   }
632
633   /** Run generation of code.
634     *
635     * @exception RemoteException remote exception
636     * @exception TIRAccessException error in access to the TIR
637     */

638   public void generate() throws RemoteException JavaDoc, TIRAccessException, IOException JavaDoc, GenerException {
639     JavaGenerator jgen;
640     if (archToGen != null) {
641       // normal (full) generation
642
ObjectList allFrames = new ObjectList();
643       ObjectList fr;
644       int i;
645       for (i=0;i<archToGen.length;i++) {
646         fr = getAllFrames(archToGen[i]);
647         allFrames.mergeTogether(fr);
648       }
649       Debug.println(allFrames);
650
651       ObjectList allObjects = getAllObjects(allFrames);
652       Debug.println(allObjects);
653
654       jgen = new JavaGenerator(allObjects, archToGen);
655     } else {
656       // typesonly generation
657
Debug.println(objToGen);
658       ObjectList allObjects = getAllTypeObjects(objToGen);
659       Debug.println(allObjects);
660       jgen = new JavaGenerator(allObjects, true);
661     }
662     jgen.generate();
663   }
664
665   /** Get objects from ids. If version is not set, it search in profiles first.
666     * This method is used only, when codegen.typesonly property is used.
667     *
668     * @exception RemoteException remote exception
669     * @exception TIRAccessException error in access to the TIR
670     * @param ids ids of object
671     */

672   private ObjectList getObjectsByID(ID[] ids) throws RemoteException JavaDoc, TIRAccessException {
673     ObjectList ret = new ObjectList();
674     Contained a;
675     try {
676       for (int i=0;i<ids.length;i++) {
677         if (profile == null) { // profile was not set
678
a = getObjectByName(ids[i]);
679           ret.addObject(a);
680         } else { // profile is set
681
if (ids[i].version()!=null && ids[i].version().compareTo("")!=0) { // version is set, search directly in objects
682
a = getObjectByName(ids[i]);
683             ret.addObject(a);
684           } else { // search in profile first
685
Identification idp = profile.lookup("::cdl"+ids[i].absoluteName());
686             if (idp!=null) { // object is in profile
687
Container con = cdlRepository;
688               int k = 0;
689               for(k=0;k<ids[i].size()-1;k++) {
690                 Contained[] x = con.lookup_name(ids[i].get(k));
691                 if (x==null || x.length==0)
692                   throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_DoesntExist"));
693                 if (x.length==1) {
694                   con = (Container) x[0];
695                 } else {
696                   boolean found = false;
697                   for(int j=0;j<x.length;j++) {
698                     if (x[j].get_identification().version().compareTo(idp.version())==0) {
699                       found = true;
700                       con = (Container) x[j];
701                       break;
702                     }
703                   }
704                   if (!found) throw new TIRAccessException(ids[i].toString()+" "+Res.res.getString("MSG_DoesntExist"));
705                 }
706               }
707               a = con.lookup(ids[i].get(k), idp.version());
708               if (a==null)
709                 throw new TIRAccessException("MSG_ErrorProfile");
710               ret.addObject(a);
711             } else { // object is not in profile
712
a = getObjectByName(ids[i]);
713               ret.addObject(a);
714             }
715           }
716         }
717       }
718     } catch (TIRExceptLock e) {
719       throw new TIRAccessException(Res.res.getString("MSG_LockedTIR")+" --> "+e.getMessage());
720     }
721     return ret;
722   }
723
724   /** Gets list with all objects, which must be generated.
725     * Used only, when codegen.typesonly property is used.
726     *
727     * @param obj list of objects from which objects are searched
728     * @exception RemoteException remote exception
729     * @exception TIRAccessException error in access to the TIR
730     */

731   private ObjectList getAllTypeObjects(ObjectList obj) throws RemoteException JavaDoc, TIRAccessException {
732     int i;
733     for(i=0;i<obj.size(); i++) {
734       firstLevelOfScaning = true;
735       scanObject(obj.getObject(i), obj);
736     }
737     return obj;
738   }
739 }
740
Popular Tags