KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: BindTypeArrayImpl.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.BindTypeArray;
8 import SOFA.SOFAnode.Made.TIR.BindTypeKind;
9 import SOFA.SOFAnode.Made.TIR.Container;
10 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
11 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
12 import SOFA.SOFAnode.Made.TIR.Repository;
13 import SOFA.SOFAnode.Made.TIR.StateKind;
14 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
15
16 public class BindTypeArrayImpl extends UnicastRemoteObject JavaDoc implements BindTypeArray, TIRImplObject {
17   DefinitionKindImpl defKindImpl;
18   StateKindImpl stKindImpl;
19   BindTypeKind btk;
20   String JavaDoc nm;
21   ExprOperDef[] inds;
22   
23   public BindTypeArrayImpl(String JavaDoc name, ExprOperDef[] indexes) throws RemoteException JavaDoc {
24     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_BindType);
25     stKindImpl = new StateKindImpl(StateKind.sk_work);
26     btk = new BindTypeKindImpl(BindTypeKind.btk_array);
27     nm = name;
28     inds = indexes;
29   }
30
31   public BindTypeArrayImpl() throws RemoteException JavaDoc {
32     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_BindType);
33     stKindImpl = new StateKindImpl(StateKind.sk_normal);
34     btk = new BindTypeKindImpl(BindTypeKind.btk_array);
35     nm = null;
36     inds = null;
37   }
38
39 /* from interface TIRObject */
40   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
41     return (DefinitionKind) defKindImpl;
42   }
43
44   /* from interface TIRObject */
45   public StateKind get_state() throws RemoteException JavaDoc {
46     return (StateKind) stKindImpl;
47   }
48
49   public BindTypeKind get_bt_kind() throws RemoteException JavaDoc {
50     return btk;
51   }
52
53   public String JavaDoc name() throws RemoteException JavaDoc {
54     return nm;
55   }
56
57   public ExprOperDef[] array_indexes() throws RemoteException JavaDoc {
58     return inds;
59   }
60
61   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
62     try {
63       st.curOutFile.writeInt(btk.value());
64       Storage.writeString(st.curOutFile, nm);
65       st.curOutFile.writeInt(inds.length);
66       for(int i=0;i<inds.length;i++)
67         Storage.writeExprOperDef(st, inds[i]);
68     } catch (IOException JavaDoc e) {
69       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
70     }
71   }
72
73   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
74     try {
75       nm = Storage.readString(st.curInFile);
76       int len = st.curInFile.readInt();
77       inds = new ExprOperDef [len];
78       for(int i=0;i<len;i++)
79         inds[i] = Storage.readExprOperDef(st);
80     } catch (IOException JavaDoc e) {
81       throw new TIRExceptStorage("Can't read in directory "+st.current+".");
82     }
83   }
84
85   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
86     for(int i=0;i<inds.length;i++)
87       ((TIRImplObject) inds[i]).postLoad(r);
88   }
89
90   public boolean isNew() {
91     return (stKindImpl.value()==StateKind.sk_work);
92   }
93
94   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {
95     for(int i=0;i<inds.length;i++)
96       ((TIRImplObject) inds[i]).canCommit();
97   }
98
99   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
100     if (stKindImpl.value()==StateKind.sk_normal)
101       return;
102     if (isNew()) {
103       for(int i=0;i<inds.length;i++) {
104         inds[i] = ExprHelp.toNormal(inds[i]);
105         ((TIRImplObject) inds[i]).doCommit(in,rep);
106       }
107       stKindImpl.toNormal();
108     }
109   }
110
111   public void doAbort(long workId) throws RemoteException JavaDoc {
112     for(int i=0;i<inds.length;i++)
113       ((TIRImplObject) inds[i]).doAbort(workId);
114   }
115 }
116
Popular Tags