KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: RequireDefImpl.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.CDLType;
8 import SOFA.SOFAnode.Made.TIR.Contained;
9 import SOFA.SOFAnode.Made.TIR.Container;
10 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
11 import SOFA.SOFAnode.Made.TIR.Identification;
12 import SOFA.SOFAnode.Made.TIR.Repository;
13 import SOFA.SOFAnode.Made.TIR.RequireDef;
14 import SOFA.SOFAnode.Made.TIR.StateKind;
15 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
16 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
17 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
18
19 public class RequireDefImpl extends ContainedImpl implements RequireDef, TIRImplObject {
20   CDLType req;
21   DefinitionKindImpl defKindImpl;
22   StateKindImpl stKindImpl;
23
24   RequireDefImpl normal;
25   long workId;
26
27   public RequireDefImpl(Identification ident, Container in, Repository inrep, CDLType r, long workId) throws RemoteException JavaDoc {
28     super(ident,in,inrep);
29     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Requires);
30     stKindImpl = new StateKindImpl(StateKind.sk_work);
31     req = r;
32     normal = null;
33     this.workId = workId;
34   }
35
36   public RequireDefImpl(Container in, Repository inrep) throws RemoteException JavaDoc {
37     super(null,in,inrep);
38     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Requires);
39     stKindImpl = new StateKindImpl(StateKind.sk_normal);
40     req = null;
41     normal = null;
42     this.workId = -1L;
43   }
44
45   public RequireDefImpl(RequireDefImpl a, Container in, Repository inrep, long workId) throws RemoteException JavaDoc {
46     super(a.id,in,inrep);
47     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Requires);
48     stKindImpl = new StateKindImpl(StateKind.sk_work);
49     req = a.req;
50     normal = a;
51     this.workId = workId;
52   }
53
54   public CDLType require() throws RemoteException JavaDoc {
55     return req;
56   }
57
58   /* from interface TIRObject */
59   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
60     return (DefinitionKind) defKindImpl;
61   }
62
63   /* from interface TIRObject */
64   public StateKind get_state() throws RemoteException JavaDoc {
65     return (StateKind) stKindImpl;
66   }
67
68   public void tag(String JavaDoc t) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
69     if (stKindImpl.value()!=StateKind.sk_work)
70       throw new TIRExceptCreate("you can call create method on work object");
71     super.tag(t);
72   }
73
74   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
75     try {
76       int i;
77       ((IdentificationImpl) id).save(st.curOutFile);
78       Storage.writeCDLType(st, req);
79     } catch (IOException JavaDoc e) {
80       throw new TIRExceptStorage("Can't write in file "+st.currentFile+".");
81     }
82   }
83
84   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
85     try {
86       int i;
87       id = new IdentificationImpl();
88       ((IdentificationImpl) id).load(st.curInFile);
89       req = Storage.readCDLType(st);
90     } catch (IOException JavaDoc e) {
91       throw new TIRExceptStorage("Can't write in file "+st.currentFile+".");
92     }
93   }
94
95   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
96     try {
97     
98       Container con;
99       Contained[] rt;
100       Contained ret;
101       IdentificationImpl id;
102       AbsoluteName nm;
103       boolean found;
104       if (req.get_def_kind().value() == DefinitionKind.dk_none) { // is tp NotYetInRep?
105
nm = ((NotYetInRep) req).nm;
106     con = r; // begin search from repository
107
for (int i=0;i<nm.size()-1;i++) { // last element is name of object
108
id = new IdentificationImpl(nm.elementAt(0), "::"+nm.elementAt(i),"");
109           rt = ((SContainer)con).slookup_name(id);
110       if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name());
111             if (rt.length==1) {
112               con = (Container) rt[0];
113       } else {
114         found = false;
115             id.version(((NotYetInRep) req).id.version());
116             int k = 0;
117         for (k=0;k<rt.length;k++) {
118           if (id.is_short_equal(rt[k].get_identification())) {
119             found = true;
120         break; // -- break for
121
}
122         } // -- end of for
123
if (!found) throw new TIRExceptStorage("Can't find type " + nm.name());
124         con = (Container) rt[k];
125       }
126     }
127     if ((ret = ((SContainer)con).slookup(((NotYetInRep) req).id))==null)
128       throw new TIRExceptStorage("Can't find type " + nm.name());
129     req = (CDLType) ret;
130     if (req.get_def_kind().value()==DefinitionKind.dk_Array ||
131         req.get_def_kind().value()==DefinitionKind.dk_Sequence)
132       ((TIRImplObject) req).postLoad(r);
133       }
134
135     } catch (TIRExceptLock e) {;}
136   }
137
138   public boolean isNew() {
139     return ((stKindImpl.value()==StateKind.sk_work) && normal==null);
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       switch (req.get_def_kind().value()) {
150         case DefinitionKind.dk_Array:
151         case DefinitionKind.dk_Sequence:
152         case DefinitionKind.dk_String:
153         case DefinitionKind.dk_Wstring:
154         case DefinitionKind.dk_Fixed:
155           ((TIRImplObject)req).doCommit(in,rep);
156           break;
157         default:
158           Identification idl = ((Contained)req).get_identification();
159           req = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version());
160           break;
161       }
162     } else
163       normal = null;
164   }
165
166   public void doAbort(long workId) throws RemoteException JavaDoc {}
167 }
168
Popular Tags