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