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.BindTypeArray; 8 import SOFA.SOFAnode.Made.TIR.BindTypeKind; 9 import SOFA.SOFAnode.Made.TIR.Container; 10 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 11 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 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 BindTypeArrayImpl extends UnicastRemoteObject implements BindTypeArray, TIRImplObject { 17 DefinitionKindImpl defKindImpl; 18 StateKindImpl stKindImpl; 19 BindTypeKind btk; 20 String nm; 21 ExprOperDef[] inds; 22 23 public BindTypeArrayImpl(String name, ExprOperDef[] indexes) throws RemoteException { 24 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_BindType); 25 stKindImpl = new StateKindImpl(StateKind.sk_work); 26 btk = new BindTypeKindImpl(BindTypeKind.btk_array); 27 nm = name; 28 inds = indexes; 29 } 30 31 public BindTypeArrayImpl() throws RemoteException { 32 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_BindType); 33 stKindImpl = new StateKindImpl(StateKind.sk_normal); 34 btk = new BindTypeKindImpl(BindTypeKind.btk_array); 35 nm = null; 36 inds = 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 BindTypeKind get_bt_kind() throws RemoteException { 50 return btk; 51 } 52 53 public String name() throws RemoteException { 54 return nm; 55 } 56 57 public ExprOperDef[] array_indexes() throws RemoteException { 58 return inds; 59 } 60 61 public void save(Storage st) throws RemoteException , TIRExceptStorage { 62 try { 63 st.curOutFile.writeInt(btk.value()); 64 Storage.writeString(st.curOutFile, nm); 65 st.curOutFile.writeInt(inds.length); 66 for(int i=0;i<inds.length;i++) 67 Storage.writeExprOperDef(st, inds[i]); 68 } catch (IOException e) { 69 throw new TIRExceptStorage("Can't write in directory "+st.current+"."); 70 } 71 } 72 73 public void load(Storage st) throws RemoteException , TIRExceptStorage { 74 try { 75 nm = Storage.readString(st.curInFile); 76 int len = st.curInFile.readInt(); 77 inds = new ExprOperDef [len]; 78 for(int i=0;i<len;i++) 79 inds[i] = Storage.readExprOperDef(st); 80 } catch (IOException e) { 81 throw new TIRExceptStorage("Can't read in directory "+st.current+"."); 82 } 83 } 84 85 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 86 for(int i=0;i<inds.length;i++) 87 ((TIRImplObject) inds[i]).postLoad(r); 88 } 89 90 public boolean isNew() { 91 return (stKindImpl.value()==StateKind.sk_work); 92 } 93 94 public void canCommit() throws RemoteException , TIRExceptCommit { 95 for(int i=0;i<inds.length;i++) 96 ((TIRImplObject) inds[i]).canCommit(); 97 } 98 99 public void doCommit(Container in, Repository rep) throws RemoteException { 100 if (stKindImpl.value()==StateKind.sk_normal) 101 return; 102 if (isNew()) { 103 for(int i=0;i<inds.length;i++) { 104 inds[i] = ExprHelp.toNormal(inds[i]); 105 ((TIRImplObject) inds[i]).doCommit(in,rep); 106 } 107 stKindImpl.toNormal(); 108 } 109 } 110 111 public void doAbort(long workId) throws RemoteException { 112 for(int i=0;i<inds.length;i++) 113 ((TIRImplObject) inds[i]).doAbort(workId); 114 } 115 } 116 | Popular Tags |