KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: CompReffer.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CDL;
3 import java.rmi.RemoteException JavaDoc;
4
5 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
6 import SOFA.SOFAnode.Made.TIR.ArrayDef;
7 import SOFA.SOFAnode.Made.TIR.AttributeDef;
8 import SOFA.SOFAnode.Made.TIR.CDLRepository;
9 import SOFA.SOFAnode.Made.TIR.CDLType;
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.ExceptionDef;
15 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
16 import SOFA.SOFAnode.Made.TIR.FixedDef;
17 import SOFA.SOFAnode.Made.TIR.Identification;
18 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
19 import SOFA.SOFAnode.Made.TIR.OperationDef;
20 import SOFA.SOFAnode.Made.TIR.ParamDescr;
21 import SOFA.SOFAnode.Made.TIR.PrimitiveDef;
22 import SOFA.SOFAnode.Made.TIR.PrimitiveKind;
23 import SOFA.SOFAnode.Made.TIR.SequenceDef;
24 import SOFA.SOFAnode.Made.TIR.StringDef;
25 import SOFA.SOFAnode.Made.TIR.StructMember;
26 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
27 import SOFA.SOFAnode.Made.TIR.TIRObject;
28 import SOFA.SOFAnode.Made.TIR.TypedefDef;
29 import SOFA.SOFAnode.Made.TIR.UnionDef;
30 import SOFA.SOFAnode.Made.TIR.UnionMember;
31 import SOFA.SOFAnode.Made.TIR.WstringDef;
32
33 class CompReffer extends CompObjectIm implements CompType {
34   public int what; /* what is reffered */
35   public CompPrimitive primKind;
36   public FullID ref;
37   public boolean isNew; // false -- object is in repository
38
public int line;
39   public int basereffer; // for typedefs (the base type of typedef)
40
public int baserefferprim; // set if basereffer is Primitive
41
public boolean isSystem; // if architecture or frame is system
42

43   public CompReffer() {
44     super(ObjectsKind.o_none);
45     line = 0;
46     basereffer = 0;
47     isSystem = false;
48   }
49
50   public String JavaDoc toString() {
51     if (ref!=null)
52       return ref.toString();
53     return "";
54   }
55
56   public Object JavaDoc getRefferedObject(CompRepository rep) throws CDLExceptLock, CDLExceptRemote {
57     int i,j;
58
59     if (isNew) {
60       CompContainer con = rep;
61       ref.sn.names.toFirst();
62       for(i=0;i<ref.sn.names.size();i++) {
63         CompContained[] a = con.lookup((String JavaDoc) ref.sn.names.aktual());
64         con = (CompContainer) a[0];
65         ref.sn.names.toNext();
66       }
67       return con.lookup(ref.name, ref.version);
68     } else {
69       try {
70         Container con = rep.cdlRepository;
71         ref.sn.names.toFirst();
72         for(i=0;i<ref.sn.names.size();i++) {
73           Contained[] a = con.lookup_name((String JavaDoc) ref.sn.names.aktual());
74           if (a.length==1) {
75             con = (Container) a[0];
76           } else {
77             for(j=0;j<a.length;j++) {
78               if (a[j].get_identification().version().compareTo(ref.version)==0) {
79                 con = (Container) a[j];
80                 break;
81               }
82             }
83           }
84           ref.sn.names.toNext();
85         }
86         return con.lookup(ref.name, ref.version);
87       } catch (TIRExceptLock e) {
88         throw new CDLExceptLock("Repository is locked.");
89       } catch (RemoteException JavaDoc e) {
90         throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
91       }
92     }
93   }
94
95   public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote {
96     int i,j;
97     if (isNew) {
98       CompContainer con = rep;
99       ref.sn.names.toFirst();
100       for(i=0;i<ref.sn.names.size();i++) {
101         CompContained[] a = con.lookup((String JavaDoc) ref.sn.names.aktual());
102         con = (CompContainer) a[0];
103         ref.sn.names.toNext();
104       }
105       CompContained sec = con.lookup(ref.name, ref.version);
106       sec.checkConsist(props, rep);
107     } else {
108       try {
109         Container con = rep.cdlRepository;
110         ref.sn.names.toFirst();
111         for(i=0;i<ref.sn.names.size();i++) {
112           Contained[] a = con.lookup_name((String JavaDoc) ref.sn.names.aktual());
113           if (a.length==1) {
114             con = (Container) a[0];
115           } else {
116             for(j=0;j<a.length;j++) {
117               if (a[j].get_identification().version().compareTo(ref.version)==0) {
118                 con = (Container) a[j];
119                 break;
120               }
121             }
122           }
123           ref.sn.names.toNext();
124         }
125         Contained sec = con.lookup(ref.name, ref.version);
126         checkNormalConsist(sec,props, rep.cdlRepository);
127       } catch (TIRExceptLock e) {
128         throw new CDLExceptLock("Repository is locked.");
129       } catch (RemoteException JavaDoc e) {
130         throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
131       }
132     }
133   }
134
135   private void checkNormalConsist(TIRObject obj, EnumList props, CDLRepository rep) throws CDLExceptCheck, TIRExceptLock, RemoteException JavaDoc, CDLExceptRemote {
136     int i;
137     if (obj instanceof Container) {
138       Contained[] con = ((Container) obj).contents(null);
139       for (i=0;i<con.length;i++) {
140         checkNormalConsist(con[i], props, rep);
141       }
142       switch (obj.get_def_kind().value()) {
143       case DefinitionKind.dk_Interface:
144         InterfaceDef[] base = ((InterfaceDef) obj).base_interfaces();
145         for (i=0;i<base.length;i++) {
146           checkNormalConsist(base[i], props, rep);
147         }
148         break;
149       case DefinitionKind.dk_Union:
150         checkNormalConsist(((UnionDef) obj).switch_type(), props, rep);
151         break;
152       }
153     } else { // non Container
154
switch (obj.get_def_kind().value()) {
155       case DefinitionKind.dk_Typedef:
156         checkNormalConsist(((TypedefDef) obj).original_type(), props, rep);
157         break;
158       case DefinitionKind.dk_Array:
159         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((ArrayDef) obj).length())))
160           throw new CDLExceptCheck("Unknown property");
161         checkNormalConsist(((ArrayDef) obj).element_type(), props, rep);
162         break;
163       case DefinitionKind.dk_Sequence:
164         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((SequenceDef) obj).bound())))
165           throw new CDLExceptCheck("Unknown property");
166         checkNormalConsist(((SequenceDef) obj).element_type(), props, rep);
167         break;
168       case DefinitionKind.dk_String:
169         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((StringDef) obj).bound())))
170           throw new CDLExceptCheck("Unknown property");
171         break;
172       case DefinitionKind.dk_Wstring:
173         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((WstringDef) obj).bound())))
174           throw new CDLExceptCheck("Unknown property");
175         break;
176       case DefinitionKind.dk_Fixed:
177         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((FixedDef) obj).digits())))
178           throw new CDLExceptCheck("Unknown property");
179         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((FixedDef) obj).scale())))
180           throw new CDLExceptCheck("Unknown property");
181         break;
182       case DefinitionKind.dk_StructMember:
183         checkNormalConsist(((StructMember) obj).type(), props, rep);
184         break;
185       case DefinitionKind.dk_UnionMember:
186         checkNormalConsist(((UnionMember) obj).type(), props, rep);
187         ExprOperDef[] labs = ((UnionMember) obj).label();
188         for(i=0;i<labs.length;i++) {
189           if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(labs[i])))
190             throw new CDLExceptCheck("Unknown property");
191         }
192         break;
193       case DefinitionKind.dk_Attribute:
194         checkNormalConsist(((AttributeDef) obj).type(), props, rep);
195         break;
196       case DefinitionKind.dk_Operation:
197         checkNormalConsist(((OperationDef) obj).result(), props, rep);
198         ExceptionDef[] exs = ((OperationDef) obj).exceptions();
199         for (i=0;i<exs.length;i++) {
200           checkNormalConsist(exs[i], props, rep);
201         }
202         ParamDescr[] pars = ((OperationDef) obj).params();
203         for (i=0;i<exs.length;i++) {
204           checkNormalConsist(pars[i].type(), props, rep);
205         }
206         break;
207       case DefinitionKind.dk_Constant:
208         checkNormalConsist(((ConstantDef) obj).type(), props, rep);
209         if (!CompExprOper.testPropInExpr(props, CompExprOper.scanNormalExpr(((ConstantDef) obj).value())))
210           throw new CDLExceptCheck("Unknown property");
211         break;
212       // others are OK
213
}
214     }
215   }
216
217   public CDLType toNormal(CDLRepository newRep) throws CDLExceptRemote, CDLExceptToNormal, CDLExceptLock {
218     try {
219       int i,j;
220       Container con = newRep;
221       ref.sn.names.toFirst();
222       for(i=0;i<ref.sn.names.size();i++) {
223         Contained[] a = con.lookup_name((String JavaDoc) ref.sn.names.aktual());
224         if (a==null || a.length==0)
225           throw new CDLExceptToNormal("Can't find type "+ref);
226         if (a.length==1) {
227           if (!(a[0] instanceof Container))
228             throw new CDLExceptToNormal("Can't find type "+ref);
229           con = (Container) a[0];
230         } else {
231           boolean found = false;
232           for(j=0;j<a.length;j++) {
233             if (a[j].get_identification().version().compareTo(ref.version)==0) {
234               if (!(a[j] instanceof Container))
235                 throw new CDLExceptToNormal("Can't find type "+ref);
236               con = (Container) a[j];
237               found = true;
238               break;
239             }
240           }
241           if (!found)
242             throw new CDLExceptToNormal("Can't find type "+ref);
243         }
244         ref.sn.names.toNext();
245       }
246       Contained sec = con.lookup(ref.name, ref.version);
247       if (sec==null)
248         throw new CDLExceptToNormal("Can't find type "+ref);
249       return (CDLType) sec;
250     } catch (TIRExceptLock e) {
251       throw new CDLExceptLock("Repository is locked.");
252     } catch (RemoteException JavaDoc e) {
253       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
254     }
255   }
256
257   /** if object's kind is type */
258   public static boolean isType(int kind) {
259     switch (kind) {
260       case ObjectsKind.o_Typedef:
261       case ObjectsKind.o_Struct:
262       case ObjectsKind.o_Union:
263       case ObjectsKind.o_Enum:
264       case ObjectsKind.o_Primitive:
265       case ObjectsKind.o_String:
266       case ObjectsKind.o_Sequence:
267       case ObjectsKind.o_Array:
268       case ObjectsKind.o_Wstring:
269       case ObjectsKind.o_Fixed:
270       case ObjectsKind.o_Interface:
271       case ObjectsKind.o_Frame:
272         return true;
273     }
274     return false;
275   }
276
277   /** if object's kind is const_type */
278   public static boolean isConstType(int kind) {
279     switch (kind) {
280       case ObjectsKind.o_Primitive:
281       case ObjectsKind.o_String:
282       case ObjectsKind.o_Wstring:
283       case ObjectsKind.o_Fixed:
284       case ObjectsKind.o_Enum:
285         return true;
286     }
287     return false;
288   }
289
290   /** if object's kind is param_type */
291   public static boolean isParamType(int kind) {
292     switch (kind) {
293       case ObjectsKind.o_Primitive:
294       case ObjectsKind.o_String:
295       case ObjectsKind.o_Wstring:
296       case ObjectsKind.o_Struct:
297       case ObjectsKind.o_Union:
298       case ObjectsKind.o_Enum:
299       case ObjectsKind.o_Interface:
300         return true;
301     }
302     return false;
303   }
304
305   /** if CompReffer typedef, scan through it (what must be type) */
306   public static boolean isConstType(CompReffer what, CompRepository rep) throws CDLExceptRemote, CDLExceptLock {
307    boolean ok = false;
308    int kind = what.what;
309    CompReffer r = what;
310    while (!ok) {
311      if (!CompReffer.isConstType(kind)) {
312        if (kind == ObjectsKind.o_Typedef) {
313          int i,j;
314          FullID id = r.ref;
315          if (r.isNew) { // in actually added objects
316
CompContainer con = rep;
317            id.sn.names.toFirst();
318            for(i=0;i<id.sn.names.size();i++) {
319              CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
320              if (a==null || a.length==0)
321                return false;
322              if (a.length==1) {
323                if (a[0].isContainer()) con = (CompContainer) a[0];
324                else return false;
325              } else {
326                return false;
327              }
328              id.sn.names.toNext();
329            }
330            CompContained sec = con.lookup(id.name, id.version);
331            if (sec!=null) {
332              CompType sectype = ((CompTypedef) sec).type;
333              if (!isConstType(sectype.objectKind())) {
334                if (sectype.objectKind()==ObjectsKind.o_none) { // is CompReffer
335
r = (CompReffer) sectype;
336                  kind = r.what;
337                } else
338                  return false;
339              } else {
340                what.basereffer = sectype.objectKind();
341                if (sectype.objectKind()==ObjectsKind.o_Primitive)
342                  what.baserefferprim = ((CompPrimitive)sectype).kind;
343                ok = true;
344              }
345            } else
346              return false;
347          } else { // in normal repository
348
try {
349              Container con = rep.cdlRepository;
350              id.sn.names.toFirst();
351              for(i=0;i<id.sn.names.size();i++) {
352                Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
353                if (a==null || a.length==0)
354                  return false;
355                if (a.length==1) {
356                  if (a[0] instanceof Container) con = (Container) a[0];
357                  else return false;
358                } else {
359                  boolean found = false;
360                  for(j=0;j<a.length;j++) {
361                    if (a[j].get_identification().version().compareTo(id.version)==0) {
362                      if ( !(a[j] instanceof Container)) return false;
363                      found = true;
364                      con = (Container) a[j];
365                      break;
366                    }
367                  }
368                  if (!found) return false;
369                }
370                id.sn.names.toNext();
371              }
372              Contained sec = con.lookup(id.name, id.version);
373              if (sec!=null) {
374                CDLType sectype = ((TypedefDef) sec).original_type();
375                if (!isConstType(sectype.get_def_kind().value())) {
376                  if (sectype.get_def_kind().value() == DefinitionKind.dk_Typedef) {
377                    CompReffer ret = new CompReffer();
378                    ret.what = sectype.get_def_kind().value();
379                    ret.ref = new FullID(true);
380                    Identification idl;
381                    ret.ref.name = new String JavaDoc((idl = ((TypedefDef)sectype).get_identification()).name());
382                    ret.ref.version = new String JavaDoc(idl.version());
383                    ret.ref.isin = IDKind.version;
384                    ret.isNew = false;
385                    AbsoluteName abs = idl.absolute_name();
386                    for(j=0;j<abs.size();j++) {
387                      ret.ref.sn.addScope(new String JavaDoc(abs.elementAt(j)));
388                    }
389                    r = ret;
390                    kind = r.what;
391                  } else
392                    return false;
393                } else {
394                  what.basereffer = sectype.get_def_kind().value();
395                  if (sectype.get_def_kind().value()==DefinitionKind.dk_Primitive)
396                    what.baserefferprim = ((PrimitiveDef)sectype).kind().value();
397                  ok = true;
398                }
399              } else {
400                return false;
401              }
402            } catch (TIRExceptLock e) {
403              throw new CDLExceptLock("Repository is locked.");
404            } catch (RemoteException JavaDoc e) {
405              throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
406            }
407          }
408        } else {
409          return false;
410        }
411      } else {
412        what.basereffer = kind;
413        ok = true;
414      }
415    }
416    return true;
417   }
418
419   /** if object's kind is switch_type */
420   public static boolean isSwitchType(int a) {
421     switch (a) {
422       case ObjectsKind.o_Primitive:
423       case ObjectsKind.o_Enum:
424         return true;
425     }
426     return false;
427   }
428
429   public static boolean isSwitchType(CompReffer what, CompRepository rep) throws CDLExceptRemote, CDLExceptLock {
430    boolean ok = false;
431    int kind = what.what;
432    CompReffer r = what;
433    while (!ok) {
434      if (!CompReffer.isConstType(kind)) {
435        if (kind == ObjectsKind.o_Typedef) {
436          int i,j;
437          FullID id = r.ref;
438          if (r.isNew) { // in actually added objects
439
CompContainer con = rep;
440            id.sn.names.toFirst();
441            for(i=0;i<id.sn.names.size();i++) {
442              CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
443              if (a==null || a.length==0)
444                return false;
445              if (a.length==1) {
446                if (a[0].isContainer()) con = (CompContainer) a[0];
447                else return false;
448              } else {
449                return false;
450              }
451              id.sn.names.toNext();
452            }
453            CompContained sec = con.lookup(id.name, id.version);
454            if (sec!=null) {
455              CompType sectype = ((CompTypedef) sec).type;
456              if (!isConstType(sectype.objectKind())) {
457                if (sectype.objectKind()==ObjectsKind.o_none) { // is CompReffer
458
r = (CompReffer) sectype;
459                  kind = r.what;
460                } else
461                  return false;
462              } else {
463                what.basereffer = sectype.objectKind();
464                if (sectype.objectKind()==ObjectsKind.o_Primitive) {
465                  switch (((CompPrimitive)sectype).kind) {
466                    case CompPrimKind.p_short:
467                    case CompPrimKind.p_long:
468                    case CompPrimKind.p_longlong:
469                    case CompPrimKind.p_ushort:
470                    case CompPrimKind.p_ulong:
471                    case CompPrimKind.p_ulonglong:
472                    case CompPrimKind.p_char:
473                    case CompPrimKind.p_boolean:
474                      ok = true;
475                      what.baserefferprim = ((CompPrimitive)sectype).kind;
476                      break;
477                    default: return false;
478                  }
479                } else
480                  ok = true;
481              }
482            } else
483              return false;
484          } else { // in normal repository
485
try {
486              Container con = rep.cdlRepository;
487              id.sn.names.toFirst();
488              for(i=0;i<id.sn.names.size();i++) {
489                Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
490                if (a==null || a.length==0)
491                  return false;
492                if (a.length==1) {
493                  if (a[0] instanceof Container) con = (Container) a[0];
494                  else return false;
495                } else {
496                  boolean found = false;
497                  for(j=0;j<a.length;j++) {
498                    if (a[j].get_identification().version().compareTo(id.version)==0) {
499                      if ( !(a[j] instanceof Container)) return false;
500                      found = true;
501                      con = (Container) a[j];
502                      break;
503                    }
504                  }
505                  if (!found) return false;
506                }
507                id.sn.names.toNext();
508              }
509              Contained sec = con.lookup(id.name, id.version);
510              if (sec!=null) {
511                CDLType sectype = ((TypedefDef) sec).original_type();
512                if (!isConstType(sectype.get_def_kind().value())) {
513                  if (sectype.get_def_kind().value() == DefinitionKind.dk_Typedef) {
514                    CompReffer ret = new CompReffer();
515                    ret.what = sectype.get_def_kind().value();
516                    ret.ref = new FullID(true);
517                    Identification idl;
518                    ret.ref.name = new String JavaDoc((idl = ((TypedefDef)sectype).get_identification()).name());
519                    ret.ref.version = new String JavaDoc(idl.version());
520                    ret.ref.isin = IDKind.version;
521                    ret.isNew = false;
522                    AbsoluteName abs = idl.absolute_name();
523                    for(j=0;j<abs.size();j++) {
524                      ret.ref.sn.addScope(new String JavaDoc(abs.elementAt(j)));
525                    }
526                    r = ret;
527                    kind = r.what;
528                  } else
529                    return false;
530                } else {
531                  what.basereffer = sectype.get_def_kind().value();
532                  if (sectype.get_def_kind().value()==DefinitionKind.dk_Primitive) {
533                    switch (((PrimitiveDef)sectype).kind().value()) {
534                      case PrimitiveKind.pk_short:
535                      case PrimitiveKind.pk_long:
536                      case PrimitiveKind.pk_longlong:
537                      case PrimitiveKind.pk_ushort:
538                      case PrimitiveKind.pk_ulong:
539                      case PrimitiveKind.pk_ulonglong:
540                      case PrimitiveKind.pk_char:
541                      case PrimitiveKind.pk_boolean:
542                        what.baserefferprim = ((PrimitiveDef)sectype).kind().value();
543                        ok = true;
544                        break;
545                      default: return false;
546                    }
547                  } else
548                    ok = true;
549                }
550              } else {
551                return false;
552              }
553            } catch (TIRExceptLock e) {
554              throw new CDLExceptLock("Repository is locked.");
555            } catch (RemoteException JavaDoc e) {
556              throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
557            }
558          }
559        } else {
560          return false;
561        }
562      } else {
563        what.basereffer = kind;
564        ok = true;
565      }
566    }
567    return true;
568   }
569
570   private static CompType goThroughCompArrSeq(CompType arseq) {
571     while (arseq instanceof CompArray || arseq instanceof CompSequence) {
572       if (arseq instanceof CompArray) {
573         arseq = ((CompArray) arseq).type;
574       } else {
575         arseq = ((CompSequence) arseq).type;
576       }
577     }
578     return arseq;
579   }
580
581   private static CDLType goThroughCDLArrSeq(CDLType arseq) throws RemoteException JavaDoc {
582     while (arseq instanceof ArrayDef || arseq instanceof SequenceDef) {
583       if (arseq instanceof ArrayDef) {
584         arseq = ((ArrayDef) arseq).element_type();
585       } else {
586         arseq = ((SequenceDef) arseq).element_type();
587       }
588     }
589     return arseq;
590   }
591
592   /** if CompReffer is typedef, scan through it */
593   public static boolean isParamType(CompReffer what, CompRepository rep) throws CDLExceptRemote, CDLExceptLock {
594    boolean ok = false;
595    int kind = what.what;
596    CompReffer r = what;
597    while (!ok) {
598      if (!CompReffer.isParamType(kind)) {
599        if (kind == ObjectsKind.o_Typedef) {
600          int i,j;
601          FullID id = r.ref;
602          if (r.isNew) { // in actually added objects
603
CompContainer con = rep;
604            id.sn.names.toFirst();
605            for(i=0;i<id.sn.names.size();i++) {
606              CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
607              if (a==null || a.length==0)
608                return false;
609              if (a.length==1) {
610                if (a[0].isContainer()) con = (CompContainer) a[0];
611                else return false;
612              } else {
613                return false;
614              }
615              id.sn.names.toNext();
616            }
617            CompContained sec = con.lookup(id.name, id.version);
618            if (sec!=null) {
619              CompType sectype = ((CompTypedef) sec).type;
620              if (!isParamType(sectype.objectKind())) {
621                if (sectype.objectKind()==ObjectsKind.o_none) { // is CompReffer
622
r = (CompReffer) sectype;
623                  kind = r.what;
624                } else {
625                  if (sectype.objectKind()==ObjectsKind.o_Array ||
626                       sectype.objectKind()==ObjectsKind.o_Sequence) {
627                    sectype = goThroughCompArrSeq(sectype);
628                    if (!isParamType(sectype.objectKind())) {
629                      if (sectype.objectKind()==ObjectsKind.o_none) { // is CompReffer
630
r = (CompReffer) sectype;
631                        kind = r.what;
632                      }
633                    } else {
634                      what.basereffer = sectype.objectKind();
635                      if (sectype.objectKind()==ObjectsKind.o_Primitive)
636                        what.baserefferprim = ((CompPrimitive)sectype).kind;
637                      ok = true;
638                    }
639                    
640                  } else
641                    return false;
642                }
643              } else {
644                what.basereffer = sectype.objectKind();
645                if (sectype.objectKind()==ObjectsKind.o_Primitive)
646                  what.baserefferprim = ((CompPrimitive)sectype).kind;
647                ok = true;
648              }
649            } else
650              return false;
651          } else { // in normal repository
652
try {
653              Container con = rep.cdlRepository;
654              id.sn.names.toFirst();
655              for(i=0;i<id.sn.names.size();i++) {
656                Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
657                if (a==null || a.length==0)
658                  return false;
659                if (a.length==1) {
660                  if (a[0] instanceof Container) con = (Container) a[0];
661                  else return false;
662                } else {
663                  boolean found = false;
664                  for(j=0;j<a.length;j++) {
665                    if (a[j].get_identification().version().compareTo(id.version)==0) {
666                      if ( !(a[j] instanceof Container)) return false;
667                      found = true;
668                      con = (Container) a[j];
669                      break;
670                    }
671                  }
672                  if (!found) return false;
673                }
674                id.sn.names.toNext();
675              }
676              Contained sec = con.lookup(id.name, id.version);
677              if (sec!=null) {
678                CDLType sectype = ((TypedefDef) sec).original_type();
679                if (!isConstType(sectype.get_def_kind().value())) {
680                  int defk = sectype.get_def_kind().value();
681                  if (defk == DefinitionKind.dk_Typedef) {
682                    CompReffer ret = new CompReffer();
683                    ret.what = sectype.get_def_kind().value();
684                    ret.ref = new FullID(true);
685                    Identification idl;
686                    ret.ref.name = new String JavaDoc((idl = ((TypedefDef)sectype).get_identification()).name());
687                    ret.ref.version = new String JavaDoc(idl.version());
688                    ret.ref.isin = IDKind.version;
689                    ret.isNew = false;
690                    AbsoluteName abs = idl.absolute_name();
691                    for(j=0;j<abs.size();j++) {
692                      ret.ref.sn.addScope(new String JavaDoc(abs.elementAt(j)));
693                    }
694                    r = ret;
695                    kind = r.what;
696                  } else {
697
698                    if (defk == DefinitionKind.dk_Array ||
699                        defk == DefinitionKind.dk_Sequence) {
700                      sectype = goThroughCDLArrSeq(sectype);
701
702                      if (!isConstType(sectype.get_def_kind().value())) {
703                        if (sectype.get_def_kind().value()== DefinitionKind.dk_Typedef) {
704                          CompReffer ret = new CompReffer();
705                          ret.what = sectype.get_def_kind().value();
706                          ret.ref = new FullID(true);
707                          Identification idl;
708                          ret.ref.name = new String JavaDoc((idl = ((TypedefDef)sectype).get_identification()).name());
709                          ret.ref.version = new String JavaDoc(idl.version());
710                          ret.ref.isin = IDKind.version;
711                          ret.isNew = false;
712                          AbsoluteName abs = idl.absolute_name();
713                          for(j=0;j<abs.size();j++) {
714                            ret.ref.sn.addScope(new String JavaDoc(abs.elementAt(j)));
715                          }
716                          r = ret;
717                          kind = r.what;
718                        } else {
719                          return false;
720                        }
721                      } else {
722                        what.basereffer = sectype.get_def_kind().value();
723                        if (sectype.get_def_kind().value()==DefinitionKind.dk_Primitive)
724                          what.baserefferprim = ((PrimitiveDef)sectype).kind().value();
725                        ok = true;
726                      }
727
728                    } else {
729                      return false;
730                    }
731                  }
732                } else {
733                  what.basereffer = sectype.get_def_kind().value();
734                  if (sectype.get_def_kind().value()==DefinitionKind.dk_Primitive)
735                    what.baserefferprim = ((PrimitiveDef)sectype).kind().value();
736                  ok = true;
737                }
738              } else {
739                return false;
740              }
741            } catch (TIRExceptLock e) {
742              throw new CDLExceptLock("Repository is locked.");
743            } catch (RemoteException JavaDoc e) {
744              throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
745            }
746          }
747        } else {
748          return false;
749        }
750      } else {
751        what.basereffer = kind;
752        ok = true;
753      }
754    }
755    return true;
756   }
757
758   /** if CompReffer is typedef, scan through it */
759   public static boolean isInterface(CompReffer what, CompRepository rep) throws CDLExceptRemote, CDLExceptLock {
760    boolean ok = false;
761    int kind = what.what;
762    CompReffer r = what;
763    while (!ok) {
764      if (kind != ObjectsKind.o_Interface) {
765        if (kind == ObjectsKind.o_Typedef) {
766          int i,j;
767          FullID id = r.ref;
768          if (r.isNew) { // in actually added objects
769
CompContainer con = rep;
770            id.sn.names.toFirst();
771            for(i=0;i<id.sn.names.size();i++) {
772              CompContained[] a = con.lookup((String JavaDoc) id.sn.names.aktual());
773              if (a==null || a.length==0)
774                return false;
775              if (a.length==1) {
776                if (a[0].isContainer()) con = (CompContainer) a[0];
777                else return false;
778              } else {
779                return false;
780              }
781              id.sn.names.toNext();
782            }
783            CompContained sec = con.lookup(id.name, id.version);
784            if (sec!=null) {
785              CompType sectype = ((CompTypedef) sec).type;
786              if (sectype.objectKind() != ObjectsKind.o_Interface) {
787                if (sectype.objectKind()==ObjectsKind.o_none) { // is CompReffer
788
r = (CompReffer) sectype;
789                  kind = r.what;
790                } else
791                  return false;
792              } else {
793                what.basereffer = sectype.objectKind();
794                what.baserefferprim = -1;
795                ok = true;
796              }
797            } else
798              return false;
799          } else { // in normal repository
800
try {
801              Container con = rep.cdlRepository;
802              id.sn.names.toFirst();
803              for(i=0;i<id.sn.names.size();i++) {
804                Contained[] a = con.lookup_name((String JavaDoc) id.sn.names.aktual());
805                if (a==null || a.length==0)
806                  return false;
807                if (a.length==1) {
808                  if (a[0] instanceof Container) con = (Container) a[0];
809                  else return false;
810                } else {
811                  boolean found = false;
812                  for(j=0;j<a.length;j++) {
813                    if (a[j].get_identification().version().compareTo(id.version)==0) {
814                      if ( !(a[j] instanceof Container)) return false;
815                      found = true;
816                      con = (Container) a[j];
817                      break;
818                    }
819                  }
820                  if (!found) return false;
821                }
822                id.sn.names.toNext();
823              }
824              Contained sec = con.lookup(id.name, id.version);
825              if (sec!=null) {
826                CDLType sectype = ((TypedefDef) sec).original_type();
827                if (sectype.get_def_kind().value() != DefinitionKind.dk_Interface) {
828                  if (sectype.get_def_kind().value() == DefinitionKind.dk_Typedef) {
829                    CompReffer ret = new CompReffer();
830                    ret.what = sectype.get_def_kind().value();
831                    ret.ref = new FullID(true);
832                    Identification idl;
833                    ret.ref.name = new String JavaDoc((idl = ((TypedefDef)sectype).get_identification()).name());
834                    ret.ref.version = new String JavaDoc(idl.version());
835                    ret.ref.isin = IDKind.version;
836                    ret.isNew = false;
837                    AbsoluteName abs = idl.absolute_name();
838                    for(j=0;j<abs.size();j++) {
839                      ret.ref.sn.addScope(new String JavaDoc(abs.elementAt(j)));
840                    }
841                    r = ret;
842                    kind = r.what;
843                  } else
844                    return false;
845                } else {
846                  what.basereffer = sectype.get_def_kind().value();
847                  what.baserefferprim = -1;
848                  ok = true;
849                }
850              } else {
851                return false;
852              }
853            } catch (TIRExceptLock e) {
854              throw new CDLExceptLock("Repository is locked.");
855            } catch (RemoteException JavaDoc e) {
856              throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
857            }
858          }
859        } else {
860          return false;
861        }
862      } else {
863        ok = true;
864      }
865    }
866    return true;
867   }
868 }
869
Popular Tags