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