1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.IOException ; 4 import java.rmi.RemoteException ; 5 import java.rmi.server.UnicastRemoteObject ; 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 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 { 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 { 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 { 37 pok = null; 38 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Protocol); 39 stKindImpl = new StateKindImpl(StateKind.sk_normal); 40 oper = null; 41 } 42 43 44 public DefinitionKind get_def_kind() throws RemoteException { 45 return (DefinitionKind) defKindImpl; 46 } 47 48 49 public StateKind get_state() throws RemoteException { 50 return (StateKind) stKindImpl; 51 } 52 53 public ProtocolOperDef operand() throws RemoteException { 54 return oper; 55 } 56 57 public ProtocolOperKind get_po_kind() throws RemoteException { 58 return pok; 59 } 60 61 public void save(Storage st) throws RemoteException , TIRExceptStorage { 62 try { 63 st.curOutFile.writeInt(pok.value()); 64 Storage.writeProtocolOperDef(st, oper); 65 } catch (IOException e) { 66 throw new TIRExceptStorage("Can't write in directory "+st.current+"."); 67 } 68 } 69 70 public void load(Storage st) throws RemoteException , TIRExceptStorage { 71 oper = Storage.readProtocolOperDef(st); 72 } 73 74 public void postLoad(RepositoryImpl r) throws RemoteException , 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 , TIRExceptCommit {;} 83 84 public void doCommit(Container in, Repository rep) throws RemoteException { 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 {} 92 93 public String to_text() throws RemoteException { 94 StringBuffer sb = new StringBuffer ("("); 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 |