KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: InterfaceDefImpl.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.AttributeDef;
12 import SOFA.SOFAnode.Made.TIR.CDLType;
13 import SOFA.SOFAnode.Made.TIR.ConstantDef;
14 import SOFA.SOFAnode.Made.TIR.Contained;
15 import SOFA.SOFAnode.Made.TIR.Container;
16 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
17 import SOFA.SOFAnode.Made.TIR.EnumDef;
18 import SOFA.SOFAnode.Made.TIR.ExceptionDef;
19 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
20 import SOFA.SOFAnode.Made.TIR.Identification;
21 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
22 import SOFA.SOFAnode.Made.TIR.OperationDef;
23 import SOFA.SOFAnode.Made.TIR.ProtocolDef;
24 import SOFA.SOFAnode.Made.TIR.Repository;
25 import SOFA.SOFAnode.Made.TIR.StateKind;
26 import SOFA.SOFAnode.Made.TIR.StructDef;
27 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
28 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
29 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
30 import SOFA.SOFAnode.Made.TIR.TIRObject;
31 import SOFA.SOFAnode.Made.TIR.TypedefDef;
32 import SOFA.SOFAnode.Made.TIR.UnionDef;
33
34 public class InterfaceDefImpl extends ContainerImpl implements InterfaceDef, SContained {
35   protected Identification id;
36   protected Container parent;
37   protected Repository rep;
38   DefinitionKindImpl defKindImpl;
39   StateKindImpl stKindImpl;
40   InterfaceDef[] base;
41   CDLType[] loadBase; // for loading
42
ProtocolDef prot;
43
44   InterfaceDefImpl normal;
45   long workId;
46
47   public InterfaceDefImpl(Identification ident, Container in, Repository inrep, InterfaceDef[] baseIf, long workId) throws RemoteException JavaDoc {
48     id = ident;
49     parent = in;
50     rep = inrep;
51     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface);
52     stKindImpl = new StateKindImpl(StateKind.sk_work);
53     if (baseIf==null)
54       base = new InterfaceDef [0];
55     else
56       base = baseIf;
57     prot = null;
58     normal = null;
59     this.workId = workId;
60   }
61
62   public InterfaceDefImpl(Container in, Repository inrep) throws RemoteException JavaDoc {
63     id = null;
64     parent = in;
65     rep = inrep;
66     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface);
67     stKindImpl = new StateKindImpl(StateKind.sk_normal);
68     base = null;
69     prot = null;
70     normal = null;
71     this.workId = -1L;
72   }
73
74   public InterfaceDefImpl(InterfaceDefImpl a, Container in, Repository inrep, long workId) throws RemoteException JavaDoc {
75     id = a.id;
76     parent = in;
77     rep = inrep;
78     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface);
79     stKindImpl = new StateKindImpl(StateKind.sk_work);
80     base = a.base;
81     prot = a.prot;
82     normal = a;
83     this.workId = workId;
84   }
85
86   public InterfaceDef[] base_interfaces() throws RemoteException JavaDoc {
87     return base;
88   }
89
90   public ProtocolDef protocol() throws RemoteException JavaDoc {
91     return prot;
92   }
93
94   /* form interface Contained */
95   public Identification get_identification() throws RemoteException JavaDoc {
96     return id;
97   }
98
99   /* form interface Contained */
100   public Container get_defined_in() throws RemoteException JavaDoc {
101     return parent;
102   }
103
104   /* form interface Contained */
105   public Container get_containing_repository() throws RemoteException JavaDoc {
106     return rep;
107   }
108
109   /* form interface Contained */
110   public AbsoluteName get_absolute_name() throws RemoteException JavaDoc {
111     AbsoluteNameImpl absName;
112     if (rep == parent) { // object is contained in repository
113
absName = new AbsoluteNameImpl("::"+id.name());
114     } else {
115       absName = new AbsoluteNameImpl(((SContained)parent).get_absolute_name().name()+"::"+id.name());
116     }
117     return (AbsoluteName) absName;
118   }
119
120   /* from interface TIRObject */
121   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
122     return (DefinitionKind) defKindImpl;
123   }
124
125   /* from interface TIRObject */
126   public StateKind get_state() throws RemoteException JavaDoc {
127     return (StateKind) stKindImpl;
128   }
129
130   public void tag(String JavaDoc t) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
131     if (stKindImpl.value()!=StateKind.sk_work)
132       throw new TIRExceptCreate("you can call create method on work object");
133     String JavaDoc ebt = id.branchTag();
134     if (t.compareTo(ebt)==0)
135       throw new TIRExceptCreate("This tag exists");
136     String JavaDoc[] et = id.tag();
137     int i,j;
138     for (i=0;i<et.length;i++) {
139       if (t.compareTo(et[i])==0)
140        throw new TIRExceptCreate("This tag exists");
141     }
142     Contained[] sibl = parent.lookup_name(id);
143     for (j=0;j<sibl.length;j++) {
144       Identification idl = sibl[j].get_identification();
145       
146       ebt = idl.branchTag();
147       if (t.compareTo(ebt)==0)
148         throw new TIRExceptCreate("This tag exists");
149       et = idl.tag();
150       for (i=0;i<et.length;i++) {
151         if (t.compareTo(et[i])==0)
152           throw new TIRExceptCreate("This tag exists");
153       }
154     }
155     ((SIdentification) id).tag(t);
156   }
157
158   private void fromNormObj() throws RemoteException JavaDoc, TIRExceptLock {
159     if (normal==null)
160       return;
161     if (((WorkRepositoryImpl)rep).lock.isLocked())
162       throw new TIRExceptLock("Repository is locked");
163     int i;
164     LiItem akt;
165     akt = normal.firstChild;
166     for(i=0;i<normal.numOfItems;i++) {
167       addListItem(WorkRepositoryImpl.newWorkFromNormal(akt.obj,rep,this,workId));
168       akt = akt.next;
169     }
170     hasCont = true;
171   }
172
173   public Contained[] contents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
174     if (stKindImpl.value()==StateKind.sk_normal) {
175       if (((RepositoryImpl) rep).lock.isLocked())
176         throw new TIRExceptLock("Repository is locked");
177       else
178         return super.contents(type);
179     } else {
180       if (!hasCont)
181         fromNormObj();
182       if (((WorkRepositoryImpl) rep).lock.isLocked())
183         throw new TIRExceptLock("Repository is locked");
184       else
185         return super.contents(type);
186     }
187   }
188
189   public Contained lookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
190     if (stKindImpl.value()==StateKind.sk_normal) {
191       if (((RepositoryImpl) rep).lock.isLocked())
192         throw new TIRExceptLock("Repository is locked");
193       else
194         return super.lookup(id);
195     } else {
196       if (!hasCont)
197         fromNormObj();
198       if (((WorkRepositoryImpl) rep).lock.isLocked())
199         throw new TIRExceptLock("Repository is locked");
200       else
201         return super.lookup(id);
202     }
203   }
204
205   public Contained lookup(String JavaDoc name, String JavaDoc ver) throws RemoteException JavaDoc, TIRExceptLock {
206     if (stKindImpl.value()==StateKind.sk_normal) {
207       if (((RepositoryImpl) rep).lock.isLocked())
208         throw new TIRExceptLock("Repository is locked");
209       else
210         return super.lookup(name, ver);
211     } else {
212       if (!hasCont)
213         fromNormObj();
214       if (((WorkRepositoryImpl) rep).lock.isLocked())
215         throw new TIRExceptLock("Repository is locked");
216       else
217         return super.lookup(name, ver);
218     }
219   }
220
221   public Contained[] lookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
222     if (stKindImpl.value()==StateKind.sk_normal) {
223       if (((RepositoryImpl) rep).lock.isLocked())
224         throw new TIRExceptLock("Repository is locked");
225       else
226         return super.lookup_name(id);
227     } else {
228       if (!hasCont)
229         fromNormObj();
230       if (((WorkRepositoryImpl) rep).lock.isLocked())
231         throw new TIRExceptLock("Repository is locked");
232       else
233         return super.lookup_name(id);
234     }
235   }
236
237   public Contained[] lookup_name(String JavaDoc id) throws RemoteException JavaDoc, TIRExceptLock {
238     if (stKindImpl.value()==StateKind.sk_normal) {
239       if (((RepositoryImpl) rep).lock.isLocked())
240         throw new TIRExceptLock("Repository is locked");
241       else
242         return super.lookup_name(id);
243     } else {
244       if (!hasCont)
245         fromNormObj();
246       if (((WorkRepositoryImpl) rep).lock.isLocked())
247         throw new TIRExceptLock("Repository is locked");
248       else
249         return super.lookup_name(id);
250     }
251   }
252
253   public Contained lookup_tag(String JavaDoc name, String JavaDoc tag) throws RemoteException JavaDoc, TIRExceptLock {
254     if (stKindImpl.value()==StateKind.sk_normal) {
255       if (((RepositoryImpl) rep).lock.isLocked())
256         throw new TIRExceptLock("Repository is locked");
257       else
258         return super.lookup_tag(name, tag);
259     } else {
260       if (!hasCont)
261         fromNormObj();
262       if (((WorkRepositoryImpl) rep).lock.isLocked())
263         throw new TIRExceptLock("Repository is locked");
264       else
265         return super.lookup_tag(name, tag);
266     }
267   }
268
269   public Contained[] lookup_branchtag(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
270     if (stKindImpl.value()==StateKind.sk_normal) {
271       if (((RepositoryImpl) rep).lock.isLocked())
272         throw new TIRExceptLock("Repository is locked");
273       else
274         return super.lookup_branchtag(name, brtag);
275     } else {
276       if (!hasCont)
277         fromNormObj();
278       if (((WorkRepositoryImpl) rep).lock.isLocked())
279         throw new TIRExceptLock("Repository is locked");
280       else
281         return super.lookup_branchtag(name, brtag);
282     }
283   }
284
285   public Contained lookup_lastinbranch(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
286     if (stKindImpl.value()==StateKind.sk_normal) {
287       if (((RepositoryImpl) rep).lock.isLocked())
288         throw new TIRExceptLock("Repository is locked");
289       else
290         return super.lookup_lastinbranch(name, brtag);
291     } else {
292       if (!hasCont)
293         fromNormObj();
294       if (((WorkRepositoryImpl) rep).lock.isLocked())
295         throw new TIRExceptLock("Repository is locked");
296       else
297         return super.lookup_lastinbranch(name, brtag);
298     }
299   }
300   
301   public Contained lookup_lastfromversion(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
302     if (stKindImpl.value()==StateKind.sk_normal) {
303       if (((RepositoryImpl) rep).lock.isLocked())
304         throw new TIRExceptLock("Repository is locked");
305       else
306         return super.lookup_lastfromversion(name, version);
307     } else {
308       if (!hasCont)
309         fromNormObj();
310       if (((WorkRepositoryImpl) rep).lock.isLocked())
311         throw new TIRExceptLock("Repository is locked");
312       else
313         return super.lookup_lastfromversion(name, version);
314     }
315   }
316
317   public Contained[] scontents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
318     if (stKindImpl.value()==StateKind.sk_normal) {
319       return super.scontents(type);
320     } else {
321       if (!hasCont)
322         fromNormObj();
323       return super.scontents(type);
324     }
325   }
326
327   public Contained slookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
328     if (stKindImpl.value()==StateKind.sk_normal) {
329         return super.slookup(id);
330     } else {
331       if (!hasCont)
332         fromNormObj();
333       return super.slookup(id);
334     }
335   }
336
337   public Contained slookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
338     if (stKindImpl.value()==StateKind.sk_normal) {
339         return super.slookup(name, version);
340     } else {
341       if (!hasCont)
342         fromNormObj();
343       return super.slookup(name, version);
344     }
345   }
346
347   public Contained[] slookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
348     if (stKindImpl.value()==StateKind.sk_normal) {
349         return super.slookup_name(id);
350     } else {
351       if (!hasCont)
352         fromNormObj();
353       return super.slookup_name(id);
354     }
355   }
356
357   public Contained[] slookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
358     if (stKindImpl.value()==StateKind.sk_normal) {
359       return super.slookup_name(name);
360     } else {
361       if (!hasCont)
362         fromNormObj();
363       return super.slookup_name(name);
364     }
365   }
366
367   public StructDef create_struct(Identification id) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
368     if (!isNew())
369       throw new TIRExceptCreate("you can call create method on work object");
370     if (id!=null) {
371       if (!hasCont)
372         fromNormObj();
373       // set version of substructure same as this version
374
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
375       Contained[] a = lookup_name(id.name());
376       if (a.length != 0) {
377         if (a[0].get_def_kind().value() != DefinitionKind.dk_Struct)
378       throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
379     boolean found = false;
380     for (int i=0;i<a.length;i++) {
381       if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
382         found = true;
383         break;
384       }
385     }
386     if (found)
387       throw new TIRExceptCreate("Object with same identification exists in repository.");
388       }
389       // creating new object
390
StructDef ret = new StructDefImpl(id, this, rep,workId);
391       addListItem(ret); // adding object to list
392
return ret; // return object
393
} else
394       return null;
395   }
396   
397   public UnionDef create_union(Identification id, CDLType switch_type) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
398     if (!isNew())
399       throw new TIRExceptCreate("you can call create method on work object");
400     if (id==null || switch_type==null)
401       return null;
402     else {
403       if (switch_type.get_state().value()==StateKind.sk_work ) {
404         if (!hasCont)
405           fromNormObj();
406         // set version of substructure same as this version
407
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
408         Contained[] a = lookup_name(id.name());
409         if (a.length != 0) {
410           if (a[0].get_def_kind().value() != DefinitionKind.dk_Union)
411         throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
412       boolean found = false;
413       for (int i=0;i<a.length;i++) {
414         if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
415           found = true;
416           break;
417         }
418       }
419       if (found)
420         throw new TIRExceptCreate("Object with same identification exists in repository.");
421         }
422         // creating new object
423
UnionDef ret = new UnionDefImpl(id, this, rep, switch_type,workId);
424         addListItem(ret); // adding object to list
425
return ret; // return object
426
} else {
427         throw new TIRExceptCreate("Given object isn't work.");
428       }
429     }
430   }
431   
432   public EnumDef create_enum(Identification id) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
433     if (!isNew())
434       throw new TIRExceptCreate("you can call create method on work object");
435     if (id!=null) {
436       if (!hasCont)
437         fromNormObj();
438       // set version of substructure same as this version
439
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
440       Contained[] a = lookup_name(id.name());
441       if (a.length != 0) {
442         if (a[0].get_def_kind().value() != DefinitionKind.dk_Enum)
443       throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
444     boolean found = false;
445     for (int i=0;i<a.length;i++) {
446       if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
447         found = true;
448         break;
449       }
450     }
451     if (found)
452       throw new TIRExceptCreate("Object with same identification exists in repository.");
453       }
454       // creating new object
455
EnumDef ret = new EnumDefImpl(id, this, rep, workId);
456       addListItem(ret); // adding object to list
457
return ret; // return object
458
} else
459       return null;
460   }
461
462   public AttributeDef create_attribute(Identification name, CDLType type, int mode) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
463     if (!isNew())
464       throw new TIRExceptCreate("you can call create method on work object");
465     if (type==null)
466       return null;
467     if (type.get_state().value()==StateKind.sk_work) {
468       // set version of substructure same as this version
469
Identification id = new IdentificationImpl(((SIdentification)name).language(), name.absolute_name().name(),this.id.version());
470       Contained[] a = lookup_name(name.name());
471       if (a.length != 0)
472     throw new TIRExceptCreate("Name \""+name.name()+"\" exists in repository.");
473       // creating new object
474
AttributeDef ret = new AttributeDefImpl(id, this, rep, type, new AttrModeImpl(mode), workId);
475       addListItem(ret); // adding object to list
476
return ret; // return object
477
} else {
478       throw new TIRExceptCreate("Given object isn't work.");
479     }
480   }
481
482   public OperationDef create_operation(Identification name, CDLType result, ExceptionDef[] exceptions) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
483     if (!isNew())
484       throw new TIRExceptCreate("you can call create method on work object");
485     if (result==null || exceptions==null)
486       return null;
487     int i;
488     for (i=0;i<exceptions.length;i++)
489       if (exceptions[i]==null)
490         return null;
491     if (result.get_state().value()==StateKind.sk_normal)
492       throw new TIRExceptCreate("Given object isn't work.");
493     for (i=0;i<exceptions.length;i++)
494       if (exceptions[i].get_state().value()==StateKind.sk_normal)
495         throw new TIRExceptCreate("Given object isn't work.");
496     // set version of substructure same as this version
497
Identification id = new IdentificationImpl(((SIdentification)name).language(), name.absolute_name().name(),this.id.version());
498     Contained[] a = lookup_name(name.name());
499     if (a.length != 0)
500        throw new TIRExceptCreate("Name \""+name.name()+"\" exists in repository.");
501       // creating new object
502
ExceptionDef[] ne = new ExceptionDef [exceptions.length];
503     for (i=0;i<exceptions.length;i++)
504       ne[i]=exceptions[i];
505     OperationDef ret = new OperationDefImpl(id, this, rep, result, ne, workId);
506     addListItem(ret); // adding object to list
507
return ret; // return object
508
}
509
510   public ProtocolDef create_protocol() throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
511     if (!isNew())
512       throw new TIRExceptCreate("You can call create method on work object only");
513     if (prot!=null)
514       throw new TIRExceptCreate("Protocol already exists");
515     prot = new ProtocolDefImpl(StateKind.sk_work);
516     return prot;
517   }
518
519   public ConstantDef create_constant(Identification id, CDLType type, ExprOperDef value) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
520     if (!isNew())
521       throw new TIRExceptCreate("you can call create method on work object");
522     if (id==null || type==null || value==null)
523       return null;
524     else {
525       if (type.get_state().value()==StateKind.sk_work &&
526           value.get_state().value()==StateKind.sk_work) {
527         if (!hasCont)
528           fromNormObj();
529         // set version of substructure same as this version
530
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
531         Contained[] a = lookup_name(id.name());
532         if (a.length != 0) {
533           if (a[0].get_def_kind().value() != DefinitionKind.dk_Constant)
534         throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
535       boolean found = false;
536       for (int i=0;i<a.length;i++) {
537         if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
538           found = true;
539           break;
540         }
541       }
542       if (found)
543         throw new TIRExceptCreate("Object with same identification exists in repository.");
544         }
545         // creating new object
546
ConstantDef ret = new ConstantDefImpl(id, this, rep,type, value, workId);
547         addListItem(ret); // adding object to list
548
return ret; // return object
549
} else {
550         throw new TIRExceptCreate("Given objects aren't work.");
551       }
552     }
553   }
554
555   public TypedefDef create_typedef(Identification id, CDLType orig_type) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
556     if (!isNew())
557       throw new TIRExceptCreate("you can call create method on work object");
558     if (id==null || orig_type==null)
559       return null;
560     else {
561       if (orig_type.get_state().value()==StateKind.sk_work ) {
562         if (!hasCont)
563           fromNormObj();
564         // set version of substructure same as this version
565
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
566         Contained[] a = lookup_name(id.name());
567         if (a.length != 0) {
568           if (a[0].get_def_kind().value() != DefinitionKind.dk_Typedef)
569         throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
570       boolean found = false;
571       for (int i=0;i<a.length;i++) {
572         if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
573           found = true;
574           break;
575         }
576       }
577       if (found)
578         throw new TIRExceptCreate("Object with same identification exists in repository.");
579         }
580         // creating new object
581
TypedefDef ret = new TypedefDefImpl(id, this, rep, orig_type,workId);
582         addListItem(ret); // adding object to list
583
return ret; // return object
584
} else {
585         throw new TIRExceptCreate("Given object isn't work.");
586       }
587     }
588   }
589   
590   public ExceptionDef create_exception(Identification id) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
591     if (!isNew())
592       throw new TIRExceptCreate("you can call create method on work object");
593     if (id!=null) {
594       if (!hasCont)
595         fromNormObj();
596       // set version of substructure same as this version
597
id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version());
598       Contained[] a = lookup_name(id.name());
599       if (a.length != 0) {
600         if (a[0].get_def_kind().value() != DefinitionKind.dk_Exception)
601       throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository.");
602     boolean found = false;
603     for (int i=0;i<a.length;i++) {
604       if (((SIdentification) a[i].get_identification()).is_short_equal(id)) {
605         found = true;
606         break;
607       }
608     }
609     if (found)
610       throw new TIRExceptCreate("Object with same identification exists in repository.");
611       }
612       // creating new object
613
ExceptionDef ret = new ExceptionDefImpl(id, this, rep,workId);
614       addListItem(ret); // adding object to list
615
return ret; // return object
616
} else
617       return null;
618   }
619
620
621   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
622     try {
623       int i;
624       st.curOutFile = new DataOutputStream JavaDoc(new FileOutputStream JavaDoc(st.currentFile));
625       ((IdentificationImpl)id).save(st.curOutFile); // saving identification
626
// saving protocol
627
if (prot != null) {
628         st.curOutFile.writeBoolean(true);
629         ((TIRImplObject) prot).save(st);
630       } else {
631          st.curOutFile.writeBoolean(false);
632       }
633       // --- and of saving protocol
634
st.curOutFile.writeInt(base.length);
635       for(i=0;i<base.length;i++) {
636         Storage.writeCDLType(st, base[i]);
637       }
638       st.curOutFile.writeInt(numOfItems);
639       LiItem akt = firstChild;
640       for(i=0;i<numOfItems;i++) { // saving all childs
641
st.curOutFile.writeInt(akt.obj.get_def_kind().value());
642         ((TIRImplObject)(akt.obj)).save(st);
643     akt = akt.next;
644       }
645       st.curOutFile.close();
646     } catch (IOException JavaDoc e) {
647       throw new TIRExceptStorage("Access error in "+st.currentFile+".");
648     }
649   }
650
651   /*from interface TIRImplObject */
652   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage{
653     try {
654       int num,i;
655       st.curInFile = new DataInputStream JavaDoc(new FileInputStream JavaDoc(st.currentFile));
656       id = new IdentificationImpl();
657       ((IdentificationImpl)id).load(st.curInFile);
658       // loading protocol
659
if (st.curInFile.readBoolean()) {
660         prot = new ProtocolDefImpl(StateKind.sk_normal);
661         ((TIRImplObject) prot).load(st);
662       } else {
663         prot = null;
664       }
665       // --- end of loading protocol
666
num = st.curInFile.readInt();
667       loadBase = new CDLType [num];
668       for(i=0;i<num;i++) {
669         loadBase[i] = Storage.readCDLType(st);
670       }
671       num = st.curInFile.readInt();
672       int dkind;
673       TIRImplObject obj;
674       for (i=0;i<num;i++) {
675         dkind = st.curInFile.readInt();
676     switch (dkind) {
677           case DefinitionKind.dk_Struct:
678         obj = new StructDefImpl(this, rep);
679         obj.load(st);
680         addListItem((TIRObject)obj);
681         break;
682       case DefinitionKind.dk_Enum:
683         obj = new EnumDefImpl(this, rep);
684         obj.load(st);
685         addListItem((TIRObject)obj);
686         break;
687       case DefinitionKind.dk_Union:
688         obj = new UnionDefImpl(this, rep);
689         obj.load(st);
690         addListItem((TIRObject)obj);
691         break;
692       case DefinitionKind.dk_Exception:
693         obj = new ExceptionDefImpl(this, rep);
694         obj.load(st);
695         addListItem((TIRObject)obj);
696         break;
697       case DefinitionKind.dk_Constant:
698         obj = new ConstantDefImpl(this, rep);
699         obj.load(st);
700         addListItem((TIRObject)obj);
701         break;
702       case DefinitionKind.dk_Typedef:
703         obj = new TypedefDefImpl(this, rep);
704         obj.load(st);
705         addListItem((TIRObject)obj);
706         break;
707       case DefinitionKind.dk_Attribute:
708         obj = new AttributeDefImpl(this, rep);
709         obj.load(st);
710         addListItem((TIRObject)obj);
711         break;
712       case DefinitionKind.dk_Operation:
713         obj = new OperationDefImpl(this, rep);
714         obj.load(st);
715         addListItem((TIRObject)obj);
716         break;
717       default:
718             throw new TIRExceptStorage("Unexpected kind of object in \""
719                                   +st.currentFile+"\".");
720     } // -- end of switch
721
}
722       st.curInFile.close();
723     } catch (IOException JavaDoc e) {
724       throw new TIRExceptStorage("Access error in "+st.current+".");
725     }
726   }
727
728   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
729     try {
730   
731     int i,k;
732
733     if (prot != null)
734       ((TIRImplObject) prot).postLoad(r);
735
736     LiItem akt = firstChild;
737     for(i=0;i<numOfItems;i++) {
738       ((TIRImplObject) akt.obj).postLoad(r);
739       akt = akt.next;
740     }
741
742     // postLoad base
743
Container con;
744     Contained[] rt;
745     Contained ret;
746     IdentificationImpl id;
747     AbsoluteName nm;
748     boolean found;
749     base = new InterfaceDef [loadBase.length];
750     for (int j=0;j<loadBase.length;j++) {
751       if (loadBase[j].get_def_kind().value() == DefinitionKind.dk_none) { // is tp NotYetInRep?
752
nm = ((NotYetInRep) loadBase[j]).nm;
753     con = r; // begin search from repository
754
for (i=0;i<nm.size()-1;i++) { // last element is name of object
755
id = new IdentificationImpl(nm.elementAt(0),"::"+nm.elementAt(i),"");
756           rt = ((SContainer)con).slookup_name(id);
757       if (rt.length==0) throw new TIRExceptStorage("Can't find interface " + nm.name());
758             if (rt.length==1) {
759               con = (Container) rt[0];
760       } else {
761         found = false;
762             id.version(((NotYetInRep) loadBase[j]).id.version());
763         for (k=0;k<rt.length;k++) {
764           if (id.is_short_equal(rt[k].get_identification())) {
765             found = true;
766         break; // -- break for
767
}
768         } // -- end of for
769
if (!found) throw new TIRExceptStorage("Can't find interface " + nm.name());
770         con = (Container) rt[k];
771       }
772     }
773     if ((ret = ((SContainer)con).slookup(((NotYetInRep) loadBase[j]).id))==null)
774       throw new TIRExceptStorage("Can't find interface " + nm.name());
775     base[j] = (InterfaceDef) ret;
776     if (base[j].get_def_kind().value()==DefinitionKind.dk_Array ||
777             base[j].get_def_kind().value()==DefinitionKind.dk_Sequence)
778       ((TIRImplObject) base[j]).postLoad(r);
779       }
780     }
781
782     } catch (TIRExceptLock e) {;}
783   }
784
785  public boolean isNew() {
786     return ((stKindImpl.value()==StateKind.sk_work) && normal==null);
787   }
788
789   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {
790     if (stKindImpl.value()==StateKind.sk_normal)
791       return;
792     LiItem akt;
793     int i;
794     akt = firstChild;
795     for (i=0;i<numOfItems;i++) {
796       ((TIRImplObject)akt.obj).canCommit();
797       akt = akt.next;
798     }
799     if (prot != null)
800       ((TIRImplObject)prot).canCommit();
801   }
802
803   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
804     if (stKindImpl.value()==StateKind.sk_normal)
805       return;
806     if (isNew()) {
807       int i;
808       stKindImpl.toNormal();
809       LiItem akt = firstChild;
810       for (i=0;i<numOfItems;i++) {
811         ((TIRImplObject)akt.obj).doCommit(this,rep);
812         akt = akt.next;
813       }
814       loadBase = new CDLType [base.length];
815       for (i=0;i<base.length;i++) {
816         Identification idl = ((Contained)base[i]).get_identification();
817         loadBase[i] = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version());
818       }
819       if (prot != null)
820         ((TIRImplObject)prot).doCommit(this, rep);
821       base = null;
822       parent = in;
823       this.rep = rep;
824     } else {
825       normal = null;
826     }
827   }
828
829   public void doAbort(long workId) throws RemoteException JavaDoc {
830     LiItem akt = firstChild;
831     for(int i=0;i<numOfItems;i++) {
832       if (((TIRImplObject)akt.obj).isNew())
833         ((TIRImplObject)akt.obj).doAbort(workId);
834       akt = akt.next;
835     }
836   }
837
838   public void setBaseInterfaces(InterfaceDef[] base_interfaces) throws RemoteException JavaDoc, TIRExceptCreate {
839     if (base_interfaces == null)
840       base = new InterfaceDef [0];
841     else {
842       base = new InterfaceDef [base_interfaces.length];
843       for (int i=0;i<base_interfaces.length;i++) {
844         if (base_interfaces[i].get_state().value()==StateKind.sk_work)
845       base[i]=base_interfaces[i];
846     else
847       throw new TIRExceptCreate("Given objects aren't work.");
848       }
849     }
850   }
851 }
852
Popular Tags