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