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.ArrayDef; 9 import SOFA.SOFAnode.Made.TIR.CDLType; 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.ExprOperDef; 14 import SOFA.SOFAnode.Made.TIR.FixedDef; 15 import SOFA.SOFAnode.Made.TIR.Identification; 16 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 17 import SOFA.SOFAnode.Made.TIR.Repository; 18 import SOFA.SOFAnode.Made.TIR.SequenceDef; 19 import SOFA.SOFAnode.Made.TIR.StateKind; 20 import SOFA.SOFAnode.Made.TIR.StringDef; 21 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 22 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 23 import SOFA.SOFAnode.Made.TIR.WstringDef; 24 25 public class SequenceDefImpl extends UnicastRemoteObject implements SequenceDef, TIRImplObject { 26 ExprOperDef bd; 27 CDLType tp; 28 DefinitionKindImpl defKindImpl; 29 StateKindImpl stKindImpl; 30 31 public SequenceDefImpl(ExprOperDef bound, CDLType type) throws RemoteException { 32 bd = bound; 33 tp = type; 34 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Sequence); 35 stKindImpl = new StateKindImpl(StateKind.sk_work); 36 } 37 38 public SequenceDefImpl() throws RemoteException { 39 bd = null; 40 tp = null; 41 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Sequence); 42 stKindImpl = new StateKindImpl(StateKind.sk_normal); 43 } 44 45 public ExprOperDef bound() throws RemoteException { 46 return bd; 47 } 48 49 public CDLType element_type() throws RemoteException { 50 return tp; 51 } 52 53 54 public DefinitionKind get_def_kind() throws RemoteException { 55 return (DefinitionKind) defKindImpl; 56 } 57 58 59 public StateKind get_state() throws RemoteException { 60 return (StateKind) stKindImpl; 61 } 62 63 64 65 public void load(Storage st) throws RemoteException , TIRExceptStorage { 66 try { 67 tp = Storage.readCDLType(st); 68 bd = Storage.readExprOperDef(st); 69 } catch (IOException e) { 70 throw new TIRExceptStorage("Can't read in file "+st.currentFile+"."); 71 } 72 } 73 74 75 public void save(Storage st) throws RemoteException , TIRExceptStorage { 76 try { 77 Storage.writeCDLType(st, tp); 78 Storage.writeExprOperDef(st,bd); 79 } catch (IOException e) { 80 throw new TIRExceptStorage("Can't write in file "+st.currentFile+"."); 81 } 82 } 83 84 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 85 try { 86 87 if (tp.get_def_kind().value() == DefinitionKind.dk_none) { if (((NotYetInRep) tp).defKind == DefinitionKind.dk_Primitive) 89 tp = r.get_prim(((NotYetInRep) tp).primKind); 90 else { AbsoluteName nm = ((NotYetInRep) tp).nm; 92 Container con = r; Contained[] rt; 94 Contained ret; 95 IdentificationImpl id; 96 for (int i=0;i<nm.size()-1;i++) { id = new IdentificationImpl(nm.elementAt(0), "::"+nm.elementAt(i),""); 98 rt = ((SContainer)con).slookup_name(id); 99 if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name()); 100 if (rt.length==1) { 101 con = (Container) rt[0]; 102 } else { boolean found = false; 104 id.version(((NotYetInRep) tp).id.version()); int j = 0; 106 for (j=0;j<rt.length;j++) { 107 if (id.is_short_equal(rt[j].get_identification())) { 108 found = true; 109 break; } 111 } if (!found) throw new TIRExceptStorage("Can't find type " + nm.name()); 113 con = (Container) rt[j]; 114 } 115 } 116 if ((ret = ((SContainer)con).slookup(((NotYetInRep) tp).id))==null) 117 throw new TIRExceptStorage("Can't find type " + nm.name()); 118 tp = (CDLType) ret; 119 if (tp.get_def_kind().value()==DefinitionKind.dk_Array || 120 tp.get_def_kind().value()==DefinitionKind.dk_Sequence || 121 tp.get_def_kind().value()==DefinitionKind.dk_String || 122 tp.get_def_kind().value()==DefinitionKind.dk_Wstring) 123 ((TIRImplObject) tp).postLoad(r); 124 } 125 } else { 126 if (tp.get_def_kind().value()==DefinitionKind.dk_Array || 127 tp.get_def_kind().value()==DefinitionKind.dk_Sequence || 128 tp.get_def_kind().value()==DefinitionKind.dk_String || 129 tp.get_def_kind().value()==DefinitionKind.dk_Wstring) 130 ((TIRImplObject) tp).postLoad(r); 131 } 132 ((TIRImplObject) bd).postLoad(r); 133 134 } catch (TIRExceptLock e) {;} 135 } 136 137 public boolean isNew() { 138 return (stKindImpl.value()==StateKind.sk_work); 139 } 140 141 public void canCommit() throws RemoteException , TIRExceptCommit {;} 142 143 public void doCommit(Container in, Repository rep) throws RemoteException { 144 if (stKindImpl.value()==StateKind.sk_normal) 145 return; 146 if (isNew()) { 147 stKindImpl.toNormal(); 148 ((TIRImplObject)bd).doCommit(in,rep); 149 switch (tp.get_def_kind().value()) { 150 case DefinitionKind.dk_Primitive: 151 tp = ((SRepository)rep).get_prim(((PrimitiveDef)tp).kind().value()); 152 break; 153 case DefinitionKind.dk_Array: 154 ArrayDef nt = new ArrayDefImpl(ExprHelp.toNormal(((ArrayDef) tp).length()), ((ArrayDef) tp).element_type()); 155 tp = nt; 156 ((TIRImplObject)tp).doCommit(in,rep); 157 break; 158 case DefinitionKind.dk_Sequence: 159 SequenceDef st = new SequenceDefImpl(ExprHelp.toNormal(((SequenceDef) tp).bound()), ((SequenceDef) tp).element_type()); 160 tp = st; 161 ((TIRImplObject)tp).doCommit(in,rep); 162 break; 163 case DefinitionKind.dk_String: 164 StringDef str = new StringDefImpl(ExprHelp.toNormal(((StringDef) tp).bound())); 165 tp = str; 166 ((TIRImplObject)tp).doCommit(in,rep); 167 break; 168 case DefinitionKind.dk_Wstring: 169 WstringDef wstr = new WstringDefImpl(ExprHelp.toNormal(((WstringDef) tp).bound())); 170 tp = wstr; 171 ((TIRImplObject)tp).doCommit(in,rep); 172 break; 173 case DefinitionKind.dk_Fixed: 174 FixedDef ft = new FixedDefImpl(ExprHelp.toNormal(((FixedDef) tp).digits()), ExprHelp.toNormal(((FixedDef) tp).scale())); 175 tp = ft; 176 ((TIRImplObject)tp).doCommit(in,rep); 177 break; 178 default: 179 Identification idl = ((Contained)tp).get_identification(); 180 tp = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version()); 181 break; 182 } 183 } 184 } 185 186 public void doAbort(long workId) throws RemoteException {} 187 } 188 | Popular Tags |