1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.IOException ; 4 import java.rmi.RemoteException ; 5 6 import SOFA.SOFAnode.Made.TIR.AbsoluteName; 7 import SOFA.SOFAnode.Made.TIR.ArrayDef; 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.ExprOperDef; 13 import SOFA.SOFAnode.Made.TIR.FixedDef; 14 import SOFA.SOFAnode.Made.TIR.Identification; 15 import SOFA.SOFAnode.Made.TIR.PrimitiveDef; 16 import SOFA.SOFAnode.Made.TIR.Repository; 17 import SOFA.SOFAnode.Made.TIR.SequenceDef; 18 import SOFA.SOFAnode.Made.TIR.StateKind; 19 import SOFA.SOFAnode.Made.TIR.StringDef; 20 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 21 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 22 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 23 import SOFA.SOFAnode.Made.TIR.UnionMember; 24 import SOFA.SOFAnode.Made.TIR.WstringDef; 25 26 public class UnionMemberImpl extends ContainedImpl implements UnionMember, TIRImplObject { 27 CDLType tp; 28 ExprOperDef[] lab; 29 DefinitionKindImpl defKindImpl; 30 StateKindImpl stKindImpl; 31 32 UnionMemberImpl normal; 33 34 public UnionMemberImpl(Identification ident, Container in, Repository inrep, CDLType type, ExprOperDef[] label) throws RemoteException { 35 super(ident,in,inrep); 36 tp = type; 37 lab = label; 38 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_UnionMember); 39 stKindImpl = new StateKindImpl(StateKind.sk_work); 40 normal = null; 41 } 42 43 44 public UnionMemberImpl(Container in, Repository inrep) throws RemoteException { 45 super(null,in,inrep); 46 tp = null; 47 lab = null; 48 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_UnionMember); 49 stKindImpl = new StateKindImpl(StateKind.sk_normal); 50 normal = null; 51 } 52 53 public UnionMemberImpl(UnionMemberImpl a, Container in, Repository inrep) throws RemoteException { 54 super(a.id,in,inrep); 55 tp = a.tp; 56 lab = a.lab; 57 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_UnionMember); 58 stKindImpl = new StateKindImpl(StateKind.sk_work); 59 normal = a; 60 } 61 62 public String name() throws RemoteException { 63 return id.name(); 64 } 65 66 public CDLType type() throws RemoteException { 67 return tp; 68 } 69 70 public ExprOperDef[] label() throws RemoteException { 71 return lab; 72 } 73 74 75 public DefinitionKind get_def_kind() throws RemoteException { 76 return (DefinitionKind) defKindImpl; 77 } 78 79 80 public StateKind get_state() throws RemoteException { 81 return (StateKind) stKindImpl; 82 } 83 84 public void tag(String t) throws RemoteException , TIRExceptCreate, TIRExceptLock { 85 if (stKindImpl.value()!=StateKind.sk_work) 86 throw new TIRExceptCreate("you can call create method on work object"); 87 super.tag(t); 88 } 89 90 public void load(Storage st) throws RemoteException , TIRExceptStorage { 91 try { 92 id = new IdentificationImpl(); 93 ((IdentificationImpl)id).load(st.curInFile); 94 tp = Storage.readCDLType(st); 95 int len = st.curInFile.readInt(); 96 lab = new ExprOperDef [len]; 97 for (int i=0;i<len;i++) { 98 lab[i] = Storage.readExprOperDef(st); 99 } 100 } catch (IOException e) { 101 throw new TIRExceptStorage("Can't read in file "+st.currentFile+"."); 102 } 103 } 104 105 public void save(Storage st) throws RemoteException , TIRExceptStorage { 106 try { 107 ((IdentificationImpl)id).save(st.curOutFile); 108 Storage.writeCDLType(st,tp); 109 st.curOutFile.writeInt(lab.length); 110 for (int i=0;i<lab.length;i++) { 111 Storage.writeExprOperDef(st,lab[i]); 112 } 113 } catch (IOException e) { 114 throw new TIRExceptStorage("Can't write in file "+st.currentFile+"."); 115 } 116 } 117 118 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 119 try { 120 121 if (tp.get_def_kind().value() == DefinitionKind.dk_none) { if (((NotYetInRep) tp).defKind == DefinitionKind.dk_Primitive) 123 tp = r.get_prim(((NotYetInRep) tp).primKind); 124 else { AbsoluteName nm = ((NotYetInRep) tp).nm; 126 Container con = r; Contained[] rt; 128 Contained ret; 129 IdentificationImpl id; 130 for (int i=0;i<nm.size()-1;i++) { id = new IdentificationImpl(nm.elementAt(0),"::"+nm.elementAt(i),""); 132 rt = ((SContainer) con).slookup_name(id); 133 if (rt.length==0) throw new TIRExceptStorage("Can't find type " + nm.name()); 134 if (rt.length==1) { 135 con = (Container) rt[0]; 136 } else { boolean found = false; 138 id.version(((NotYetInRep) tp).id.version()); int j = 0; 140 for (j=0;j<rt.length;j++) { 141 if (id.is_short_equal(rt[j].get_identification())) { 142 found = true; 143 break; } 145 } if (!found) throw new TIRExceptStorage("Can't find type " + nm.name()); 147 con = (Container) rt[j]; 148 } 149 } 150 if ((ret = ((SContainer) con).slookup(((NotYetInRep) tp).id))==null) 151 throw new TIRExceptStorage("Can't find type " + nm.name()); 152 tp = (CDLType) ret; 153 if (tp.get_def_kind().value()==DefinitionKind.dk_Array || 154 tp.get_def_kind().value()==DefinitionKind.dk_Sequence || 155 tp.get_def_kind().value()==DefinitionKind.dk_String || 156 tp.get_def_kind().value()==DefinitionKind.dk_Wstring) 157 ((TIRImplObject) tp).postLoad(r); 158 } 159 } else { 160 if (tp.get_def_kind().value()==DefinitionKind.dk_Array || 161 tp.get_def_kind().value()==DefinitionKind.dk_Sequence || 162 tp.get_def_kind().value()==DefinitionKind.dk_String || 163 tp.get_def_kind().value()==DefinitionKind.dk_Wstring) 164 ((TIRImplObject) tp).postLoad(r); 165 } 166 for (int i=0;i<lab.length;i++) 167 ((TIRImplObject) lab[i]).postLoad(r); 168 169 } catch (TIRExceptLock e) {;} 170 } 171 172 public boolean isNew() { 173 return ((stKindImpl.value()==StateKind.sk_work) && normal==null); 174 } 175 176 public void canCommit() throws RemoteException , TIRExceptCommit {;} 177 178 public void doCommit(Container in, Repository rep) throws RemoteException { 179 if (stKindImpl.value()==StateKind.sk_normal) 180 return; 181 if (isNew()) { 182 stKindImpl.toNormal(); 183 switch (tp.get_def_kind().value()) { 184 case DefinitionKind.dk_Primitive: 185 tp = ((SRepository)rep).get_prim(((PrimitiveDef)tp).kind().value()); 186 break; 187 case DefinitionKind.dk_Array: 188 ArrayDef nt = new ArrayDefImpl(ExprHelp.toNormal(((ArrayDef) tp).length()), ((ArrayDef) tp).element_type()); 189 tp = nt; 190 ((TIRImplObject)tp).doCommit(in,rep); 191 break; 192 case DefinitionKind.dk_Sequence: 193 SequenceDef st = new SequenceDefImpl(ExprHelp.toNormal(((SequenceDef) tp).bound()), ((SequenceDef) tp).element_type()); 194 tp = st; 195 ((TIRImplObject)tp).doCommit(in,rep); 196 break; 197 case DefinitionKind.dk_String: 198 StringDef str = new StringDefImpl(ExprHelp.toNormal(((StringDef) tp).bound())); 199 tp = str; 200 ((TIRImplObject)tp).doCommit(in,rep); 201 break; 202 case DefinitionKind.dk_Wstring: 203 WstringDef wstr = new WstringDefImpl(ExprHelp.toNormal(((WstringDef) tp).bound())); 204 tp = wstr; 205 ((TIRImplObject)tp).doCommit(in,rep); 206 break; 207 case DefinitionKind.dk_Fixed: 208 FixedDef ft = new FixedDefImpl(ExprHelp.toNormal(((FixedDef) tp).digits()), ExprHelp.toNormal(((FixedDef) tp).scale())); 209 tp = ft; 210 ((TIRImplObject)tp).doCommit(in,rep); 211 break; 212 default: 213 Identification idl = ((Contained)tp).get_identification(); 214 tp = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version()); 215 break; 216 } 217 for (int i=0;i<lab.length;i++) { 218 lab[i] = ExprHelp.toNormal(lab[i]); 219 ((TIRImplObject)lab[i]).doCommit(in,rep); 220 } 221 } else { 222 normal=null; 223 } 224 } 225 226 public void doAbort(long workId) throws RemoteException {} 227 } 228 | Popular Tags |