KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > lib > EnumDeclImpl


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, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.lib;
28
29 /** Used to access AST AnyValue. */
30 import org.objectweb.openccm.ast.api.AnyValue;
31
32 /** Used to access AST TypeKind. */
33 import org.objectweb.openccm.ast.api.TypeKind;
34
35 /** Used to access AST DeclarationKind. */
36 import org.objectweb.openccm.ast.api.DeclarationKind;
37
38 /** Used to access AST StringList. */
39 import org.objectweb.openccm.ast.api.StringList;
40
41 /** To use CORBA::EnumDef. */
42 import org.omg.CORBA.EnumDef JavaDoc;
43 import org.omg.CORBA.EnumDefHelper;
44
45 /**
46  * EnumDeclImpl is a wrapper class for IDL enum declarations.
47  *
48  *
49  *
50  * Inherits from:
51  *
52  * - DeclarationImpl as enums are IDL declarations,
53  *
54  * - EnumDecl: OMG IDL for enum declarations.
55  *
56  * - IDLTypeWrapper as enums are IDL types.
57  *
58  *
59  * Provides:
60  *
61  * - The list of enum members,
62  * i.e. the getMemberList operation.
63  *
64  *
65  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
66  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
67  *
68  * @version 0.3
69  */

70
71 public class EnumDeclImpl
72        extends DeclarationImpl
73        implements org.objectweb.openccm.ast.api.EnumDecl,
74                   IDLTypeWrapper
75 {
76     // ==================================================================
77
//
78
// Internal state.
79
//
80
// ==================================================================
81

82     /** Reference to the CORBA 3.0 EnumDef. */
83     private EnumDef JavaDoc enum_def_;
84
85     /** List of members names. */
86     private StringListImpl members_;
87
88     // ==================================================================
89
//
90
// Constructor.
91
//
92
// ==================================================================
93

94     /**
95      * The constructor with the parent scope.
96      *
97      * @param rep The repository of the declaration.
98      * @param parent The parent scope of the declaration.
99      */

100     protected
101     EnumDeclImpl(Repository rep,
102                  ScopeImpl parent)
103     {
104         // Call the DeclarationImpl constructor.
105
super(rep, parent);
106
107         // Init internal state.
108
enum_def_ = null;
109         members_ = new StringListImpl();
110     }
111
112     // ==================================================================
113
//
114
// Internal methods.
115
//
116
// ==================================================================
117

118     // ==================================================================
119
//
120
// Internal methods for DeclarationImpl.
121
//
122
// ==================================================================
123

124     /**
125      * Loads infos of the CORBA 3.0 EnumDef.
126      *
127      * @param contained The EnumDef to load.
128      */

129     protected void
130     load(org.omg.CORBA.Contained JavaDoc contained)
131     {
132         enum_def_ = EnumDefHelper.narrow(contained);
133         String JavaDoc[] members = enum_def_.members();
134         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
135         for (int i=0; i<members.length; i++)
136         {
137             members_.add(members[i]);
138             DeclarationWithAnyValueImpl decl = new DeclarationWithAnyValueImpl(getRepository(), the_parent_);
139             decl.setName(members[i]);
140             AnyValue av = new AnyValueImpl();
141             av.setAsEnum(enumTC, i, members[i]);
142             decl.setAnyValue(av);
143             decl.create();
144         }
145         super.load(contained);
146     }
147
148     /**
149      * Loads infos of the CORBA 3.0 EnumDef.
150      *
151      * @param contained The EnumDef to load.
152      */

153     protected void
154     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
155     {
156         enum_def_ = EnumDefHelper.narrow(contained);
157         String JavaDoc[] members = enum_def_.members();
158         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
159         for (int i=0;i<members.length;i++)
160         {
161             members_.add(members[i]);
162             DeclarationWithAnyValueImpl decl = new DeclarationWithAnyValueImpl(getRepository(), the_parent_);
163             decl.setName(members[i]);
164             AnyValue av = new AnyValueImpl();
165             av.setAsEnum(enumTC, i, members[i]);
166             decl.setAnyValue(av);
167             decl.create();
168         }
169
170         super.loadAsMapping(contained);
171     }
172
173     /**
174      * Obtain its CORBA 3.0 Contained reference.
175      *
176      * @return The Contained object associated with the enum declaration.
177      */

178     protected org.omg.CORBA.Contained JavaDoc
179     getContained()
180     {
181        return enum_def_;
182     }
183
184     // ==================================================================
185
//
186
// Public methods.
187
//
188
// ==================================================================
189

190     // ==================================================================
191
//
192
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDeclarators
193
//
194
// ==================================================================
195

196     /**
197      * Find the declarator associated to an index.
198      *
199      * @param index The index of the element.
200      *
201      * @return The enumeration symbolic name of the element
202      * at the specified index.
203      */

204     public String JavaDoc
205     declaratorAt(int index)
206     {
207         return (String JavaDoc)members_.get(index);
208     }
209
210     // ==================================================================
211
//
212
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
213
//
214
// ==================================================================
215

216     // ==================================================================
217
//
218
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
219
//
220
// ==================================================================
221

222     /**
223      * Obtain its DeclarationKind.
224      *
225      * @return The DeclarationKind of the object.
226      */

227     public long
228     getDeclKind()
229     {
230         return DeclarationKind.dk_enum;
231     }
232
233     /**
234      * Create the enum declaration.
235      */

236     public void
237     create()
238     {
239         String JavaDoc[] members = members_.getStrings();
240
241         enum_def_ = the_parent_.getContainer().
242                     create_enum(getId(), getName(), getVersion(), members);
243
244         org.omg.CORBA.TypeCode JavaDoc enumTC = enum_def_.type();
245         for(int i=0; i<members_.getSize(); i++)
246         {
247             String JavaDoc name = (String JavaDoc)members_.get(i);
248             DeclarationWithAnyValueImpl decl = new DeclarationWithAnyValueImpl(getRepository(), the_parent_);
249             decl.setName(name);
250             AnyValue av = new AnyValueImpl();
251             av.setAsEnum(enumTC, i, name);
252             decl.setAnyValue(av);
253             decl.create();
254         }
255
256         super.create();
257     }
258
259     // ==================================================================
260
//
261
// Methods for OMG IDL org.objectweb.openccm.ast.api.TypeRef
262
//
263
// ==================================================================
264

265     /**
266      * Obtain its associated TypeKind.
267      *
268      * @return The associated TypeKind.
269      */

270     public TypeKind
271     getTypeKind()
272     {
273         return TypeKind.tk_enum;
274     }
275
276     // ==================================================================
277
//
278
// Methods for OMG IDL org.objectweb.openccm.ast.api.EnumDecl
279
//
280
// ==================================================================
281

282     /**
283      * Obtain the list of members.
284      *
285      * @return The list of members.
286      */

287     public StringList
288     getMemberList()
289     {
290         return members_;
291     }
292
293     // ==================================================================
294
//
295
// Methods for interface IDLTypeWrapper
296
//
297
// ==================================================================
298

299     /**
300      * Obtain its IDLType reference.
301      *
302      * @return The IDLType associated with the type reference.
303      */

304     public org.omg.CORBA.IDLType JavaDoc
305     getIDLType()
306     {
307         return enum_def_;
308     }
309 }
310
Popular Tags