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.BindOperKind; 8 import SOFA.SOFAnode.Made.TIR.BindOperProvReq; 9 import SOFA.SOFAnode.Made.TIR.BindType; 10 import SOFA.SOFAnode.Made.TIR.BindTypeArray; 11 import SOFA.SOFAnode.Made.TIR.BindTypeKind; 12 import SOFA.SOFAnode.Made.TIR.BindTypeNormal; 13 import SOFA.SOFAnode.Made.TIR.Container; 14 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 15 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 16 import SOFA.SOFAnode.Made.TIR.Repository; 17 import SOFA.SOFAnode.Made.TIR.StateKind; 18 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 19 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 20 21 public class BindOperProvReqImpl extends UnicastRemoteObject implements BindOperProvReq, TIRImplObject { 22 DefinitionKindImpl defKindImpl; 23 StateKindImpl stKindImpl; 24 BindOperKind bok; 25 int numOfEl; 26 LiItem firstEl; 27 LiItem lastEl; 28 29 public BindOperProvReqImpl(int state) throws RemoteException { 30 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_BindOper); 31 stKindImpl = new StateKindImpl(state); 32 bok = new BindOperKindImpl(BindOperKind.bok_provreq); 33 numOfEl = 0; 34 firstEl = lastEl = null; 35 } 36 37 38 public DefinitionKind get_def_kind() throws RemoteException { 39 return (DefinitionKind) defKindImpl; 40 } 41 42 43 public StateKind get_state() throws RemoteException { 44 return (StateKind) stKindImpl; 45 } 46 47 public BindOperKind get_bo_kind() throws RemoteException { 48 return bok; 49 } 50 51 public BindType[] elements() throws RemoteException { 52 LiItem l = firstEl; 53 BindType[] ret = new BindType [numOfEl]; 54 for(int i = 0;i<numOfEl;i++) { 55 ret[i] = (BindType) l.obj; 56 l = l.next; 57 } 58 return ret; 59 } 60 61 public void save(Storage st) throws RemoteException , TIRExceptStorage { 62 try { 63 st.curOutFile.writeInt(bok.value()); 64 st.curOutFile.writeInt(numOfEl); 65 LiItem l= firstEl; 66 for(int i=0;i<numOfEl;i++) { 67 ((TIRImplObject) l.obj).save(st); 68 l = l.next; 69 } 70 } catch (IOException e) { 71 throw new TIRExceptStorage("Can't write in directory "+st.current+"."); 72 } 73 } 74 75 public void load(Storage st) throws RemoteException , TIRExceptStorage { 76 try { 77 int len = st.curInFile.readInt(); 78 for(int i=0;i<len;i++) { 79 BindType akt; 80 switch (st.curInFile.readInt()) { 81 case BindTypeKind.btk_normal: 82 akt = new BindTypeNormalImpl(); 83 break; 84 case BindTypeKind.btk_array: 85 akt = new BindTypeArrayImpl(); 86 break; 87 default: 88 throw new TIRExceptStorage("Unexpected kind of object in \""+st.currentFile+"\"."); 89 } 90 ((TIRImplObject) akt).load(st); 91 add(akt); 92 } 93 } catch (IOException e) { 94 throw new TIRExceptStorage("Can't read in directory "+st.current+"."); 95 } 96 } 97 98 public void add(BindType what) { 99 LiItem item = new LiItem(what); 100 if (firstEl == null) { 101 firstEl = lastEl = item; 102 } else { 103 lastEl.next = item; 104 item.prev = lastEl; 105 lastEl = item; 106 } 107 numOfEl++; 108 } 109 110 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 111 LiItem l = firstEl; 112 for(int i=0;i<numOfEl;i++) { 113 ((TIRImplObject) l.obj).postLoad(r); 114 l = l.next; 115 } 116 } 117 118 public boolean isNew() { 119 return (stKindImpl.value()==StateKind.sk_work); 120 } 121 122 public void canCommit() throws RemoteException , TIRExceptCommit { 123 if (numOfEl == 0) 124 throw new TIRExceptCommit("Empty prov/req bind"); 125 LiItem l = firstEl; 126 for(int i=0;i<numOfEl;i++) { 127 ((TIRImplObject) l.obj).canCommit(); 128 l = l.next; 129 } 130 } 131 132 public void doCommit(Container in, Repository rep) throws RemoteException { 133 if (stKindImpl.value()==StateKind.sk_normal) 134 return; 135 if (isNew()) { 136 LiItem l = firstEl; 137 for(int i=0;i<numOfEl;i++) { 138 ((TIRImplObject) l.obj).doCommit(in, rep); 139 l = l.next; 140 } 141 stKindImpl.toNormal(); 142 } 143 } 144 145 public void doAbort(long workId) throws RemoteException { 146 LiItem l = firstEl; 147 for(int i=0;i<numOfEl;i++) { 148 ((TIRImplObject) l.obj).doAbort(workId); 149 l = l.next; 150 } 151 } 152 153 public BindTypeNormal add_bindtypenormal(String name) throws RemoteException , TIRExceptCreate { 154 if (stKindImpl.value() == StateKind.sk_normal) 155 throw new TIRExceptCreate("You can call add method on work objects only"); 156 BindTypeNormal ret = new BindTypeNormalImpl(new String (name)); 157 add(ret); 158 return ret; 159 } 160 161 public BindTypeArray add_bindtypearray(String name, ExprOperDef[] indexes) throws RemoteException , TIRExceptCreate { 162 if (stKindImpl.value() == StateKind.sk_normal) 163 throw new TIRExceptCreate("You can call add method on work objects only"); 164 ExprOperDef[] np = new ExprOperDef [indexes.length]; 165 for (int i=0;i<indexes.length;i++) 166 np[i] = indexes[i]; 167 BindTypeArray ret = new BindTypeArrayImpl(new String (name), np); 168 add(ret); 169 return ret; 170 } 171 } 172 | Popular Tags |