KickJava   Java API By Example, From Geeks To Geeks.

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


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