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.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 implements ProtocolOperandDef, TIRImplObject, SProtocolOperDef { 17 String [] op; 18 ProtocolMode mod; 19 ProtocolOperKind pok; 20 DefinitionKindImpl defKindImpl; 21 StateKindImpl stKindImpl; 22 23 24 public ProtocolOperandDefImpl(String [] oper, ProtocolMode mode) throws RemoteException { 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 [oper.length]; 30 for (int i=0;i<oper.length;i++) { 31 op[i] = new String (oper[i]); 32 } 33 } 34 35 public ProtocolOperandDefImpl() throws RemoteException { 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 { 44 return pok; 45 } 46 47 48 public DefinitionKind get_def_kind() throws RemoteException { 49 return (DefinitionKind) defKindImpl; 50 } 51 52 53 public StateKind get_state() throws RemoteException { 54 return (StateKind) stKindImpl; 55 } 56 57 public String [] operand() throws RemoteException { 58 return op; 59 } 60 61 public ProtocolMode operand_mode() throws RemoteException { 62 return mod; 63 } 64 65 public void save(Storage st) throws RemoteException , 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 e) { 74 throw new TIRExceptStorage("Can't write in directory "+st.current+"."); 75 } 76 } 77 78 public void load(Storage st) throws RemoteException , TIRExceptStorage { 79 try { 80 mod = new ProtocolModeImpl(); 81 ((TIRImplObject) mod).load(st); 82 int j = st.curInFile.readInt(); 83 op = new String [j]; 84 for(int i=0;i<j;i++) { 85 op[i] = Storage.readString(st.curInFile); 86 } 87 } catch (IOException e) { 88 throw new TIRExceptStorage("Can't read in directory "+st.current+"."); 89 } 90 } 91 92 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 93 } 94 95 public boolean isNew() { 96 return (stKindImpl.value()==StateKind.sk_work); 97 } 98 99 public void canCommit() throws RemoteException , TIRExceptCommit {;} 100 101 public void doCommit(Container in, Repository rep) throws RemoteException { 102 if (stKindImpl.value()==StateKind.sk_normal) 103 return; 104 stKindImpl.toNormal(); 105 } 106 107 public void doAbort(long workId) throws RemoteException {} 108 109 public String to_text() throws RemoteException { 110 StringBuffer sb = new StringBuffer (); 111 if (mod.value() == ProtocolMode.pm_none) { sb.append(op[0]); 113 } else { 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 |