1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.IOException ; 4 import java.rmi.RemoteException ; 5 6 import SOFA.SOFAnode.Made.TIR.BindDef; 7 import SOFA.SOFAnode.Made.TIR.BindMode; 8 import SOFA.SOFAnode.Made.TIR.BindOperDef; 9 import SOFA.SOFAnode.Made.TIR.BindOperKind; 10 import SOFA.SOFAnode.Made.TIR.BindOperProvReq; 11 import SOFA.SOFAnode.Made.TIR.BindOperSub; 12 import SOFA.SOFAnode.Made.TIR.BindType; 13 import SOFA.SOFAnode.Made.TIR.BindTypeArray; 14 import SOFA.SOFAnode.Made.TIR.BindTypeKind; 15 import SOFA.SOFAnode.Made.TIR.BindTypeNormal; 16 import SOFA.SOFAnode.Made.TIR.Container; 17 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 18 import SOFA.SOFAnode.Made.TIR.Identification; 19 import SOFA.SOFAnode.Made.TIR.Repository; 20 import SOFA.SOFAnode.Made.TIR.StateKind; 21 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 22 23 public class BindDefImpl extends ContainedImpl implements BindDef { 24 DefinitionKindImpl defKindImpl; 25 StateKindImpl stKindImpl; 26 BindOperDef rhs; 27 BindOperDef lhs; 28 BindMode mod; 29 String connector; 30 31 BindDefImpl normal; 32 33 public BindDefImpl(Identification ident, Container in, Repository inrep, BindOperDef l, BindOperDef r, BindMode m, String using) throws RemoteException { 34 super(ident,in,inrep); 35 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Bind); 36 stKindImpl = new StateKindImpl(StateKind.sk_work); 37 rhs = r; 38 lhs = l; 39 mod = m; 40 connector = using; 41 normal = null; 42 } 43 44 public BindDefImpl(Container in, Repository inrep) throws RemoteException { 45 super(null ,in,inrep); 46 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Bind); 47 stKindImpl = new StateKindImpl(StateKind.sk_normal); 48 rhs = null; 49 lhs = null; 50 mod = null; 51 connector = null; 52 normal = null; 53 } 54 55 public BindDefImpl(BindDefImpl a, Container in, Repository inrep) throws RemoteException { 56 super(a.id ,in,inrep); 57 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Bind); 58 stKindImpl = new StateKindImpl(StateKind.sk_work); 59 rhs = a.rhs; 60 lhs = a.lhs; 61 mod = a.mod; 62 connector = a.connector; 63 normal = a; 64 } 65 66 67 public DefinitionKind get_def_kind() throws RemoteException { 68 return (DefinitionKind) defKindImpl; 69 } 70 71 72 public StateKind get_state() throws RemoteException { 73 return (StateKind) stKindImpl; 74 } 75 76 public BindOperDef lhsop() throws RemoteException { 77 return lhs; 78 } 79 80 public BindOperDef rhsop() throws RemoteException { 81 return rhs; 82 } 83 84 public BindMode mode() throws RemoteException { 85 return mod; 86 } 87 88 public String using() throws RemoteException { 89 return connector; 90 } 91 92 public void save(Storage st) throws RemoteException , TIRExceptStorage { 93 try { 94 ((IdentificationImpl)id).save(st.curOutFile); 95 ((TIRImplObject) rhs).save(st); 96 ((TIRImplObject) lhs).save(st); 97 ((TIRImplObject) mod).save(st); 98 Storage.writeString(st.curOutFile, connector); 99 } catch (IOException e) { 100 throw new TIRExceptStorage("Can't write in file "+st.currentFile+"."); 101 } 102 } 103 104 public void load(Storage st) throws RemoteException , TIRExceptStorage { 105 try { 106 id = new IdentificationImpl(); 107 ((IdentificationImpl)id).load(st.curInFile); 108 int kind = st.curInFile.readInt(); 109 switch (kind) { 110 case BindOperKind.bok_provreq: 111 rhs = new BindOperProvReqImpl(StateKind.sk_normal); 112 break; 113 case BindOperKind.bok_sub: 114 rhs = new BindOperSubImpl(StateKind.sk_normal); 115 break; 116 } 117 ((TIRImplObject) rhs).load(st); 118 kind = st.curInFile.readInt(); 119 switch (kind) { 120 case BindOperKind.bok_provreq: 121 lhs = new BindOperProvReqImpl(StateKind.sk_normal); 122 break; 123 case BindOperKind.bok_sub: 124 lhs = new BindOperSubImpl(StateKind.sk_normal); 125 break; 126 } 127 ((TIRImplObject) lhs).load(st); 128 mod = new BindModeImpl(); 129 ((TIRImplObject) mod).load(st); 130 connector = Storage.readString(st.curInFile); 131 } catch (IOException e) { 132 throw new TIRExceptStorage("Can't write in file "+st.currentFile+"."); 133 } 134 } 135 136 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 137 ((TIRImplObject) rhs).postLoad(r); 138 ((TIRImplObject) lhs).postLoad(r); 139 } 140 141 public boolean isNew() { 142 return ((stKindImpl.value()==StateKind.sk_work) && normal==null); 143 } 144 145 public void canCommit() throws RemoteException , TIRExceptCommit {;} 146 147 public void doCommit(Container in, Repository rep) throws RemoteException { 148 if (stKindImpl.value()==StateKind.sk_work) { 149 stKindImpl.toNormal(); 150 rhs = bo_toNormal(rhs); 151 lhs = bo_toNormal(lhs); 152 ((TIRImplObject)rhs).doCommit(in,rep); 153 ((TIRImplObject)lhs).doCommit(in,rep); 154 } 155 } 156 157 public void doAbort(long workId) throws RemoteException { 158 ((TIRImplObject)rhs).doAbort(workId); 159 ((TIRImplObject)lhs).doAbort(workId); 160 } 161 162 private BindOperDef bo_toNormal(BindOperDef b) throws RemoteException { 163 if (b != null) { 164 switch (b.get_bo_kind().value()) { 165 case BindOperKind.bok_provreq: { 166 BindOperProvReqImpl ret = new BindOperProvReqImpl(StateKind.sk_work); 167 BindType[] el = ((BindOperProvReq) b).elements(); 168 for (int i=0;i<el.length;i++) { 169 switch (el[i].get_bt_kind().value()) { 170 case BindTypeKind.btk_normal: 171 ret.add(new BindTypeNormalImpl(new String (((BindTypeNormal) el[i]).name()))); 172 break; 173 case BindTypeKind.btk_array: 174 ret.add(new BindTypeArrayImpl(new String (((BindTypeArray) el[i]).name()), ((BindTypeArray) el[i]).array_indexes())); 175 break; 176 } 177 } 178 return ret; 179 } 180 case BindOperKind.bok_sub: { 181 BindOperSubImpl ret = new BindOperSubImpl(StateKind.sk_work); 182 BindType[] el = ((BindOperSub) b).elements(); 183 for (int i=0;i<el.length;i++) { 184 switch (el[i].get_bt_kind().value()) { 185 case BindTypeKind.btk_normal: 186 ret.addEl(new BindTypeNormalImpl(new String (((BindTypeNormal) el[i]).name()))); 187 break; 188 case BindTypeKind.btk_array: 189 ret.addEl(new BindTypeArrayImpl(new String (((BindTypeArray) el[i]).name()), ((BindTypeArray) el[i]).array_indexes())); 190 break; 191 } 192 } 193 el = ((BindOperSub) b).subs(); 194 for (int i=0;i<el.length;i++) { 195 switch (el[i].get_bt_kind().value()) { 196 case BindTypeKind.btk_normal: 197 ret.addSub(new BindTypeNormalImpl(new String (((BindTypeNormal) el[i]).name()))); 198 break; 199 case BindTypeKind.btk_array: 200 ret.addSub(new BindTypeArrayImpl(new String (((BindTypeArray) el[i]).name()), ((BindTypeArray) el[i]).array_indexes())); 201 break; 202 } 203 } 204 return ret; 205 } 206 } } 208 return null; 209 } 210 } 211 | Popular Tags |