KickJava   Java API By Example, From Geeks To Geeks.

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


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