KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: CompInterface.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.AttributeDef;
6 import SOFA.SOFAnode.Made.TIR.CDLRepository;
7 import SOFA.SOFAnode.Made.TIR.CDLType;
8 import SOFA.SOFAnode.Made.TIR.ConstantDef;
9 import SOFA.SOFAnode.Made.TIR.Contained;
10 import SOFA.SOFAnode.Made.TIR.Container;
11 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
12 import SOFA.SOFAnode.Made.TIR.EnumDef;
13 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
14 import SOFA.SOFAnode.Made.TIR.ExprFixed;
15 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
16 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
17 import SOFA.SOFAnode.Made.TIR.OperationDef;
18 import SOFA.SOFAnode.Made.TIR.ProtocolDef;
19 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef;
20 import SOFA.SOFAnode.Made.TIR.StructDef;
21 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate;
22 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
23 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
24 import SOFA.SOFAnode.Made.TIR.TypedefDef;
25 import SOFA.SOFAnode.Made.TIR.UnionDef;
26
27 class CompInterface extends CompContainedContainerIm implements CompType {
28   class NName {
29     String JavaDoc iface; // name if iface
30
String JavaDoc name;
31     boolean isOper; // is operation?
32
public NName(String JavaDoc iface, String JavaDoc name, boolean isOper) {
33       this.iface = iface;
34       this.name = name;
35       this.isOper = isOper;
36     }
37   }
38   
39   class Names extends List {
40     public Names() { super(); }
41     public boolean isIn(String JavaDoc iface, String JavaDoc name) {
42       akt = first;
43       for (int i=0;i<count;i++) {
44         if (name.compareTo(((NName)akt.item).name)==0 && iface.compareTo(((NName)akt.item).iface)!=0)
45           return true;
46         toNext();
47       }
48       return false;
49     }
50
51     public void addName(String JavaDoc iface, String JavaDoc name, boolean isOper) {
52       add(new NName(iface,name,isOper));
53     }
54   }
55   
56   boolean forwarddcl;
57   boolean wasforwarddcl;
58   List baseIfaces;
59   CompProtOper protocol;
60   Names names; // all names (direct and inherited) in iface
61

62   public CompInterface(ID id, CompContainer in, CompRepository inRep, boolean fwd) {
63     super(ObjectsKind.o_Interface, id, in, inRep);
64     forwarddcl = fwd;
65     wasforwarddcl = false;
66     baseIfaces = new List();
67     protocol = null;
68     names = new Names();
69 // Debug.message("Vytvarim interface: "+id);
70
}
71
72   public boolean setBaseIfaces(List bi) throws CDLExceptLock, CDLExceptRemote {
73     int i;
74     bi.toFirst();
75     for (int k=0;k<bi.size();k++) {
76       CompReffer ref = (CompReffer) bi.aktual();
77       if (ref.isNew) {
78         CompContainer con = rep;
79         ref.ref.sn.names.toFirst();
80         for(i=0;i<ref.ref.sn.names.size();i++) {
81           CompContained[] a = con.lookup((String JavaDoc) ref.ref.sn.names.aktual());
82           if (a==null || a.length==0)
83             return false;
84           if (a.length==1) {
85             if (a[0].isContainer()) con = (CompContainer) a[0];
86             else return false;
87           } else {
88             return false;
89           }
90           ref.ref.sn.names.toNext();
91         }
92         CompContained sec = con.lookup(ref.ref.name, ref.ref.version);
93         if (sec!=null) {
94           if (sec.objectKind() != ObjectsKind.o_Interface)
95             return false;
96           Names obj = ((CompInterface) sec).names;
97           obj.toFirst();
98           for (int j=0;j<obj.size();j++) {
99             if (names.isIn(((NName) obj.aktual()).iface, ((NName) obj.aktual()).name))
100               return false;
101               names.addName(((NName) obj.aktual()).iface,((NName) obj.aktual()).name,((NName) obj.aktual()).isOper);
102             obj.toNext();
103           }
104 /* obj.toFirst();
105           for (int j=0;j<obj.size();j++) { // adding
106             names.addName(((NName) obj.aktual()).iface,((NName) obj.aktual()).name,((NName) obj.aktual()).isOper);
107             obj.toNext();
108           } */

109         // !!!
110
CompReffer nb = new CompReffer();
111           nb.what = sec.objectKind();
112           nb.ref = new FullID(true);
113           nb.ref.name = new String JavaDoc(ref.ref.name);
114           nb.ref.version = new String JavaDoc(ref.ref.version);
115           nb.ref.isin = IDKind.version;
116           nb.isNew = true;
117           ref.ref.sn.names.toFirst();
118           for(int j=0;j<ref.ref.sn.names.size();j++) {
119             nb.ref.sn.addScope(new String JavaDoc((String JavaDoc)ref.ref.sn.names.aktual()));
120             ref.ref.sn.names.toNext();
121           }
122           baseIfaces.add(nb);
123         // !!!
124
}
125       } else {
126         try {
127           Container con = rep.cdlRepository;
128           ref.ref.sn.names.toFirst();
129           for(i=0;i<ref.ref.sn.names.size();i++) {
130             Contained[] a = con.lookup_name((String JavaDoc) ref.ref.sn.names.aktual());
131             if (a==null || a.length==0)
132               return false;
133            if (a.length==1) {
134               if (a[0] instanceof Container) con = (Container) a[0];
135               else return false;
136             } else {
137               boolean found = false;
138               for(int j=0;j<a.length;j++) {
139                 if (a[j].get_identification().version().compareTo(ref.ref.version)==0) {
140                   if ( !(a[j] instanceof Container)) return false;
141                   found = true;
142                   con = (Container) a[j];
143                   break;
144                 }
145               }
146               if (!found) return false;
147             }
148             ref.ref.sn.names.toNext();
149           }
150           Contained sec = con.lookup(ref.ref.name, ref.ref.version);
151           if (sec!=null) {
152             if (sec.get_def_kind().value() != DefinitionKind.dk_Interface)
153               return false;
154             int j;
155             Contained[] obj = ((InterfaceDef) sec).contents(null);
156             for (j=0;j<obj.length;j++) {
157               boolean isOper = false;
158               if (names.isIn(ref.ref.name, obj[j].get_identification().name()))
159                 return false;
160               if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation)
161                 isOper = true;
162               names.addName(ref.ref.name, new String JavaDoc(obj[j].get_identification().name()),isOper);
163             }
164             // test base ifaces of this (base iface)
165
if (!testSetBaseIfaces((InterfaceDef)sec))
166               return false;
167 /* for (j=0;j<obj.length;j++) { // adding
168               boolean isOper = false;
169               if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation)
170                 isOper = true;
171               names.addName(ref.ref.name, new String(obj[j].get_identification().name()),isOper);
172             } */

173
174             // !!!
175
CompReffer nb = new CompReffer();
176             nb.what = sec.get_def_kind().value();
177             nb.ref = new FullID(true);
178             nb.ref.name = new String JavaDoc(ref.ref.name);
179             nb.ref.version = new String JavaDoc(ref.ref.version);
180             nb.ref.isin = IDKind.version;
181             nb.isNew = false;
182             ref.ref.sn.names.toFirst();
183             for(int l=0;l<ref.ref.sn.names.size();l++) {
184               nb.ref.sn.addScope(new String JavaDoc((String JavaDoc)ref.ref.sn.names.aktual()));
185               ref.ref.sn.names.toNext();
186             }
187             baseIfaces.add(nb);
188             // !!!
189

190           }
191         } catch (TIRExceptLock e) {
192           throw new CDLExceptLock("Repository is locked.");
193         } catch (RemoteException JavaDoc e) {
194           throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
195         }
196       }
197
198       bi.toNext();
199     }
200     return true;
201   }
202
203   private boolean testSetBaseIfaces(InterfaceDef iface) throws TIRExceptLock, RemoteException JavaDoc {
204     InterfaceDef[] bbase = ((InterfaceDef) iface).base_interfaces();
205     for (int i=0;i<bbase.length;i++) {
206       Contained[] obj = ((InterfaceDef) bbase[i]).contents(null);
207       for (int j=0;j<obj.length;j++) {
208         boolean isOper = false;
209         if (names.isIn(((InterfaceDef) bbase[i]).get_identification().name(),obj[j].get_identification().name()))
210            return false;
211         if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation)
212           isOper = true;
213         names.addName(((InterfaceDef) bbase[i]).get_identification().name(),new String JavaDoc(obj[j].get_identification().name()),isOper);
214       }
215       if (!testSetBaseIfaces(bbase[i]))
216         return false;
217     }
218     return true;
219   }
220
221 /* private void setBaseIfaces(InterfaceDef iface) throws TIRExceptLock, RemoteException {
222     InterfaceDef[] bbase = ((InterfaceDef) iface).base_interfaces();
223     for (int i=0;i<bbase.length;i++) {
224       Contained[] obj = ((InterfaceDef) bbase[i]).contents(null);
225       for (int j=0;j<obj.length;j++) {
226         boolean isOper = false;
227         if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation)
228           isOper = true;
229         names.addName(((InterfaceDef) bbase[i]).get_identification().name(),new String(obj[j].get_identification().name()),isOper);
230       }
231       setBaseIfaces(bbase[i]);
232     }
233   }*/

