KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CDL > CompUnion


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