KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ProtocolUnOperationDefImpl.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.ProtocolOperDef;
10 import SOFA.SOFAnode.Made.TIR.ProtocolOperKind;
11 import SOFA.SOFAnode.Made.TIR.ProtocolUnOperationDef;
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 ProtocolUnOperationDefImpl extends UnicastRemoteObject JavaDoc implements ProtocolUnOperationDef, TIRImplObject, SProtocolOperDef {
17   ProtocolOperKindImpl pok;
18   DefinitionKindImpl defKindImpl;
19   StateKindImpl stKindImpl;
20   ProtocolOperDef oper;
21
22   public ProtocolUnOperationDefImpl(int kind, ProtocolOperDef op) throws RemoteException JavaDoc {
23     pok = new ProtocolOperKindImpl(kind);
24     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
25     stKindImpl = new StateKindImpl(StateKind.sk_work);
26     oper = op;
27   }
28
29   public ProtocolUnOperationDefImpl(int kind) throws RemoteException JavaDoc {
30     pok = new ProtocolOperKindImpl(kind);
31     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_ProtocolOper);
32     stKindImpl = new StateKindImpl(StateKind.sk_normal);
33     oper = null;
34   }
35
36   public ProtocolUnOperationDefImpl() throws RemoteException JavaDoc {
37     pok = null;
38     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Protocol);
39     stKindImpl = new StateKindImpl(StateKind.sk_normal);
40     oper = null;
41   }
42
43   /* from interface TIRObject */
44   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
45     return (DefinitionKind) defKindImpl;
46   }
47
48   /* from interface TIRObject */
49   public StateKind get_state() throws RemoteException JavaDoc {
50     return (StateKind) stKindImpl;
51   }
52
53   public ProtocolOperDef operand() throws RemoteException JavaDoc {
54     return oper;
55   }
56
57   public ProtocolOperKind get_po_kind() throws RemoteException JavaDoc {
58     return pok;
59   }
60
61   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
62     try {
63       st.curOutFile.writeInt(pok.value());
64       Storage.writeProtocolOperDef(st, oper);
65     } catch (IOException JavaDoc e) {
66       throw new TIRExceptStorage("Can't write in directory "+st.current+".");
67     }
68   }
69
70   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
71     oper = Storage.readProtocolOperDef(st);
72   }
73
74   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
75     ((TIRImplObject) oper).postLoad(r);
76   }
77
78   public boolean isNew() {
79     return (stKindImpl.value()==StateKind.sk_work);
80   }
81
82   public void canCommit() throws RemoteException JavaDoc, TIRExceptCommit {;}
83
84   public void doCommit(Container in, Repository rep) throws RemoteException JavaDoc {
85     if (stKindImpl.value()==StateKind.sk_normal)
86       return;
87     stKindImpl.toNormal();
88     ((TIRImplObject) oper).doCommit(in,rep);
89   }
90
91   public void doAbort(long workId) throws RemoteException JavaDoc {}
92
93   public String JavaDoc to_text() throws RemoteException JavaDoc {
94     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("(");
95     switch (pok.value()) {
96     case ProtocolOperKind.pok_repetition:
97       sb.append(((SProtocolOperDef)oper).to_text());
98       sb.append(")*");
99       break;
100     default: break;
101     }
102     return sb.toString();
103   }
104 }
105
Popular Tags