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.CDLType; 9 import SOFA.SOFAnode.Made.TIR.ConstantDef; 10 import SOFA.SOFAnode.Made.TIR.Contained; 11 import SOFA.SOFAnode.Made.TIR.Container; 12 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 13 import SOFA.SOFAnode.Made.TIR.ExprConstant; 14 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 15 import SOFA.SOFAnode.Made.TIR.ExprOperKind; 16 import SOFA.SOFAnode.Made.TIR.Identification; 17 import SOFA.SOFAnode.Made.TIR.Repository; 18 import SOFA.SOFAnode.Made.TIR.StateKind; 19 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate; 20 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 21 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 22 23 public class ExprConstantImpl extends UnicastRemoteObject implements ExprConstant, TIRImplObject { 24 ConstantDef cnst; 25 CDLType loadCnst; 26 ExprOperKindImpl eok; 27 DefinitionKindImpl defKindImpl; 28 StateKindImpl stKindImpl; 29 30 public ExprConstantImpl(ConstantDef constant) throws RemoteException { 31 cnst = constant; 32 loadCnst = null; 33 eok = new ExprOperKindImpl(ExprOperKind.eok_constant); 34 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression); 35 stKindImpl = new StateKindImpl(StateKind.sk_work); 36 } 37 38 public ExprConstantImpl() throws RemoteException { 39 cnst = null; 40 loadCnst = null; 41 eok = new ExprOperKindImpl(ExprOperKind.eok_constant); 42 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Expression); 43 stKindImpl = new StateKindImpl(StateKind.sk_normal); 44 } 45 46 47 public DefinitionKind get_def_kind() throws RemoteException { 48 return (DefinitionKind) defKindImpl; 49 } 50 51 52 public StateKind get_state() throws RemoteException { 53 return (StateKind) stKindImpl; 54 } 55 56 public ConstantDef ref_const() throws RemoteException { 57 return cnst; 58 } 59 60 public ExprOperKind get_eok_kind() throws RemoteException { 61 return (ExprOperKind) eok; 62 } 63 64 public ExprOperDef calculate() throws RemoteException , TIRExceptCalculate { 65 return cnst.value().calculate(); 66 } 67 68 public void save(Storage st) throws RemoteException , TIRExceptStorage { 69 try { 70 st.curOutFile.writeInt(eok.value()); 71 Identification idl = ((Contained)cnst).get_identification(); 72 Storage.writeString(st.curOutFile, idl.lang_absolute_name().name()); 73 Storage.writeString(st.curOutFile, idl.name()); 74 Storage.writeString(st.curOutFile, idl.version()); 75 } catch (IOException e) { 76 throw new TIRExceptStorage("Can't write in directory "+st.current+"."); 77 } 78 } 79 80 public void load(Storage st) throws RemoteException , TIRExceptStorage { 81 try { 82 String absn = Storage.readString(st.curInFile); 83 String name = Storage.readString(st.curInFile); 84 String ver = Storage.readString(st.curInFile); 85 loadCnst = new NotYetInRep(absn,name,ver); 86 } catch (IOException e) { 87 throw new TIRExceptStorage("Can't read in directory "+st.current+"."); 88 } 89 } 90 91 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 92 try { 93 94 if ((loadCnst!=null) && (loadCnst.get_def_kind().value() == DefinitionKind.dk_none)) { AbsoluteName nm = ((NotYetInRep) loadCnst).nm; 96 Container con = r; Contained[] rt; 98 Contained ret; 99 IdentificationImpl id; 100 for (int i=0;i<nm.size()-1;i++) { id = new IdentificationImpl(nm.elementAt(0),"::"+nm.elementAt(i),""); 102 rt = ((SContainer)con).slookup_name(id); 103 if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name()); 104 if (rt.length==1) { 105 con = (Container) rt[0]; 106 } else { boolean found = false; 108 id.version(((NotYetInRep) loadCnst).id.version()); 109 int j = 0; 110 for (j=0;j<rt.length;j++) { 111 if (id.is_short_equal(rt[j].get_identification())) { 112 found = true; 113 break; } 115 } if (!found) throw new TIRExceptStorage("Can't find type " + nm.name()); 117 con = (Container) rt[j]; 118 } 119 } 120 if ((ret = ((SContainer)con).slookup(((NotYetInRep) loadCnst).id))==null) 121 throw new TIRExceptStorage("Can't find type " + nm.name()); 122 cnst = (ConstantDef) ret; 123 loadCnst = null; 124 } 125 126 } catch (TIRExceptLock e) {;} 127 } 128 129 public boolean isNew() { 130 return (stKindImpl.value()==StateKind.sk_work); 131 } 132 133 public void canCommit() throws RemoteException , TIRExceptCommit {;} 134 135 public void doCommit(Container in, Repository rep) throws RemoteException { 136 if (stKindImpl.value()==StateKind.sk_work) { 137 stKindImpl.toNormal(); 138 Identification idl = cnst.get_identification(); 139 loadCnst = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version()); 140 cnst = null; 141 } 142 } 143 144 public void doAbort(long workId) throws RemoteException {} 145 } 146 | Popular Tags |