KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: PropertyDefImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.io.IOException JavaDoc;
4 import java.rmi.RemoteException JavaDoc;
5
6 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
7 import SOFA.SOFAnode.Made.TIR.ArrayDef;
8 import SOFA.SOFAnode.Made.TIR.CDLType;
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.FixedDef;
13 import SOFA.SOFAnode.Made.TIR.Identification;
14 import SOFA.SOFAnode.Made.TIR.PrimitiveDef;
15 import SOFA.SOFAnode.Made.TIR.PropertyDef;
16 import SOFA.SOFAnode.Made.TIR.Repository;
17 import SOFA.SOFAnode.Made.TIR.SequenceDef;
18 import SOFA.SOFAnode.Made.TIR.StateKind;
19 import SOFA.SOFAnode.Made.TIR.StringDef;
20 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
21 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
22 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
23 import SOFA.SOFAnode.Made.TIR.WstringDef;
24
25 public class PropertyDefImpl extends ContainedImpl implements PropertyDef {
26   DefinitionKindImpl defKindImpl;
27   StateKindImpl stKindImpl;
28   CDLType typ;
29
30   PropertyDefImpl normal;
31   long workId;
32
33   public PropertyDefImpl(Identification ident, Container in, Repository inrep, CDLType t, long workId) throws RemoteException JavaDoc {
34     super(ident,in,inrep);
35     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Property);
36     stKindImpl = new StateKindImpl(StateKind.sk_work);
37     typ = t;
38     normal = null;
39     this.workId = workId;
40   }
41
42   public PropertyDefImpl(Container in, Repository inrep) throws RemoteException JavaDoc {
43     super(null,in,inrep);
44     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Property);
45     stKindImpl = new StateKindImpl(StateKind.sk_normal);
46     typ = null;
47     normal = null;
48     this.workId = -1L;
49   }
50
51   public PropertyDefImpl(PropertyDefImpl a, Container in, Repository inrep, long workId) throws RemoteException JavaDoc {
52     super(a.id,in,inrep);
53     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Property);
54     stKindImpl = new StateKindImpl(StateKind.sk_work);
55     typ = a.typ;
56     normal = a;
57     this.workId = workId;
58   }
59
60   /* from interface TIRObject */
61   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
62     return (DefinitionKind) defKindImpl;
63   }
64
65   /* from interface TIRObject */
66   public StateKind get_state() throws RemoteException JavaDoc {
67     return (StateKind) stKindImpl;
68   }
69
70   public CDLType type() throws RemoteException JavaDoc {
71     return typ;
72   }
73
74   public void tag(String JavaDoc t) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
75     if (stKindImpl.value()!=StateKind.sk_work)
76       throw new TIRExceptCreate("you can call create method on work object");
77     super.tag(t);
78   }
79   
80   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
81     try {
82       ((IdentificationImpl)id).save(st.curOutFile); // saving identification
83
Storage.writeCDLType(st, typ);
84     } catch (IOException JavaDoc e) {
85       throw new TIRExceptStorage("Can't write in file "+st.currentFile+".");
86     }
87   }
88
89   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
90     try {
91       id = new IdentificationImpl();
92       ((IdentificationImpl)id).load(st.curInFile);
93       typ = Storage.readCDLType(st);
94     } catch (IOException JavaDoc e) {
95       throw new TIRExceptStorage("Can't read in file "+st.currentFile+".");
96     }
97   }
98
99   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
100     try {
101     
102     if (typ.get_def_kind().value() == DefinitionKind.dk_none) { // is typ NotYetInRep?
103
if (((NotYetInRep) typ).defKind == DefinitionKind.dk_Primitive)
104         typ = r.get_prim(((NotYetInRep) typ).primKind);
105       else { // in typ there is reference to some type
106
AbsoluteName nm = ((NotYetInRep) typ).nm;
107     Container con = r; // begin search from repository
108
Contained[] rt;
109     Contained ret;
110     IdentificationImpl id;
111         for (int i=0;i<nm.size()-1;i++) { // last element is name of object
112
id = new IdentificationImpl(nm.elementAt(0), "::"+nm.elementAt(i),"");
113           rt = ((SContainer) con).slookup_name(id);
114       if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name());
115           if (rt.length==1) {
116             con = (Container) rt[0];
117       } else {
118         boolean found = false;
119             id.version(((NotYetInRep) typ).id.version());
120             int j = 0;
121         for (j=0;j<rt.length;j++) {
122           if (id.is_short_equal(rt[j].get_identification())) {
123             found = true;
124         break; // -- break for
125
}
126         } // -- end of for
127
if (!found) throw new TIRExceptStorage("Can't find type " + nm.name());
128         con = (Container) rt[j];
129       }
130     }
131     if ((ret = ((SContainer) con).slookup(((NotYetInRep) typ).id))==null)
132       throw new TIRExceptStorage("Can't find type " + nm.name());
133     typ = (CDLType) ret;
134     if (typ.get_def_kind().value()==DefinitionKind.dk_Array ||
135             typ.get_def_kind().value()==DefinitionKind.dk_Sequence ||
136             typ.get_def_kind().value()==DefinitionKind.dk_String ||
137             typ.get_def_kind().value()==DefinitionKind.dk_Wstring)
138       ((TIRImplObject) typ).postLoad(r);
139       }
140     } else {
141       if (typ.get_def_kind().value()==DefinitionKind.dk_Array ||
142           typ.get_def_kind().value()==DefinitionKind.dk_Sequence ||
143           typ.get_def_kind().value()==DefinitionKind.dk_String ||
144           typ.get_def_kind().value()==DefinitionKind.dk_Wstring)
145         ((TIRImplObject) typ).postLoad(r);
146     }
147
148     } catch (TIRExceptLock e) {;}
149   }
150
151  public boolean isNew() {
152     return ((stKindImpl.value()==StateKind.sk_work) && normal==null);
153   }
154
155   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
156
157   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
158     if (stKindImpl.value()==StateKind.sk_normal)
159       return;
160     if (isNew()) {
161       stKindImpl.toNormal();
162       switch (typ.get_def_kind().value()) {
163         case DefinitionKind.dk_Primitive:
164           typ = ((SRepository)rep).get_prim(((PrimitiveDef)typ).kind().value());
165           break;
166         case DefinitionKind.dk_Array:
167           ArrayDef nt = new ArrayDefImpl(ExprHelp.toNormal(((ArrayDef) typ).length()), ((ArrayDef) typ).element_type());
168           typ = nt;
169           ((TIRImplObject)typ).doCommit(in,rep);
170           break;
171         case DefinitionKind.dk_Sequence:
172           SequenceDef st = new SequenceDefImpl(ExprHelp.toNormal(((SequenceDef) typ).bound()), ((SequenceDef) typ).element_type());
173           typ = st;
174           ((TIRImplObject)typ).doCommit(in,rep);
175           break;
176         case DefinitionKind.dk_String:
177           StringDef str = new StringDefImpl(ExprHelp.toNormal(((StringDef) typ).bound()));
178           typ = str;
179           ((TIRImplObject)typ).doCommit(in,rep);
180           break;
181         case DefinitionKind.dk_Wstring:
182           WstringDef wstr = new WstringDefImpl(ExprHelp.toNormal(((WstringDef) typ).bound()));
183           typ = wstr;
184           ((TIRImplObject)typ).doCommit(in,rep);
185           break;
186         case DefinitionKind.dk_Fixed:
187           FixedDef ft = new FixedDefImpl(ExprHelp.toNormal(((FixedDef) typ).digits()), ExprHelp.toNormal(((FixedDef) typ).scale()));
188           typ = ft;
189           ((TIRImplObject)typ).doCommit(in,rep);
190           break;
191         default:
192           Identification idl = ((Contained)typ).get_identification();
193           typ = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version());
194           break;
195       }
196     } else {
197       normal=null;
198     }
199   }
200
201   public void doAbort(long workId) throws RemoteException JavaDoc {}
202 }
203
Popular Tags