KickJava   Java API By Example, From Geeks To Geeks.

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


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