KickJava   Java API By Example, From Geeks To Geeks.

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


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