KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ProtocolBinOperationDefImpl.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.ProtocolBinOperationDef;
10 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef;
11 import SOFA.SOFAnode.Made.TIR.ProtocolOperKind;
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 ProtocolBinOperationDefImpl extends UnicastRemoteObject JavaDoc implements ProtocolBinOperationDef, TIRImplObject, SProtocolOperDef {
17   ProtocolOperKindImpl pok;
18   DefinitionKindImpl defKindImpl;
19   StateKindImpl stKindImpl;
20   ProtocolOperDef oper1;
21   ProtocolOperDef oper2;
22
23   public ProtocolBinOperationDefImpl(int kind, ProtocolOperDef op1, ProtocolOperDef op2) throws RemoteException JavaDoc {
24     pok = new ProtocolOperKindImpl(kind);
25     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
26     stKindImpl = new StateKindImpl(StateKind.sk_work);
27     oper1 = op1;
28     oper2 = op2;
29   }
30
31   public ProtocolBinOperationDefImpl(int kind) throws RemoteException JavaDoc {
32     pok = new ProtocolOperKindImpl(kind);
33     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
34     stKindImpl = new StateKindImpl(StateKind.sk_normal);
35     oper1 = null;
36     oper2 = null;
37   }
38
39   public ProtocolBinOperationDefImpl() throws RemoteException JavaDoc {
40     pok = null;
41     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Protocol);
42     stKindImpl = new StateKindImpl(StateKind.sk_normal);
43     oper1 = null;
44     oper2 = null;
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 ProtocolOperDef operand1() throws RemoteException JavaDoc {
58     return oper1;
59   }
60
61   public ProtocolOperDef operand2() throws RemoteException JavaDoc {
62     return oper2;
63   }
64
65   public ProtocolOperKind get_po_kind() throws RemoteException JavaDoc {
66     return pok;
67   }
68
69   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
70     try {
71       st.curOutFile.writeInt(pok.value());
72       Storage.writeProtocolOperDef(st, oper1);
73       Storage.writeProtocolOperDef(st, oper2);
74     } catch (IOException JavaDoc e) {
75       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
76     }
77   }
78
79   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
80     oper1 = Storage.readProtocolOperDef(st);
81     oper2 = Storage.readProtocolOperDef(st);
82   }
83
84   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
85     ((TIRImplObject) oper1).postLoad(r);
86     ((TIRImplObject) oper2).postLoad(r);
87   }
88
89   public boolean isNew() {
90     return (stKindImpl.value()==StateKind.sk_work);
91   }
92
93   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
94
95   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
96     if (stKindImpl.value()==StateKind.sk_normal)
97       return;
98     stKindImpl.toNormal();
99     ((TIRImplObject) oper1).doCommit(in,rep);
100     ((TIRImplObject) oper2).doCommit(in,rep);
101   }
102
103   public void doAbort(long workId) throws RemoteException JavaDoc {}
104
105   public String JavaDoc to_text() throws RemoteException JavaDoc {
106     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("(");
107     String JavaDoc strOp="";
108     switch (pok.value()) {
109     case ProtocolOperKind.pok_alternative:
110       strOp = ")+(";
111       break;
112     case ProtocolOperKind.pok_andparallel:
113       strOp = ")|(";
114       break;
115     case ProtocolOperKind.pok_orparallel:
116       strOp = ")||(";
117       break;
118     case ProtocolOperKind.pok_sequence:
119       strOp = ");(";
120       break;
121     case ProtocolOperKind.pok_restriction:
122       strOp = ")/(";
123       break;
124     default: break;
125     }
126     
127     sb.append(((SProtocolOperDef)oper1).to_text());
128     sb.append(strOp);
129     sb.append(((SProtocolOperDef)oper2).to_text());
130     sb.append(")");
131     return sb.toString();
132   }
133 }
134
Popular Tags