234   
235   public boolean addObject(CompContained o) {
236     ((CompContained) o).getIdent().version = id.version;
237     // search in baseIfaces
238
String JavaDoc nm = o.getIdent().name;
239     if (names.isIn(id.name, nm))
240       return false;
241     boolean isOper = false;
242     if (o.objectKind()==ObjectsKind.o_Operation)
243       isOper = true;
244     names.addName(id.name,nm,isOper);
245     return super.addObject(o);
246   }
247
248   public boolean isOperationName(String JavaDoc name) {
249     names.toFirst();
250     for (int i=0;i<names.size();i++) {
251       if ((((NName) names.aktual()).name.compareTo(name)==0) && (((NName) names.aktual()).isOper))
252         return true;
253       names.toNext();
254     }
255     return false;
256   }
257
258   /** return all (direct and inherit) operation's names */
259   public EnumList operationNames() {
260     EnumList ret = new EnumList();
261     names.toFirst();
262     for (int i=0;i<names.size();i++) {
263       if (((NName) names.aktual()).isOper)
264         ret.addName(((NName) names.aktual()).name);
265       names.toNext();
266     }
267     return ret;
268   }
269
270   public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote {
271     // test if it wasn't only fwd declaration
272
if (forwarddcl)
273       throw new CDLExceptCheck("Forward declaration of interface "+fullName()+" only.");
274     if (props == null) {
275       ;
276     } else {
277       // test for properties
278
CompContained[] cont = contents();
279       for (int i=0;i<cont.length;i++) {
280         cont[i].checkConsist(props, rep);
281       }
282     }
283
284     if (rep.useProtocols) {
285       if (protocol == null && contents().length!=0)
286         throw new CDLExceptCheck("No protocol for interface "+fullName());
287     }
288
289   }
290
291   public void addToNormal(Container obj, CDLRepository normRep, java.util.ArrayList JavaDoc delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock {
292 /*
293     System.out.println("***"+id.toString()+"***");
294     if (wasforwarddcl) {
295       delayed.add(this);
296       delayed.add(obj);
297       System.out.println("fwddcl");
298     } else { */

299
300     delayed.add(this);
301     delayed.add(obj);
302     return;
303    /*
304     if (id.isin == IDKind.versiontag) {
305       try {
306         ((Contained)obj).tag(id.tag);
307       } catch (RemoteException e) {
308         throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
309       } catch (TIRExceptLock e) {
310         throw new CDLExceptLock("Repository is locked.");
311       } catch (TIRExceptCreate ecr) {
312         throw new CDLExceptToNormal("Can't set tag for "+ fullName());
313       }
314     }
315     cont.toFirst();
316     try {
317       for (int i=0;i<cont.size(); i++) {
318         CompContained akt = (CompContained) cont.aktual();
319         switch (akt.objectKind()) {
320         // *****************
321         case ObjectsKind.o_Typedef:
322           try {
323             TypedefDef td = ((InterfaceDef) obj).create_typedef(akt.getIdent().id, ((CompTypedef) akt).type.toNormal(normRep));
324             if (td == null)
325               throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
326           } catch (TIRExceptCreate ecr) {
327             throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
328           }
329           break;
330         // *****************
331         case ObjectsKind.o_Enum:
332           try {
333             EnumDef en = ((InterfaceDef) obj).create_enum(akt.getIdent().id);
334             if (en == null)
335               throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName());
336             ((CompEnum) akt).addToNormal(en);
337           } catch (TIRExceptCreate ecr) {
338             throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName());
339           }
340           break;
341         // *****************
342         case ObjectsKind.o_Struct:
343           try {
344             StructDef str = ((InterfaceDef) obj).create_struct(akt.getIdent().id);
345             if (str == null)
346               throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
347             ((CompStruct) akt).addToNormal(str, normRep, delayed);
348           } catch (TIRExceptCreate ecr) {
349             throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
350           }
351           break;
352         // *****************
353         case ObjectsKind.o_Union:
354           try {
355             UnionDef un = ((InterfaceDef) obj).create_union(akt.getIdent().id, ((CompUnion) akt).switch_type.toNormal(normRep));
356             if (un == null)
357               throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
358             ((CompUnion) akt).addToNormal(un, normRep, delayed);
359           } catch (TIRExceptCreate ecr) {
360             throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
361           }
362           break;
363         // *****************
364         case ObjectsKind.o_Exception:
365           try {
366             ExceptionDef str = ((InterfaceDef) obj).create_exception(akt.getIdent().id);
367             if (str == null)
368               throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
369             ((CompException) akt).addToNormal(str, normRep, delayed);
370           } catch (TIRExceptCreate ecr) {
371             throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
372           }
373           break;
374         // *****************
375         case ObjectsKind.o_Constant:
376           try {
377             ConstantDef cnst;
378             if (((CompConstant) akt).type.objectKind() == ObjectsKind.o_Fixed) {
379               ExprOperDef expr = ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep);
380               ExprOperDef cexpr = null;
381               try {
382                 cexpr = expr.calculate();
383               } catch (TIRExceptCalculate e) {
384                 throw new CDLExceptToNormal("Bad expression in the constant "+((CompContained)akt).fullName());
385               }
386               ((CompFixed) ((CompConstant) akt).type).digits = new CompExprInteger(((ExprFixed) cexpr).digits());
387               ((CompFixed) ((CompConstant) akt).type).scale = new CompExprInteger(((ExprFixed) cexpr).scale());
388               cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), expr);
389             } else {
390               cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep));
391             }
392             if (cnst == null)
393               throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
394           } catch (TIRExceptCreate ecr) {
395             throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
396           }
397           break;
398         // *****************
399         case ObjectsKind.o_Attribute:
400           try {
401             AttributeDef attr = ((InterfaceDef) obj).create_attribute(akt.getIdent().id, ((CompAttribute) akt).type.toNormal(normRep), ((CompAttribute)akt).mode);
402             if (attr == null)
403               throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName());
404           } catch (TIRExceptCreate ecr) {
405             throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName()+"\n"+
406                                          ecr.getMessage());
407           }
408           break;
409         // *****************
410         case ObjectsKind.o_Operation:
411           try {
412             ExceptionDef[] raises = null;
413             if (((CompOperation) akt).raises != null) {
414               ((CompOperation) akt).raises.toFirst();
415               raises = new ExceptionDef [((CompOperation) akt).raises.size()];
416               for (int j=0;j<((CompOperation) akt).raises.size();j++) {
417                 raises[j] = (ExceptionDef) ((CompType) ((CompOperation) akt).raises.aktual()).toNormal(normRep);
418                 ((CompOperation) akt).raises.toNext();
419               }
420             } else {
421               raises = new ExceptionDef [0];
422             }
423             OperationDef oper = ((InterfaceDef) obj).create_operation(akt.getIdent().id, ((CompOperation) akt).type.toNormal(normRep) , raises);
424             if (oper == null)
425               throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName());
426             ((CompOperation) akt).addToNormal(oper, normRep);
427           } catch (TIRExceptCreate ecr) {
428             throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName()+"\n"+
429                                          ecr.getMessage());
430           }
431           break;
432         default:
433           throw new CDLExceptToNormal("Unexcepted kind of object");
434         }
435         cont.toNext();
436       }
437       if (protocol != null) {
438         try {
439           ProtocolDef newProt = ((InterfaceDef) obj).create_protocol();
440           ProtocolOperDef p = CompProtOper.toNormalIface(protocol, newProt);
441       newProt.protocol(p);
442     } catch (TIRExceptCreate ecr) {
443       throw new CDLExceptToNormal("Can't create protocol in "+ fullName()+"\n"+
444                                          ecr.getMessage());
445     }
446       }
447       
448     } catch (RemoteException e) {
449       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
450     } catch (TIRExceptLock e) {
451       throw new CDLExceptLock("Repository is locked.");
452     } */

453
454
455    /* } */
456   }
457
458
459   public void addToNormalDelayed(Container obj, CDLRepository normRep, java.util.ArrayList JavaDoc delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock {
460     try {
461       InterfaceDef[] base = null;
462       if (baseIfaces != null) {
463         baseIfaces.toFirst();
464         base = new InterfaceDef [baseIfaces.size()];
465         for (int j=0;j<baseIfaces.size();j++) {
466           base[j] = (InterfaceDef) ((CompType) baseIfaces.aktual()).toNormal(normRep);
467           baseIfaces.toNext();
468         }
469         //System.out.println(id.toString()+"***");
470
//System.out.println(base.length);
471
((InterfaceDef) obj).setBaseInterfaces(base);
472       }
473       
474     } catch (RemoteException JavaDoc e) {
475       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
476     } catch (TIRExceptCreate ecr) {
477       throw new CDLExceptToNormal("Can't create interface "+fullName());
478     }
479     
480     if (id.isin == IDKind.versiontag) {
481       try {
482         ((Contained)obj).tag(id.tag);
483       } catch (RemoteException JavaDoc e) {
484         throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
485       } catch (TIRExceptLock e) {
486         throw new CDLExceptLock("Repository is locked.");
487       } catch (TIRExceptCreate ecr) {
488         throw new CDLExceptToNormal("Can't set tag for "+ fullName());
489       }
490     }
491     cont.toFirst();
492     try {
493       for (int i=0;i<cont.size(); i++) {
494         CompContained akt = (CompContained) cont.aktual();
495         switch (akt.objectKind()) {
496         // *****************
497
case ObjectsKind.o_Typedef:
498           try {
499             TypedefDef td = ((InterfaceDef) obj).create_typedef(akt.getIdent().id, ((CompTypedef) akt).type.toNormal(normRep));
500             if (td == null)
501               throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
502           } catch (TIRExceptCreate ecr) {
503             throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
504           }
505           break;
506         // *****************
507
case ObjectsKind.o_Enum:
508           try {
509             EnumDef en = ((InterfaceDef) obj).create_enum(akt.getIdent().id);
510             if (en == null)
511               throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName());
512             ((CompEnum) akt).addToNormal(en);
513           } catch (TIRExceptCreate ecr) {
514             throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName());
515           }
516           break;
517         // *****************
518
case ObjectsKind.o_Struct:
519           try {
520             StructDef str = ((InterfaceDef) obj).create_struct(akt.getIdent().id);
521             if (str == null)
522               throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
523             ((CompStruct) akt).addToNormal(str, normRep, delayed);
524           } catch (TIRExceptCreate ecr) {
525             throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
526           }
527           break;
528         // *****************
529
case ObjectsKind.o_Union:
530           try {
531             UnionDef un = ((InterfaceDef) obj).create_union(akt.getIdent().id, ((CompUnion) akt).switch_type.toNormal(normRep));
532             if (un == null)
533               throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
534             ((CompUnion) akt).addToNormal(un, normRep, delayed);
535           } catch (TIRExceptCreate ecr) {
536             throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
537           }
538           break;
539         // *****************
540
case ObjectsKind.o_Exception:
541           try {
542             ExceptionDef str = ((InterfaceDef) obj).create_exception(akt.getIdent().id);
543             if (str == null)
544               throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
545             ((CompException) akt).addToNormal(str, normRep, delayed);
546           } catch (TIRExceptCreate ecr) {
547             throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
548           }
549           break;
550         // *****************
551
case ObjectsKind.o_Constant:
552           try {
553             ConstantDef cnst;
554             if (((CompConstant) akt).type.objectKind() == ObjectsKind.o_Fixed) {
555               ExprOperDef expr = ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep);
556               ExprOperDef cexpr = null;
557               try {
558                 cexpr = expr.calculate();
559               } catch (TIRExceptCalculate e) {
560                 throw new CDLExceptToNormal("Bad expression in the constant "+((CompContained)akt).fullName());
561               }
562               ((CompFixed) ((CompConstant) akt).type).digits = new CompExprInteger(((ExprFixed) cexpr).digits());
563               ((CompFixed) ((CompConstant) akt).type).scale = new CompExprInteger(((ExprFixed) cexpr).scale());
564               cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), expr);
565             } else {
566               cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep));
567             }
568             if (cnst == null)
569               throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
570           } catch (TIRExceptCreate ecr) {
571             throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
572           }
573           break;
574         // *****************
575
case ObjectsKind.o_Attribute:
576           try {
577             AttributeDef attr = ((InterfaceDef) obj).create_attribute(akt.getIdent().id, ((CompAttribute) akt).type.toNormal(normRep), ((CompAttribute)akt).mode);
578             if (attr == null)
579               throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName());
580           } catch (TIRExceptCreate ecr) {
581             throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName()+"\n"+
582                                          ecr.getMessage());
583           }
584           break;
585         // *****************
586
case ObjectsKind.o_Operation:
587           try {
588             ExceptionDef[] raises = null;
589             if (((CompOperation) akt).raises != null) {
590               ((CompOperation) akt).raises.toFirst();
591               raises = new ExceptionDef [((CompOperation) akt).raises.size()];
592               for (int j=0;j<((CompOperation) akt).raises.size();j++) {
593                 raises[j] = (ExceptionDef) ((CompType) ((CompOperation) akt).raises.aktual()).toNormal(normRep);
594                 ((CompOperation) akt).raises.toNext();
595               }
596             } else {
597               raises = new ExceptionDef [0];
598             }
599             OperationDef oper = ((InterfaceDef) obj).create_operation(akt.getIdent().id, ((CompOperation) akt).type.toNormal(normRep) , raises);
600             if (oper == null)
601               throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName());
602             ((CompOperation) akt).addToNormal(oper, normRep);
603           } catch (TIRExceptCreate ecr) {
604             throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName()+"\n"+
605                                          ecr.getMessage());
606           }
607           break;
608         default:
609           throw new CDLExceptToNormal("Unexcepted kind of object");
610         }
611         cont.toNext();
612       }
613       if (protocol != null) {
614         try {
615           ProtocolDef newProt = ((InterfaceDef) obj).create_protocol();
616           ProtocolOperDef p = CompProtOper.toNormalIface(protocol, newProt);
617       newProt.protocol(p);
618     } catch (TIRExceptCreate ecr) {
619       throw new CDLExceptToNormal("Can't create protocol in "+ fullName()+"\n"+
620                                          ecr.getMessage());
621     }
622       }
623       
624     } catch (RemoteException JavaDoc e) {
625       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
626     } catch (TIRExceptLock e) {
627       throw new CDLExceptLock("Repository is locked.");
628     }
629   }
630
631   /** from CompType */
632   public CDLType toNormal(CDLRepository newRep) throws CDLExceptToNormal {
633     // never call this
634
throw new CDLExceptToNormal("It should never throw");
635   }
636
637   public String JavaDoc protocolToText() {
638     if (protocol != null) {
639       return protocol.toText();
640     }
641     return "-- no protocol --";
642   }
643 }
644
Popular Tags