KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > IDL3 > UnionMembersImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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, Mathieu Vadet.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.IDL3;
28
29 /**
30  * This class manages IDL union members.
31  *
32  * @author <a=href="Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a=href="Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class UnionMembersImpl
39        implements UnionMembers
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /**
48      ** List of members names.
49      **/

50     private org.objectweb.ccm.util.Vector member_names_;
51
52     /**
53      ** List of members TypeRef.
54      **/

55     private org.objectweb.ccm.util.Vector member_types_;
56
57     /**
58      **
59      **/

60     private org.objectweb.ccm.util.Vector member_values_;
61
62     /**
63      **
64      **/

65     private TypeRef discriminator_;
66
67     // ==================================================================
68
//
69
// Constructor.
70
//
71
// ==================================================================
72

73     /**
74      ** The default constructor.
75      **/

76     public
77     UnionMembersImpl()
78     {
79         // Init internal state.
80
member_names_ = new org.objectweb.ccm.util.Vector();
81         member_types_ = new org.objectweb.ccm.util.Vector();
82         member_values_ = new org.objectweb.ccm.util.Vector();
83         discriminator_ = null;
84     }
85
86     // ==================================================================
87
//
88
// Internal methods.
89
//
90
// ==================================================================
91

92     /**
93      ** Obtain its UnionMember[].
94      **
95      ** @return An array containing the union members.
96      **/

97     protected org.omg.CORBA.UnionMember JavaDoc[]
98     getMemberDefs()
99     {
100         org.omg.CORBA.UnionMember JavaDoc[] result =
101             new org.omg.CORBA.UnionMember JavaDoc[member_names_.size()];
102
103         for(int i=0; i<result.length; i++)
104         {
105             result[i] = new org.omg.CORBA.UnionMember JavaDoc(
106                 (String JavaDoc)member_names_.get(i),
107                 ((AnyValue)member_values_.get(i)).computeAny(discriminator_.getIDLType().type()),
108                 org.objectweb.openccm.corba.TypeCodeUtils.getTC_void(),
109                 ((TypeRef)member_types_.get(i)).getIDLType());
110         }
111
112         return result;
113     }
114
115     /**
116      **
117      **/

118     protected void
119     destroy()
120     {
121         if (discriminator_!=null)
122             discriminator_.removeRef();
123
124         for (int i=0;i<member_types_.size();i++)
125         {
126             ((TypeRef)member_types_.get(i)).removeRef();
127         }
128     }
129
130     // ==================================================================
131
//
132
// Methods for the StructMembers interface.
133
//
134
// ==================================================================
135

136     /**
137      ** Add a member.
138      **
139      ** @param name The name of the member.
140      ** @param type The TypeRef of the member.
141      **/

142     public void
143     addMember(String JavaDoc name,
144               TypeRef type,
145               AnyValue value)
146     {
147         if ((type != null) && (name!=null) && (value!=null))
148         {
149             member_names_.add(name);
150             type.addRef();
151             member_types_.add(type);
152             member_values_.add(value);
153         }
154     }
155
156     /**
157      **
158      **/

159     public void
160     setDiscriminator(TypeRef type)
161     {
162         if (type!=null)
163         {
164             discriminator_ = type;
165             discriminator_.addRef();
166         }
167     }
168
169     /**
170      **
171      **/

172     public TypeRef
173     getDiscriminator()
174     {
175         return discriminator_;
176     }
177
178     /**
179      **
180      **/

181     public String JavaDoc[]
182     getMemberNames()
183     {
184         String JavaDoc[] result = new String JavaDoc[member_names_.size()];
185         for (int i=0;i<result.length;i++)
186         {
187             result[i] = (String JavaDoc)member_names_.get(i);
188         }
189         return result;
190     }
191
192     /**
193      **
194      **/

195     public TypeRef[]
196     getMemberTypes()
197     {
198         TypeRef[] result = new TypeRef[member_types_.size()];
199         for (int i=0;i<result.length;i++)
200         {
201             result[i] = (TypeRef)member_types_.get(i);
202         }
203         return result;
204     }
205
206     /**
207      **
208      **/

209     public AnyValue[]
210     getMemberValues()
211     {
212         AnyValue[] result = new AnyValue[member_values_.size()];
213         for (int i=0;i<result.length;i++)
214         {
215             result[i] = (AnyValue)member_values_.get(i);
216         }
217         return result;
218     }
219 }
220
Popular Tags