1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.rmi.RemoteException ; 4 import java.rmi.server.UnicastRemoteObject ; 5 6 import SOFA.SOFAnode.Made.TIR.Container; 7 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 8 import SOFA.SOFAnode.Made.TIR.ProtocolBinOperationDef; 9 import SOFA.SOFAnode.Made.TIR.ProtocolDef; 10 import SOFA.SOFAnode.Made.TIR.ProtocolMetaOperandDef; 11 import SOFA.SOFAnode.Made.TIR.ProtocolNestedOperandDef; 12 import SOFA.SOFAnode.Made.TIR.ProtocolNullOperandDef; 13 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef; 14 import SOFA.SOFAnode.Made.TIR.ProtocolOperKind; 15 import SOFA.SOFAnode.Made.TIR.ProtocolOperandDef; 16 import SOFA.SOFAnode.Made.TIR.ProtocolUnOperationDef; 17 import SOFA.SOFAnode.Made.TIR.Repository; 18 import SOFA.SOFAnode.Made.TIR.StateKind; 19 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 20 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 21 22 public class ProtocolDefImpl extends UnicastRemoteObject implements ProtocolDef, TIRImplObject { 23 ProtocolOperDef op; 24 DefinitionKindImpl defKindImpl; 25 StateKindImpl stKindImpl; 26 27 public ProtocolDefImpl(ProtocolOperDef o) throws RemoteException { 28 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Protocol); 29 stKindImpl = new StateKindImpl(StateKind.sk_work); 30 op = o; 31 } 32 33 public ProtocolDefImpl(int state) throws RemoteException { 34 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Protocol); 35 stKindImpl = new StateKindImpl(state); 36 op = null; 37 } 38 39 40 public DefinitionKind get_def_kind() throws RemoteException { 41 return (DefinitionKind) defKindImpl; 42 } 43 44 45 public StateKind get_state() throws RemoteException { 46 return (StateKind) stKindImpl; 47 } 48 49 public ProtocolOperDef protocol() throws RemoteException { 50 return op; 51 } 52 53 public void protocol(ProtocolOperDef pr) throws RemoteException , TIRExceptCreate { 54 if (stKindImpl.value()==StateKind.sk_normal) 55 throw new TIRExceptCreate("you can call create method on work object"); 56 op = pr; 57 } 58 59 public ProtocolBinOperationDef create_binoperation(int pokind, ProtocolOperDef op1, ProtocolOperDef op2) throws RemoteException , TIRExceptCreate { 60 if (stKindImpl.value()==StateKind.sk_normal) 61 throw new TIRExceptCreate("you can call create method on work object"); 62 if (op1==null || op2==null) 63 return null; 64 if (op1.get_state().value()==StateKind.sk_work && 65 op2.get_state().value()==StateKind.sk_work ) { 66 return new ProtocolBinOperationDefImpl(pokind,op1,op2); 67 } else 68 throw new TIRExceptCreate("Given objects aren't work."); 69 } 70 71 public ProtocolUnOperationDef create_unoperation(int pokind, ProtocolOperDef op) throws RemoteException , TIRExceptCreate { 72 if (stKindImpl.value()==StateKind.sk_normal) 73 throw new TIRExceptCreate("you can call create method on work object"); 74 if (op==null) 75 return null; 76 if (op.get_state().value()==StateKind.sk_work) { 77 return new ProtocolUnOperationDefImpl(pokind,op); 78 } else 79 throw new TIRExceptCreate("Given object isn't work."); 80 } 81 82 public ProtocolNestedOperandDef create_nestedoperand(int mode, String [] op, ProtocolOperDef nestOper) throws RemoteException , TIRExceptCreate { 83 if (stKindImpl.value()==StateKind.sk_normal) 84 throw new TIRExceptCreate("you can call create method on work object"); 85 if (op==null || nestOper==null) 86 return null; 87 if (op.length==0) 88 return null; 89 if (nestOper.get_state().value()==StateKind.sk_work) { 90 return new ProtocolNestedOperandDefImpl(op, new ProtocolModeImpl(mode), nestOper); 91 } else 92 throw new TIRExceptCreate("Given object isn't work."); 93 } 94 95 public ProtocolOperandDef create_operand(int mode, String [] op) throws RemoteException , TIRExceptCreate { 96 if (stKindImpl.value()==StateKind.sk_normal) 97 throw new TIRExceptCreate("you can call create method on work object"); 98 if (op==null) 99 return null; 100 if (op.length==0) 101 return null; 102 return new ProtocolOperandDefImpl(op, new ProtocolModeImpl(mode)); 103 } 104 105 public ProtocolNullOperandDef create_nulloperand() throws RemoteException , TIRExceptCreate { 106 if (stKindImpl.value()==StateKind.sk_normal) 107 throw new TIRExceptCreate("you can call create method on work object"); 108 return new ProtocolNullOperandDefImpl(StateKind.sk_work); 109 } 110 111 public ProtocolMetaOperandDef create_metaoperand(String name) throws RemoteException , TIRExceptCreate { 112 if (stKindImpl.value()==StateKind.sk_normal) 113 throw new TIRExceptCreate("you can call create method on work object"); 114 if (name==null) 115 return null; 116 return new ProtocolMetaOperandDefImpl(name); 117 } 118 119 public void save(Storage st) throws RemoteException , TIRExceptStorage { 120 Storage.writeProtocolOperDef(st, op); 121 } 122 123 public void load(Storage st) throws RemoteException , TIRExceptStorage { 124 op = Storage.readProtocolOperDef(st); 125 } 126 127 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 128 ((TIRImplObject) op).postLoad(r); 129 } 130 131 public boolean isNew() { 132 return (stKindImpl.value()==StateKind.sk_work); 133 } 134 135 public void canCommit() throws RemoteException , TIRExceptCommit {;} 136 137 public void doCommit(Container in, Repository rep) throws RemoteException { 138 if (stKindImpl.value()==StateKind.sk_normal) 139 return; 140 stKindImpl.toNormal(); 141 op = toNormal(op); 142 ((TIRImplObject) op).doCommit(in,rep); 143 } 144 145 public void doAbort(long workId) throws RemoteException {} 146 147 public String to_text() throws RemoteException { 148 return ((SProtocolOperDef)op).to_text(); 149 } 150 151 static ProtocolOperDef toNormal(ProtocolOperDef pr) throws RemoteException { 152 if (pr == null) 153 return null; 154 String [] sold; 155 String [] snew; 156 ProtocolOperDef o1; 157 ProtocolOperDef o2; 158 int i; 159 switch (pr.get_po_kind().value()) { 160 case ProtocolOperKind.pok_andparallel: 161 case ProtocolOperKind.pok_orparallel: 162 case ProtocolOperKind.pok_sequence: 163 case ProtocolOperKind.pok_alternative: 164 case ProtocolOperKind.pok_restriction: 165 o1 = toNormal(((ProtocolBinOperationDef) pr).operand1()); 166 o2 = toNormal(((ProtocolBinOperationDef) pr).operand2()); 167 return new ProtocolBinOperationDefImpl(pr.get_po_kind().value(),o1,o2); 168 case ProtocolOperKind.pok_repetition: 169 o1 = toNormal(((ProtocolUnOperationDef) pr).operand()); 170 return new ProtocolUnOperationDefImpl(pr.get_po_kind().value(),o1); 171 case ProtocolOperKind.pok_nestedoperand: 172 o1 = toNormal(((ProtocolNestedOperandDef) pr).nested_operand()); 173 sold = ((ProtocolNestedOperandDef) pr).operand(); 174 snew = new String [sold.length]; 175 for(i=0;i<sold.length;i++) { 176 snew[i] = new String (sold[i]); 177 } 178 return new ProtocolNestedOperandDefImpl(snew, new ProtocolModeImpl(((ProtocolNestedOperandDef) pr).operand_mode().value()),o1); 179 case ProtocolOperKind.pok_operand: 180 sold = ((ProtocolOperandDef) pr).operand(); 181 snew = new String [sold.length]; 182 for(i=0;i<sold.length;i++) { 183 snew[i] = new String (sold[i]); 184 } 185 return new ProtocolOperandDefImpl(snew, new ProtocolModeImpl(((ProtocolOperandDef) pr).operand_mode().value())); 186 case ProtocolOperKind.pok_nulloperand: 187 return new ProtocolNullOperandDefImpl(StateKind.sk_normal); 188 case ProtocolOperKind.pok_metaoperand: 189 return new ProtocolMetaOperandDefImpl(new String ( ((ProtocolMetaOperandDef)pr).name() )); 190 } 191 return null; 192 } 193 } 194 | Popular Tags |