KickJava   Java API By Example, From Geeks To Geeks.

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


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 enum declarations.
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 EnumDeclImpl
39        extends DeclarationImpl
40        implements TypeRef, EnumDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /**
49      ** Reference to the CORBA 3.0 EnumDef.
50      **/

51     private org.omg.CORBA.EnumDef JavaDoc enum_def_;
52
53     /**
54      ** List of members names.
55      **/

56     private org.objectweb.ccm.util.Vector members_;
57
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ==================================================================
63

64     /**
65      ** The constructor with the parent scope.
66      **
67      ** @param parent The parent scope of the declaration.
68      **/

69     protected
70     EnumDeclImpl(Repository rep, ScopeImpl parent)
71     {
72         // Call the DeclarationImpl constructor.
73
super(rep, parent);
74
75         // Init internal state.
76
enum_def_ = null;
77         members_ = new org.objectweb.ccm.util.Vector();
78         the_declaration_kind_ = DeclarationKind._dk_enum;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      ** Loads infos of the CORBA 3.0 EnumDef.
89      **
90      ** @param enum_def The EnumDef to load.
91      **/

92     protected void
93     load(org.omg.CORBA.Contained JavaDoc contained)
94     {
95         enum_def_ = org.omg.CORBA.EnumDefHelper.narrow(contained);
96         String JavaDoc[] members = enum_def_.members();
97         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
98         for (int i=0;i<members.length;i++)
99         {
100             addMember(members[i]);
101             AnyValueDeclImpl decl = new AnyValueDeclImpl(getRepository(), the_parent_);
102             decl.setName(members[i]);
103             AnyValue av = new AnyValue();
104             av.setAsEnum(enumTC, i, members[i]);
105             decl.setAnyValue(av);
106             decl.create();
107         }
108         super.load(contained);
109     }
110
111     /**
112      ** Loads infos of the CORBA 3.0 EnumDef.
113      **
114      ** @param enum_def The EnumDef to load.
115      **/

116     protected void
117     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
118     {
119         enum_def_ = org.omg.CORBA.EnumDefHelper.narrow(contained);
120         String JavaDoc[] members = enum_def_.members();
121         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
122         for (int i=0;i<members.length;i++)
123         {
124             addMember(members[i]);
125             AnyValueDeclImpl decl = new AnyValueDeclImpl(getRepository(), the_parent_);
126             decl.setName(members[i]);
127             AnyValue av = new AnyValue();
128             av.setAsEnum(enumTC, i, members[i]);
129             decl.setAnyValue(av);
130             decl.create();
131         }
132
133         super.loadAsMapping(contained);
134     }
135
136     // ==================================================================
137
//
138
// Methods for the Declaration interface.
139
//
140
// ==================================================================
141

142     /**
143      ** Create the enum declaration.
144      **/

145     public void
146     create()
147     {
148         String JavaDoc[] members = new String JavaDoc[members_.size()];
149         for(int i=0; i<members.length; i++)
150             members[i] = (String JavaDoc)(members_.get(i));
151
152         enum_def_ = the_parent_.getContainer().create_enum(getId(), getName(),
153                                                            getVersion(), members);
154
155         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
156         for(int i=0; i<members_.size(); i++)
157         {
158             String JavaDoc name = (String JavaDoc)members_.get(i);
159             AnyValueDeclImpl decl = new AnyValueDeclImpl(getRepository(), the_parent_);
160             decl.setName(name);
161             AnyValue av = new AnyValue();
162             av.setAsEnum(enumTC, i, name);
163             decl.setAnyValue(av);
164             decl.create();
165         }
166
167         super.create();
168     }
169
170     /**
171      ** Return the index declarator.
172      **
173      ** @param index The index of the element.
174      **
175      ** @return The enumeration symbolic name of the element
176      ** at the specified index.
177      **/

178     public String JavaDoc
179     declaratorAt(int index)
180     {
181         return (String JavaDoc)members_.get(index);
182     }
183
184     // ==================================================================
185
//
186
// Methods for the TypeRef interface.
187
//
188
// ==================================================================
189

190     /**
191      ** Obtain its IDLType reference.
192      **
193      ** @return The IDLType associated with the declaration.
194      **/

195     public org.omg.CORBA.IDLType JavaDoc
196     getIDLType()
197     {
198         return enum_def_;
199     }
200
201     /**
202      **
203      **/

204     public int
205     getTypeKind()
206     {
207         return TypeKind._tk_enum;
208     }
209
210     // ==================================================================
211
//
212
// Methods for the EnumDecl interface.
213
//
214
// ==================================================================
215

216     /**
217      ** Add a member name.
218      **
219      ** @param name The name of the member.
220      **/

221     public void
222     addMember(String JavaDoc name)
223     {
224         members_.add(name);
225     }
226
227     /**
228      **
229      **/

230     public String JavaDoc[]
231     getMembers()
232     {
233         String JavaDoc[] result = new String JavaDoc[members_.size()];
234         for (int i=0;i<result.length;i++)
235         {
236             result[i] = (String JavaDoc)members_.get(i);
237         }
238         return result;
239     }
240
241     // ==================================================================
242
//
243
// Methods for the inherited DeclarationImpl class.
244
//
245
// ==================================================================
246

247     /**
248      ** Obtain its CORBA 3.0 Contained reference.
249      **
250      ** @return The Contained object associated with the enum declaration.
251      **/

252     protected org.omg.CORBA.Contained JavaDoc
253     getContained()
254     {
255        return enum_def_;
256     }
257 }
258
Popular Tags