1 2 package SOFA.SOFAnode.Made.CDL; 3 import java.rmi.RemoteException ; 4 5 import SOFA.SOFAnode.Made.TIR.CDLRepository; 6 import SOFA.SOFAnode.Made.TIR.CDLType; 7 import SOFA.SOFAnode.Made.TIR.Contained; 8 import SOFA.SOFAnode.Made.TIR.Container; 9 import SOFA.SOFAnode.Made.TIR.EnumDef; 10 import SOFA.SOFAnode.Made.TIR.StructDef; 11 import SOFA.SOFAnode.Made.TIR.StructMember; 12 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 13 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 14 import SOFA.SOFAnode.Made.TIR.UnionDef; 15 16 class CompStruct extends CompContainedContainerIm implements CompType { 17 public CompStruct(ID id, CompContainer in, CompRepository inRep) { 18 super(ObjectsKind.o_Struct, id, in, inRep); 19 } 20 21 public static boolean canBeDefIn(CompType type) { 22 switch (type.objectKind()) { 23 case ObjectsKind.o_Struct: 24 case ObjectsKind.o_Enum: 25 case ObjectsKind.o_Union: 26 return true; 27 default: return false; 28 } 29 } 30 31 public boolean addObject(CompContained o) { 32 ((CompContained) o).getIdent().version = id.version; 33 return super.addObject(o); 34 } 35 36 public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote { 37 CompContained[] cont = contents(); 38 for (int i=0;i<cont.length;i++) { 39 cont[i].checkConsist(props, rep); 40 } 41 } 42 43 public void addToNormal(Container obj, CDLRepository normRep, java.util.ArrayList delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock { 44 if (id.isin == IDKind.versiontag) { 45 try { 46 ((Contained)obj).tag(id.tag); 47 } catch (RemoteException e) { 48 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 49 } catch (TIRExceptLock e) { 50 throw new CDLExceptLock("Repository is locked."); 51 } catch (TIRExceptCreate ecr) { 52 throw new CDLExceptToNormal("Can't set tag for "+ fullName()); 53 } 54 } 55 cont.toFirst(); 56 try { 57 for (int i=0;i<cont.size(); i++) { 58 CompContained akt = (CompContained) cont.aktual(); 59 switch (akt.objectKind()) { 60 case ObjectsKind.o_Struct: 62 try { 63 StructDef str = ((StructDef) obj).create_struct(akt.getIdent().id); 64 if (str == null) 65 throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName()); 66 ((CompStruct) akt).addToNormal(str, normRep, delayed); 67 } catch (TIRExceptCreate ecr) { 68 throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName()); 69 } 70 break; 71 case ObjectsKind.o_StructMember: 73 try { 74 StructMember mem = ((StructDef) obj).create_member(akt.getIdent().name, ((CompStructMember)akt).tp.toNormal(normRep)); 75 if (mem == null) 76 throw new CDLExceptToNormal("Can't create struct member "+((CompContained)akt).fullName()); 77 } catch (TIRExceptCreate ecr) { 78 throw new CDLExceptToNormal("Can't create struct member "+((CompContained)akt).fullName()+"\n"+ecr.getMessage()); 79 } 80 break; 81 case ObjectsKind.o_Enum: 83 try { 84 EnumDef en = ((StructDef) obj).create_enum(akt.getIdent().id); 85 if (en == null) 86 throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName()); 87 ((CompEnum) akt).addToNormal(en); 88 } catch (TIRExceptCreate ecr) { 89 throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName()); 90 } 91 break; 92 case ObjectsKind.o_Union: 94 try { 95 UnionDef un = ((StructDef) obj).create_union(akt.getIdent().id, ((CompUnion) akt).switch_type.toNormal(normRep)); 96 if (un == null) 97 throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName()); 98 ((CompUnion) akt).addToNormal(un, normRep, delayed); 99 } catch (TIRExceptCreate ecr) { 100 throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName()); 101 } 102 break; 103 104 default: 105 throw new CDLExceptToNormal("Unexcepted kind of object"); 106 } 107 cont.toNext(); 108 } 109 } catch (RemoteException e) { 110 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 111 } catch (TIRExceptLock e) { 112 throw new CDLExceptLock("Repository is locked."); 113 } 114 } 115 116 117 public CDLType toNormal(CDLRepository newRep) throws CDLExceptToNormal { 118 throw new CDLExceptToNormal("It should never throw"); 120 } 121 } 122 | Popular Tags |