KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ProtocolNestedOperandDefImpl.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.Container;
9 import SOFA.SOFAnode.Made.TIR.DefinitionKind;
10 import SOFA.SOFAnode.Made.TIR.ProtocolMode;
11 import SOFA.SOFAnode.Made.TIR.ProtocolNestedOperandDef;
12 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef;
13 import SOFA.SOFAnode.Made.TIR.ProtocolOperKind;
14 import SOFA.SOFAnode.Made.TIR.Repository;
15 import SOFA.SOFAnode.Made.TIR.StateKind;
16 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit;
17
18 public class ProtocolNestedOperandDefImpl extends UnicastRemoteObject JavaDoc implements ProtocolNestedOperandDef, TIRImplObject, SProtocolOperDef {
19   String JavaDoc[] op;
20   ProtocolOperDef nestOper;
21   ProtocolMode mod;
22   ProtocolOperKind pok;
23   DefinitionKindImpl defKindImpl;
24   StateKindImpl stKindImpl;
25   
26   // next three attribs are for loading operation
27
IdentificationImpl ifaceId;
28   IdentificationImpl operId;
29   AbsoluteName aName;
30
31   public ProtocolNestedOperandDefImpl(String JavaDoc[] oper, ProtocolMode mode, ProtocolOperDef nestOper) throws RemoteException JavaDoc {
32     mod = mode;
33     this.nestOper = nestOper;
34     pok = new ProtocolOperKindImpl(ProtocolOperKind.pok_nestedoperand);
35     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
36     stKindImpl = new StateKindImpl(StateKind.sk_work);
37     op = new String JavaDoc [oper.length];
38     for (int i=0;i<oper.length;i++) {
39       op[i] = new String JavaDoc(oper[i]);
40     }
41   }
42
43   public ProtocolNestedOperandDefImpl() throws RemoteException JavaDoc {
44     op = null;
45     mod = null;
46     pok = new ProtocolOperKindImpl(ProtocolOperKind.pok_nestedoperand);
47     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
48     stKindImpl = new StateKindImpl(StateKind.sk_normal);
49   }
50
51   public ProtocolOperKind get_po_kind() throws RemoteException JavaDoc {
52     return pok;
53   }
54
55   /* from interface TIRObject */
56   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
57     return (DefinitionKind) defKindImpl;
58   }
59
60   /* from interface TIRObject */
61   public StateKind get_state() throws RemoteException JavaDoc {
62     return (StateKind) stKindImpl;
63   }
64
65   public String JavaDoc[] operand() throws RemoteException JavaDoc {
66     return op;
67   }
68
69   public ProtocolOperDef nested_operand() throws RemoteException JavaDoc {
70     return nestOper;
71   }
72   
73   public ProtocolMode operand_mode() throws RemoteException JavaDoc {
74     return mod;
75   }
76
77   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
78     try {
79       st.curOutFile.writeInt(pok.value());
80       ((TIRImplObject) mod).save(st);
81       st.curOutFile.writeInt(op.length);
82       for(int i=0;i<op.length;i++) {
83         Storage.writeString(st.curOutFile, op[i]);
84       }
85       Storage.writeProtocolOperDef(st, nestOper);
86     } catch (IOException JavaDoc e) {
87       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
88     }
89   }
90   
91   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
92     try {
93       mod = new ProtocolModeImpl();
94       ((TIRImplObject) mod).load(st);
95       int j = st.curInFile.readInt();
96       op = new String JavaDoc [j];
97       for(int i=0;i<j;i++) {
98         op[i] = Storage.readString(st.curInFile);
99       }
100       nestOper = Storage.readProtocolOperDef(st);
101     } catch (IOException JavaDoc e) {
102       throw new TIRExceptStorage("Can't read in directory "+st.current+".");
103     }
104   }
105
106   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
107     ((TIRImplObject) nestOper).postLoad(r);
108   }
109
110   public boolean isNew() {
111     return (stKindImpl.value()==StateKind.sk_work);
112   }
113
114   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
115
116   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
117     if (stKindImpl.value()==StateKind.sk_normal)
118       return;
119     stKindImpl.toNormal();
120     ((TIRImplObject) nestOper).doCommit(in,rep);
121   }
122
123   public void doAbort(long workId) throws RemoteException JavaDoc {}
124
125   public String JavaDoc to_text() throws RemoteException JavaDoc {
126     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
127     if (mod.value() == ProtocolMode.pm_in)
128       sb.append("?");
129     else
130       sb.append("!");
131     sb.append(op[0]);
132     for(int i=1;i<op.length;i++) {
133       sb.append(".");
134       sb.append(op[i]);
135     }
136     sb.append("{");
137     sb.append(((SProtocolOperDef) nestOper).to_text());
138     sb.append("}");
139     return sb.toString();
140   }
141 }
142
Popular Tags