KickJava   Java API By Example, From Geeks To Geeks.

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


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