KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: CompModule.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.CDLContainer;
6 import SOFA.SOFAnode.Made.TIR.CDLRepository;
7 import SOFA.SOFAnode.Made.TIR.ConstantDef;
8 import SOFA.SOFAnode.Made.TIR.Contained;
9 import SOFA.SOFAnode.Made.TIR.Container;
10 import SOFA.SOFAnode.Made.TIR.EnumDef;
11 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
12 import SOFA.SOFAnode.Made.TIR.ExprFixed;
13 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
14 import SOFA.SOFAnode.Made.TIR.FrameDef;
15 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
16 import SOFA.SOFAnode.Made.TIR.ModuleDef;
17 import SOFA.SOFAnode.Made.TIR.StructDef;
18 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate;
19 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
20 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
21 import SOFA.SOFAnode.Made.TIR.TypedefDef;
22 import SOFA.SOFAnode.Made.TIR.UnionDef;
23
24 class CompModule extends CompContainedContainerIm {
25
26   public CompModule(ID id, CompContainer in, CompRepository inRep) {
27     super(ObjectsKind.o_Module, id, in, inRep);
28   }
29
30   public void addToNormal(Container obj, CDLRepository normRep, java.util.ArrayList JavaDoc delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock {
31     cont.toFirst();
32     try {
33       for (int i=0;i<cont.size(); i++) {
34         CompContained akt = (CompContained) cont.aktual();
35         switch (akt.objectKind()) {
36         // *****************
37
case ObjectsKind.o_Module:
38           Contained[] cmod = obj.lookup_name(akt.getIdent().name);
39           if ((cmod == null) || (cmod.length == 0)) { //create ne module
40
ModuleDef mod = null;
41             try {
42               mod = ((CDLContainer) obj).create_module(akt.getIdent().id);
43             } catch (TIRExceptCreate ecr) {
44               throw new CDLExceptToNormal("Can't create module "+((CompContained)akt).fullName());
45             }
46             if (mod==null)
47               throw new CDLExceptToNormal("Can't create module "+((CompContained)akt).fullName());
48             ((CompContainer) akt).addToNormal(mod, normRep, delayed);
49           } else { // use old module
50
if (cmod.length!=1)
51               throw new CDLExceptToNormal("Unexpected error");
52             ((CompContainer) akt).addToNormal((Container) cmod[0], normRep, delayed);
53           }
54           break;
55         // *****************
56
case ObjectsKind.o_Typedef:
57           try {
58             TypedefDef td =( (CDLContainer) obj).create_typedef(akt.getIdent().id, ((CompTypedef) akt).type.toNormal(normRep));
59             if (td == null)
60               throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
61           } catch (TIRExceptCreate ecr) {
62             throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName()+"\n"+
63                                           ecr.getMessage());
64           }
65           break;
66         // *****************
67
case ObjectsKind.o_Enum:
68           try {
69             EnumDef en = ((CDLContainer) obj).create_enum(akt.getIdent().id);
70             if (en == null)
71               throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName());
72             ((CompEnum) akt).addToNormal(en);
73           } catch (TIRExceptCreate ecr) {
74             throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName());
75           }
76           break;
77         // *****************
78
case ObjectsKind.o_Struct:
79           try {
80             StructDef str = ((CDLContainer) obj).create_struct(akt.getIdent().id);
81             if (str == null)
82               throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
83             ((CompStruct) akt).addToNormal(str, normRep, delayed);
84           } catch (TIRExceptCreate ecr) {
85             throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName());
86           }
87           break;
88         // *****************
89
case ObjectsKind.o_Union:
90           try {
91             UnionDef un = ((CDLContainer) obj).create_union(akt.getIdent().id, ((CompUnion) akt).switch_type.toNormal(normRep));
92             if (un == null)
93               throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
94             ((CompUnion) akt).addToNormal(un, normRep, delayed);
95           } catch (TIRExceptCreate ecr) {
96             throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName());
97           }
98           break;
99         // *****************
100
case ObjectsKind.o_Exception:
101           try {
102             ExceptionDef str = ((CDLContainer) obj).create_exception(akt.getIdent().id);
103             if (str == null)
104               throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
105             ((CompException) akt).addToNormal(str, normRep, delayed);
106           } catch (TIRExceptCreate ecr) {
107             throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName());
108           }
109           break;
110         // *****************
111
case ObjectsKind.o_Constant:
112           try {
113             ConstantDef cnst;
114             if (((CompConstant) akt).type.objectKind() == ObjectsKind.o_Fixed) {
115               ExprOperDef expr = ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep);
116               ExprOperDef cexpr = null;
117               try {
118                 cexpr = expr.calculate();
119               } catch (TIRExceptCalculate e) {
120                 throw new CDLExceptToNormal("Bad expression in the constant "+((CompContained)akt).fullName());
121               }
122               ((CompFixed) ((CompConstant) akt).type).digits = new CompExprInteger(((ExprFixed) cexpr).digits());
123               ((CompFixed) ((CompConstant) akt).type).scale = new CompExprInteger(((ExprFixed) cexpr).scale());
124               cnst = ((CDLContainer) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), expr);
125             } else {
126               cnst = ((CDLContainer) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep));
127             }
128             if (cnst == null)
129               throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
130           } catch (TIRExceptCreate ecr) {
131             throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName());
132           }
133           break;
134         // *****************
135
case ObjectsKind.o_Interface:
136           try {
137            /* InterfaceDef[] base = null;
138             if (((CompInterface) akt).baseIfaces != null) {
139               ((CompInterface) akt).baseIfaces.toFirst();
140               base = new InterfaceDef [((CompInterface) akt).baseIfaces.size()];
141               for (int j=0;j<((CompInterface) akt).baseIfaces.size();j++) {
142                 base[j] = (InterfaceDef) ((CompType) ((CompInterface) akt).baseIfaces.aktual()).toNormal(normRep);
143                 ((CompInterface) akt).baseIfaces.toNext();
144               }
145             } else {
146               base = new InterfaceDef [0];
147             } */

148             InterfaceDef iface = ((CDLContainer) obj).create_interface(akt.getIdent().id /*,base*/);
149             if (iface == null)
150               throw new CDLExceptToNormal("Can't create interface "+((CompContained)akt).fullName());
151             ((CompInterface) akt).addToNormal(iface, normRep, delayed);
152           } catch (TIRExceptCreate ecr) {
153             throw new CDLExceptToNormal("Can't create interface "+((CompContained)akt).fullName());
154           }
155           break;
156         // *****************
157
case ObjectsKind.o_Frame:
158           try {
159             FrameDef frm = ((CDLContainer) obj).create_frame(akt.getIdent().id, ((CompFrame)akt).isSystem);
160             if (frm == null)
161               throw new CDLExceptToNormal("Can't create frame "+((CompContained)akt).fullName());
162             ((CompFrame) akt).addToNormal(frm, normRep, delayed);
163           } catch (TIRExceptCreate ecr) {
164             throw new CDLExceptToNormal("Can't create frame "+((CompContained)akt).fullName());
165           }
166           break;
167         default:
168           throw new CDLExceptToNormal("Unexcepted kind of object");
169         }
170         cont.toNext();
171       }
172     } catch (RemoteException JavaDoc e) {
173       throw new CDLExceptRemote("Remote exception occured: "+e.getMessage());
174     } catch (TIRExceptLock e) {
175       throw new CDLExceptLock("Repository is locked.");
176     }
177   }
178
179   public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote {
180     CompContained[] cont = contents();
181     for (int i=0;i<cont.length;i++) {
182       switch (cont[i].objectKind()) {
183       case ObjectsKind.o_Module:
184         cont[i].checkConsist(null,rep);
185         break;
186       case ObjectsKind.o_Interface:
187         cont[i].checkConsist(null,rep);
188         break;
189       case ObjectsKind.o_Frame:
190         try {
191           cont[i].checkConsist(null,rep);
192         } catch (CDLExceptCheck e) {
193           throw new CDLExceptCheck(e.getMessage()+" in frame "+cont[i].fullName());
194         }
195         break;
196       }
197     }
198   }
199 }
200
Popular Tags