KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > UnionMembers


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.*;
31
32 /**
33  * Implementation of the CORBA::UnionMemberSeq helper class.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.4
39  */

40
41 public class UnionMembers
42      extends Members
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50    /** The members labels. */
51     protected Any[] labels_;
52
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

59     /** TODO */
60     public
61     UnionMembers(UnionDef_impl owner)
62     {
63         super(owner, owner);
64
65         // Inits internal state.
66
labels_ = null;
67     }
68
69     // ==================================================================
70
//
71
// Public methods.
72
//
73
// ==================================================================
74

75     /**
76      * Obtain as CORBA::UnionMemberSeq
77      */

78     public UnionMember[]
79     getUnionMemberSeq(java.util.List JavaDoc idSeq)
80     {
81         UnionMember[] result = new UnionMember[names_.length];
82
83         for(int i=0; i<result.length; i++)
84     {
85             result[i] = new UnionMember();
86             result[i].name = names_[i];
87             result[i].label = labels_[i];
88             // recompute the typecode of each member.
89
result[i].type = types_[i].recursiveType(idSeq);
90             result[i].type_def = types_[i].asIDLType();
91     }
92
93         return result;
94     }
95
96     /**
97      * Obtain as CORBA::UnionMemberSeq
98      */

99     public UnionMember[]
100     getUnionMemberSeq()
101     {
102         UnionMember[] result = new UnionMember[names_.length];
103         java.util.List JavaDoc idSeq = new java.util.ArrayList JavaDoc();
104
105         for(int i=0; i<result.length; i++)
106     {
107             idSeq.clear();
108             result[i] = new UnionMember();
109             result[i].name = names_[i];
110             result[i].label = labels_[i];
111             // recompute the typecode of each member.
112
result[i].type = types_[i].recursiveType(idSeq);
113             result[i].type_def = types_[i].asIDLType();
114     }
115
116         return result;
117     }
118
119     /**
120      * Set as CORBA::UnionMemberSeq
121      */

122     public void
123     setUnionMemberSeq(UnionMember[] val)
124     {
125         // TODO checks members type and label.
126

127         // duplicates members names.
128
String JavaDoc[] names = new String JavaDoc[val.length];
129         for (int i=0; i<val.length; i++)
130             names[i] = val[i].name;
131
132         for(int i=0; i<names.length; i++)
133         {
134             String JavaDoc name = names[i];
135
136             container_.checkName(name, false, false);
137
138             if (name.equalsIgnoreCase(contained_.name()))
139                 contained_.exceptionNameAlreadyUsedByImmediateScope(name);
140         }
141
142         // duplicates members labels.
143
Any[] labels = new Any[val.length];
144         for (int i=0; i<val.length; i++)
145             labels[i] = val[i].label;
146
147         IRObject_impl[] types = new IRObject_impl[val.length];
148         for (int i=0; i<val.length; i++)
149             types[i] = contained_.castToLocal(val[i].type_def);
150
151         IDLType_ref[] refs = new IDLType_ref[val.length];
152         for (int i=0; i<val.length; i++)
153             refs[i] = new IDLType_ref( container_, types[i] );
154
155         labels_ = labels;
156         super.setNamesTypes(names, refs);
157     }
158 }
159
Popular Tags