KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > TIR > Impl > UnionDefImpl


1 /* $Id: UnionDefImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.io.DataInputStream JavaDoc;
4 import java.io.DataOutputStream JavaDoc;
5 import java.io.FileInputStream JavaDoc;
6 import java.io.FileOutputStream JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.rmi.RemoteException JavaDoc;
9
10 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
11 import SOFA.SOFAnode.Made.TIR.ArrayDef;
12 import SOFA.SOFAnode.Made.TIR.CDLType;
13 import SOFA.SOFAnode.Made.TIR.Contained;
14 import SOFA.SOFAnode.Made.TIR.Container;
15 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
16 import SOFA.SOFAnode.Made.TIR.EnumDef;
17 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
18 import SOFA.SOFAnode.Made.TIR.FixedDef;
19 import SOFA.SOFAnode.Made.TIR.Identification;
20 import SOFA.SOFAnode.Made.TIR.PrimitiveDef;
21 import SOFA.SOFAnode.Made.TIR.Repository;
22 import SOFA.SOFAnode.Made.TIR.SequenceDef;
23 import SOFA.SOFAnode.Made.TIR.StateKind;
24 import SOFA.SOFAnode.Made.TIR.StringDef;
25 import SOFA.SOFAnode.Made.TIR.StructDef;
26 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
27 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
28 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
29 import SOFA.SOFAnode.Made.TIR.TIRObject;
30 import SOFA.SOFAnode.Made.TIR.UnionDef;
31 import SOFA.SOFAnode.Made.TIR.UnionMember;
32 import SOFA.SOFAnode.Made.TIR.WstringDef;
33
34 public class UnionDefImpl extends ContainerImpl implements UnionDef, TIRImplObject, SContained {
35   protected Identification id;
36   protected Container parent;
37   protected Repository rep;
38   CDLType swtype;
39   DefinitionKindImpl defKindImpl;
40   StateKindImpl stKindImpl;
41  
42   UnionDefImpl normal;
43   long workId;
44  
45   public UnionDefImpl(Identification ident, Container in, Repository inrep, CDLType swType, long workId) throws RemoteException JavaDoc {
46     id = ident;
47     parent = in;
48     rep = inrep;
49     swtype = swType;
50     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Union);
51     stKindImpl = new StateKindImpl(StateKind.sk_work);
52     normal = null;
53     this.workId = workId;
54   }
55
56   public UnionDefImpl(Container in, Repository inrep) throws RemoteException JavaDoc {
57     id = null;
58     parent = in;
59     rep = inrep;
60     swtype = null;
61     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Union);
62     stKindImpl = new StateKindImpl(StateKind.sk_normal);
63     normal = null;
64     this.workId = -1L;
65   }
66
67   public UnionDefImpl(UnionDefImpl a, Container in, Repository inrep, long workId) throws RemoteException JavaDoc {
68     id = a.id;
69     parent = in;
70     rep = inrep;
71     swtype = a.swtype;
72     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Union);
73     stKindImpl = new StateKindImpl(StateKind.sk_work);
74     normal = a;
75     this.workId = workId;
76   }
77
78   public CDLType switch_type() throws RemoteException JavaDoc {
79     return swtype;
80   }
81  
82   /* form interface Contained */
83   public Identification get_identification() throws RemoteException JavaDoc {
84     return id;
85   }
86
87   /* form interface Contained */
88   public Container get_defined_in() throws RemoteException JavaDoc {
89     return parent;
90   }
91
92   /* form interface Contained */
93   public Container get_containing_repository() throws RemoteException JavaDoc {
94     return rep;
95   }
96
97   /* form interface Contained */
98   public AbsoluteName get_absolute_name() throws RemoteException JavaDoc {
99     AbsoluteNameImpl absName;
100     if (rep == parent) { // object is contained in repository
101
absName = new AbsoluteNameImpl("::"+id.name());
102     } else {
103       absName = new AbsoluteNameImpl(((SContained)parent).get_absolute_name().name()+"::"+id.name());
104     }
105     return (AbsoluteName) absName;
106   }
107
108   /* from interface TIRObject */
109   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
110     return (DefinitionKind) defKindImpl;
111   }
112
113   /* from interface TIRObject */
114   public StateKind get_state() throws RemoteException JavaDoc {
115     return (StateKind) stKindImpl;
116   }
117
118   public void tag(String JavaDoc t) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
119     if (stKindImpl.value()!=StateKind.sk_work)
120       throw new TIRExceptCreate("you can call create method on work object");
121     String JavaDoc ebt = id.branchTag();
122     if (t.compareTo(ebt)==0)
123       throw new TIRExceptCreate("This tag exists");
124     String JavaDoc[] et = id.tag();
125     int i,j;
126     for (i=0;i<et.length;i++) {
127       if (t.compareTo(et[i])==0)
128        throw new TIRExceptCreate("This tag exists");
129     }
130     Contained[] sibl = parent.lookup_name(id);
131     for (j=0;j<sibl.length;j++) {
132       Identification idl = sibl[j].get_identification();
133       
134       ebt = idl.branchTag();
135       if (t.compareTo(ebt)==0)
136         throw new TIRExceptCreate("This tag exists");
137       et = idl.tag();
138       for (i=0;i<et.length;i++) {
139         if (t.compareTo(et[i])==0)
140           throw new TIRExceptCreate("This tag exists");
141       }
142     }
143     ((SIdentification) id).tag(t);
144   }
145
146   private void fromNormObj() throws RemoteException JavaDoc, TIRExceptLock {
147     if (normal==null)
148       return;
149     if (((WorkRepositoryImpl)rep).lock.isLocked())
150       throw new TIRExceptLock("Repository is locked");
151     int i;
152     LiItem akt;
153     akt = normal.firstChild;
154     for(i=0;i<normal.numOfItems;i++) {
155       addListItem(WorkRepositoryImpl.newWorkFromNormal(akt.obj,rep,this,workId));
156       akt = akt.next;
157     }
158     hasCont = true;
159   }
160
161   public UnionMember[] members() throws RemoteException JavaDoc, TIRExceptLock {
162     if (stKindImpl.value()==StateKind.sk_normal) {
163       if (((RepositoryImpl) rep).lock.isLocked())
164         throw new TIRExceptLock("Repository is locked");
165     } else {
166       if (!hasCont)
167         fromNormObj();
168       if (((WorkRepositoryImpl) rep).lock.isLocked())
169         throw new TIRExceptLock("Repository is locked");
170     }
171     UnionMember[] all = new UnionMember [numOfItems];
172     LiItem akt = firstChild;
173     int i,j = 0;
174     for(i=0;i<numOfItems;i++) {
175       if (akt.obj.get_def_kind().value()==DefinitionKind.dk_UnionMember) {
176         all[j] = (UnionMember) akt.obj;
177     j++;
178       }
179       akt = akt.next;
180     }
181     UnionMember[] ret = new UnionMember [j];
182     for(i=0;i<j;i++) {
183       ret[i] = all[i];
184     }
185     return ret;
186   }
187
188   public Contained[] contents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
189     if (stKindImpl.value()==StateKind.sk_normal) {
190       if (((RepositoryImpl) rep).lock.isLocked())
191         throw new TIRExceptLock("Repository is locked");
192       else
193         return super.contents(type);
194     } else {
195       if (!hasCont)
196         fromNormObj();
197       if (((WorkRepositoryImpl) rep).lock.isLocked())
198         throw new TIRExceptLock("Repository is locked");
199       else
200         return super.contents(type);
201     }
202   }
203
204   public Contained lookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
205     if (stKindImpl.value()==StateKind.sk_normal) {
206       if (((RepositoryImpl) rep).lock.isLocked())
207         throw new TIRExceptLock("Repository is locked");
208       else
209         return super.lookup(id);
210     } else {
211       if (!hasCont)
212         fromNormObj();
213       if (((WorkRepositoryImpl) rep).lock.isLocked())
214         throw new TIRExceptLock("Repository is locked");
215       else
216         return super.lookup(id);
217     }
218   }
219
220   public Contained lookup(String JavaDoc name, String JavaDoc ver) throws RemoteException JavaDoc, TIRExceptLock {
221     if (stKindImpl.value()==StateKind.sk_normal) {
222       if (((RepositoryImpl) rep).lock.isLocked())
223         throw new TIRExceptLock("Repository is locked");
224       else
225         return super.lookup(name, ver);
226     } else {
227       if (!hasCont)
228         fromNormObj();
229       if (((WorkRepositoryImpl) rep).lock.isLocked())
230         throw new TIRExceptLock("Repository is locked");
231       else
232         return super.lookup(name, ver);
233     }
234   }
235
236   public Contained[] lookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
237     if (stKindImpl.value()==StateKind.sk_normal) {
238       if (((RepositoryImpl) rep).lock.isLocked())
239         throw new TIRExceptLock("Repository is locked");
240       else
241         return super.lookup_name(id);
242     } else {
243       if (!hasCont)
244         fromNormObj();
245       if (((WorkRepositoryImpl) rep).lock.isLocked())
246         throw new TIRExceptLock("Repository is locked");
247       else
248         return super.lookup_name(id);
249     }
250   }
251
252   public Contained[] lookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
253     if (stKindImpl.value()==StateKind.sk_normal) {
254       if (((RepositoryImpl) rep).lock.isLocked())
255         throw new TIRExceptLock("Repository is locked");
256       else
257         return super.lookup_name(name);
258     } else {
259       if (!hasCont)
260         fromNormObj();
261       if (((WorkRepositoryImpl) rep).lock.isLocked())
262         throw new TIRExceptLock("Repository is locked");
263       else
264         return super.lookup_name(name);
265     }
266   }
267
268   public Contained lookup_tag(String JavaDoc name, String JavaDoc tag) throws RemoteException JavaDoc, TIRExceptLock {
269     if (stKindImpl.value()==StateKind.sk_normal) {
270       if (((RepositoryImpl) rep).lock.isLocked())
271         throw new TIRExceptLock("Repository is locked");
272       else
273         return super.lookup_tag(name, tag);
274     } else {
275       if (!hasCont)
276         fromNormObj();
277       if (((WorkRepositoryImpl) rep).lock.isLocked())
278         throw new TIRExceptLock("Repository is locked");
279       else
280         return super.lookup_tag(name, tag);
281     }
282   }
283
284   public Contained[] lookup_branchtag(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
285     if (stKindImpl.value()==StateKind.sk_normal) {
286       if (((RepositoryImpl) rep).lock.isLocked())
287         throw new TIRExceptLock("Repository is locked");
288       else
289         return super.lookup_branchtag(name, brtag);
290     } else {
291       if (!hasCont)
292         fromNormObj();
293       if (((WorkRepositoryImpl) rep).lock.isLocked())
294         throw new TIRExceptLock("Repository is locked");
295       else
296         return super.lookup_branchtag(name, brtag);
297     }
298   }
299
300   public Contained lookup_lastinbranch(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
301     if (stKindImpl.value()==StateKind.sk_normal) {
302       if (((RepositoryImpl) rep).lock.isLocked())
303         throw new TIRExceptLock("Repository is locked");
304       else
305         return super.lookup_lastinbranch(name, brtag);
306     } else {
307       if (!hasCont)
308         fromNormObj();
309       if (((WorkRepositoryImpl) rep).lock.isLocked())
310         throw new TIRExceptLock("Repository is locked");
311       else
312         return super.lookup_lastinbranch(name, brtag);
313     }
314   }
315   
316   public Contained lookup_lastfromversion(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
317     if (stKindImpl.value()==StateKind.sk_normal) {
318       if (((RepositoryImpl) rep).lock.isLocked())
319         throw new TIRExceptLock("Repository is locked");
320       else
321         return super.lookup_lastfromversion(name, version);
322     } else {
323       if (!hasCont)
324         fromNormObj();
325       if (((WorkRepositoryImpl) rep).lock.isLocked())
326         throw new TIRExceptLock("Repository is locked");
327       else
328         return super.lookup_lastfromversion(name, version);
329     }
330   }
331
332   public Contained[] scontents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
333     if (stKindImpl.value()==StateKind.sk_normal) {
334       return super.scontents(type);
335     } else {
336       if (!hasCont)
337         fromNormObj();
338       return super.scontents(type);
339     }
340   }
341
342   public Contained slookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
343     if (stKindImpl.value()==StateKind.sk_normal) {
344         return super.slookup(id);
345     } else {
346       if (!hasCont)
347         fromNormObj();
348       return super.slookup(id);
349     }
350   }
351
352   public Contained slookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
353     if (stKindImpl.value()==StateKind.sk_normal) {
354         return super.slookup(name, version);
355     } else {
356       if (!hasCont)
357         fromNormObj();
358       return super.slookup(name, version);
359     }
360   }
361
362   public Contained[] slookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
363     if (stKindImpl.value()==StateKind.sk_normal) {
364         return super.slookup_name(id);
365     } else {
366       if (!hasCont)
367         fromNormObj();
368       return super.slookup_name(id);
369     }
370   }
371
372   public Contained[] slookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
373     if (stKindImpl.value()==StateKind.sk_normal) {
374       return super.slookup_name(name);
375     } else {
376       if (!hasCont)
377         fromNormObj();
378       return super.slookup_name(name);
379     }
380   }
381
382   public UnionMember create_member(String JavaDoc name, CDLType type, ExprOperDef[] label) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
383   /* !!! dopsat testovani typu u label */
384     if (!isNew())
385       throw new TIRExceptCreate("you can call create method on work object");
386     if (name!=null && name.compareTo("")!=0 && type!=null && label!=null && label.length!=0) {
387       if (type.get_state().value()==StateKind.sk_work) {
388         for (int i=0;i<label.length;i++) {
389           if (label[i].get_state().value()!=StateKind.sk_work) {
390             throw new TIRExceptCreate("Given object isn't work.");
391           }
392         }
393     UnionMember[] a = members();
394     boolean found = false;
395     for (int i=0;i<a.length;i++) {
396           if (a[i].name().compareTo(name)==0) {
397         found = true;
398         break;
399       }
400     }
401         if (found)
402       throw new TIRExceptCreate("Member with this name exists in union.");
403         ExprOperDef[] ll = new ExprOperDef [label.length];
404         for (int i=0;i<label.length;i++)
405           ll[i] = label[i];
406     UnionMember m = new UnionMemberImpl(new IdentificationImpl(((SIdentification) this.id).language(), this.id.absolute_name().name()+"::"+name,this.id.version()), this, rep, type, ll);
407     addListItem(m);
408     return m;
409       } else {
410         throw new TIRExceptCreate("Given object isn't work.");
411       }
412     } else {
413       return null;
414     }
415   }
416
417   public StructDef create_struct(Identification id) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
418     if (!isNew())
419       throw new TIRExceptCreate("you can call create method on work object");
420     if (id!=null) {
421       if (!hasCont)
422         fromNormObj();
423       // set version of substructure same as this version
424
id = new IdentificationImpl(((SIdentification) id).language(), id.absolute_name().name(),this.id.version());
425       Contained[] a = lookup_name(id.name());
426       if (a.length != 0) {
427         if (a[0].get_def_kind().value() != DefinitionKind.dk_Struct)
428       throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
429     boolean found = false;
430     for (int i=0;i<a.length;i++) {
431       if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
432         found = true;
433         break;
434       }
435     }
436     if (found)
437       throw new TIRExceptCreate("Object with same identification exists in repository.");
438       }
439       // creating new object
440
StructDef ret = new StructDefImpl(id, this, rep, workId);
441       addListItem(ret); // adding object to list
442
return ret; // return object
443
} else
444       return null;
445   }
446   
447   public UnionDef create_union(Identification id, CDLType switch_type) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
448     if (!isNew())
449       throw new TIRExceptCreate("you can call create method on work object");
450     if (id==null || switch_type==null)
451       return null;
452     else {
453       if (switch_type.get_state().value()==StateKind.sk_work ) {
454         if (!hasCont)
455           fromNormObj();
456         // set version of substructure same as this version
457
id = new IdentificationImpl(((SIdentification) id).language(), id.absolute_name().name(),this.id.version());
458         Contained[] a = lookup_name(id.name());
459         if (a.length != 0) {
460           if (a[0].get_def_kind().value() != DefinitionKind.dk_Union)
461         throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
462       boolean found = false;
463       for (int i=0;i<a.length;i++) {
464         if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
465           found = true;
466           break;
467         }
468       }
469       if (found)
470         throw new TIRExceptCreate("Object with same identification exists in repository.");
471         }
472         // creating new object
473
UnionDef ret = new UnionDefImpl(id, this, rep, switch_type,workId);
474         addListItem(ret); // adding object to list
475
return ret; // return object
476
} else {
477         throw new TIRExceptCreate("Given object isn't work.");
478       }
479     }
480   }
481   
482   public EnumDef create_enum(Identification id) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
483     if (!isNew())
484       throw new TIRExceptCreate("you can call create method on work object");
485     if (id!=null) {
486       if (!hasCont)
487         fromNormObj();
488       // set version of substructure same as this version
489
id = new IdentificationImpl(((SIdentification) id).language(), id.absolute_name().name(),this.id.version());
490       Contained[] a = lookup_name(id.name());
491       if (a.length != 0) {
492         if (a[0].get_def_kind().value() != DefinitionKind.dk_Enum)
493       throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
494     boolean found = false;
495     for (int i=0;i<a.length;i++) {
496       if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
497         found = true;
498         break;
499       }
500     }
501     if (found)
502       throw new TIRExceptCreate("Object with same identification exists in repository.");
503       }
504       // creating new object
505
EnumDef ret = new EnumDefImpl(id, this, rep, workId);
506       addListItem(ret); // adding object to list
507
return ret; // return object
508
} else
509       return null;
510   }
511
512   /*from interface TIRImplObject */
513   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
514     try {
515       boolean closeFile = false;
516       if (st.curOutFile==null) { // saving in module
517
st.curOutFile = new DataOutputStream JavaDoc(new FileOutputStream JavaDoc(st.currentFile));
518     closeFile = true;
519       } else { // saving in other structure (or union)
520
;
521       }
522       ((IdentificationImpl)id).save(st.curOutFile); // saving identification of union
523
Storage.writeCDLType(st, swtype);
524       st.curOutFile.writeInt(numOfItems);
525       LiItem akt = firstChild;
526       for(int i=0;i<numOfItems;i++) { // saving all childs
527
st.curOutFile.writeInt(akt.obj.get_def_kind().value());
528         ((TIRImplObject)(akt.obj)).save(st);
529     akt = akt.next;
530       }
531       if (closeFile) { // close file
532
st.curOutFile.close();
533     st.curOutFile = null;
534       }
535     } catch (IOException JavaDoc e) {
536       throw new TIRExceptStorage("Access error in "+st.current+".");
537     }
538   }
539
540   /*from interface TIRImplObject */
541   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage{
542     try {
543       boolean closeFile = false;
544       if (st.curInFile==null) {
545         st.curInFile = new DataInputStream JavaDoc(new FileInputStream JavaDoc(st.currentFile));
546         closeFile = true;
547       } else {
548         ;
549       }
550       id = new IdentificationImpl();
551       ((IdentificationImpl)id).load(st.curInFile);
552       swtype = Storage.readCDLType(st);
553       int num = st.curInFile.readInt();
554       int dkind;
555       TIRImplObject obj;
556       for (int i=0;i<num;i++) {
557         dkind = st.curInFile.readInt();
558     switch (dkind) {
559       case DefinitionKind.dk_UnionMember:
560         obj = new UnionMemberImpl(this, rep);
561         obj.load(st);
562         addListItem((TIRObject)obj);
563         break;
564           case DefinitionKind.dk_Struct:
565         obj = new StructDefImpl(this, rep);
566         obj.load(st);
567         addListItem((TIRObject)obj);
568         break;
569       case DefinitionKind.dk_Enum:
570         obj = new EnumDefImpl(this, rep);
571         obj.load(st);
572         addListItem((TIRObject)obj);
573         break;
574       case DefinitionKind.dk_Union:
575         obj = new UnionDefImpl(this,rep);
576         obj.load(st);
577         addListItem((TIRObject)obj);
578         break;
579       default:
580             throw new TIRExceptStorage("Unexpected kind of object in \""
581                                   +st.currentFile+"\".");
582     } // -- end of switch
583
}
584       if (closeFile) { // close file
585
st.curInFile.close();
586     st.curInFile = null;
587       }
588     } catch (IOException JavaDoc e) {
589       throw new TIRExceptStorage("Access error in "+st.current+".");
590     }
591   }
592
593   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
594     try {
595     
596     if (swtype.get_def_kind().value() == DefinitionKind.dk_none) { // is NotYetInRep?
597
if (((NotYetInRep) swtype).defKind == DefinitionKind.dk_Primitive)
598         swtype = r.get_prim(((NotYetInRep) swtype).primKind);
599       else {
600         AbsoluteName nm = ((NotYetInRep) swtype).nm;
601     Container con = r; // begin search from repository
602
Contained[] rt;
603     Contained ret;
604     IdentificationImpl id;
605         for (int i=0;i<nm.size()-1;i++) { // last element is name of object
606
id = new IdentificationImpl(nm.elementAt(0),"::"+nm.elementAt(i),"");
607           rt = ((SContainer)con).slookup_name(id);
608       if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name());
609           if (rt.length==1) {
610             con = (Container) rt[0];
611       } else { // type in struct (etc.) - more versions of this struct
612
boolean found = false;
613             id.version(((NotYetInRep) swtype).id.version()); // substruct version is inherited from parent
614
int j = 0;
615         for (j=0;j<rt.length;j++) {
616           if (id.is_short_equal(rt[j].get_identification())) {
617             found = true;
618         break; // -- break for
619
}
620         } // -- end of for
621
if (!found) throw new TIRExceptStorage("Can't find type " + nm.name());
622         con = (Container) rt[j];
623       }
624     }
625     if ((ret = ((SContainer)con).slookup(((NotYetInRep) swtype).id))==null)
626       throw new TIRExceptStorage("Can't find type " + nm.name());
627     swtype = (CDLType) ret;
628     if (swtype.get_def_kind().value()==DefinitionKind.dk_Array ||
629             swtype.get_def_kind().value()==DefinitionKind.dk_Sequence)
630       ((TIRImplObject) swtype).postLoad(r);
631       }
632     }
633     // postLoad() items
634
LiItem akt = firstChild;
635     for(int i=0;i<numOfItems;i++) {
636       ((TIRImplObject) akt.obj).postLoad(r);
637       akt = akt.next;
638     }
639
640     } catch (TIRExceptLock e) {;}
641   }
642
643   public boolean isNew() {
644     return ((stKindImpl.value()==StateKind.sk_work) && normal==null);
645   }
646
647   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {
648     if (stKindImpl.value()==StateKind.sk_normal)
649       return;
650     LiItem akt;
651     int i;
652     akt = firstChild;
653     for (i=0;i<numOfItems;i++) {
654       ((TIRImplObject)akt.obj).canCommit();
655       akt = akt.next;
656     }
657   }
658
659   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
660     if (stKindImpl.value()==StateKind.sk_normal)
661       return;
662     if (isNew()) {
663       stKindImpl.toNormal();
664       switch (swtype.get_def_kind().value()) {
665         case DefinitionKind.dk_Primitive:
666           swtype = ((SRepository)rep).get_prim(((PrimitiveDef)swtype).kind().value());
667           break;
668         case DefinitionKind.dk_Array:
669           ArrayDef nt = new ArrayDefImpl(ExprHelp.toNormal(((ArrayDef) swtype).length()), ((ArrayDef) swtype).element_type());
670           swtype = nt;
671           ((TIRImplObject)swtype).doCommit(in,rep);
672           break;
673         case DefinitionKind.dk_Sequence:
674           SequenceDef st = new SequenceDefImpl(ExprHelp.toNormal(((SequenceDef) swtype).bound()), ((SequenceDef) swtype).element_type());
675           swtype = st;
676           ((TIRImplObject)swtype).doCommit(in,rep);
677           break;
678         case DefinitionKind.dk_String:
679           StringDef str = new StringDefImpl(ExprHelp.toNormal(((StringDef) swtype).bound()));
680           swtype = str;
681           ((TIRImplObject)swtype).doCommit(in,rep);
682           break;
683         case DefinitionKind.dk_Wstring:
684           WstringDef wstr = new WstringDefImpl(ExprHelp.toNormal(((WstringDef) swtype).bound()));
685           swtype = wstr;
686           ((TIRImplObject)swtype).doCommit(in,rep);
687           break;
688         case DefinitionKind.dk_Fixed:
689           FixedDef ft = new FixedDefImpl(ExprHelp.toNormal(((FixedDef) swtype).digits()), ExprHelp.toNormal(((FixedDef) swtype).scale()));
690           swtype = ft;
691           ((TIRImplObject)swtype).doCommit(this,rep);
692           break;
693         default:
694           Identification idl = ((Contained)swtype).get_identification();
695           swtype = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version());
696           break;
697       }
698       LiItem akt = firstChild;
699       for (int i=0;i<numOfItems;i++) {
700         ((TIRImplObject)akt.obj).doCommit(this,rep);
701         akt = akt.next;
702       }
703       parent = in;
704       this.rep = rep;
705     } else {
706       normal = null;
707     }
708   }
709
710   public void doAbort(long workId) throws RemoteException JavaDoc {
711     LiItem akt = firstChild;
712     for(int i=0;i<numOfItems;i++) {
713       if (((TIRImplObject)akt.obj).isNew())
714         ((TIRImplObject)akt.obj).doAbort(workId);
715       akt = akt.next;
716     }
717   }
718 }
719
Popular Tags