KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** To access AST TypeRef. */
30 import org.objectweb.openccm.ast.api.TypeRef;
31
32 /** To access AST TypeKind. */
33 import org.objectweb.openccm.ast.api.TypeKind;
34
35 /** To access AST DeclarationKind. */
36 import org.objectweb.openccm.ast.api.DeclarationKind;
37
38 /** To access AST Declaration. */
39 import org.objectweb.openccm.ast.api.Declaration;
40
41 /** To access AST StructMember. */
42 import org.objectweb.openccm.ast.api.StructMember;
43
44 /** To access AST StructMemberList. */
45 import org.objectweb.openccm.ast.api.StructMemberList;
46
47 /** To use CORBA::StructDef. */
48 import org.omg.CORBA.StructDef JavaDoc;
49 import org.omg.CORBA.StructDefHelper;
50
51 /**
52  * StructDeclImpl is a wrapper class for IDL struct declarations.
53  *
54  * Inherits from:
55  * - ForwardScopeIDLImpl as structs are also IDL forward scopes.
56  * - TypeRef as structs are IDL types,
57  * - WithDeclarators to access struct members
58  * - IDLTypeWrapper as structs are IDL types.
59  *
60  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
61  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
62  *
63  * @version 0.3
64  */

65
66 public class StructDeclImpl
67      extends ForwardScopeIDLImpl
68   implements org.objectweb.openccm.ast.api.StructDecl,
69              IDLTypeWrapper
70 {
71     // ==================================================================
72
//
73
// Internal state.
74
//
75
// ==================================================================
76

77     /** Reference to the CORBA 3.0 StructDef. */
78     protected StructDef JavaDoc struct_def_;
79
80     /** List of members. */
81     protected StructMemberListImpl members_;
82
83     // ==================================================================
84
//
85
// Constructor.
86
//
87
// ==================================================================
88

89     /**
90      * The constructor with the parent scope.
91      *
92      * @param rep The repository of the declaration.
93      * @param parent The parent scope of the declaration.
94      */

95     protected
96     StructDeclImpl(Repository rep,
97                    ScopeImpl parent)
98     {
99         // Call the ForwardScopeIDLImpl constructor.
100
super(rep, parent);
101
102         // Init internal state.
103
struct_def_ = null;
104         members_ = new StructMemberListImpl();
105     }
106
107     // ==================================================================
108
//
109
// Internal methods.
110
//
111
// ==================================================================
112

113     // ==================================================================
114
//
115
// Internal methods for DeclarationImpl.
116
//
117
// ==================================================================
118

119     /**
120      * Loads infos of the CORBA 3.0 StructDef.
121      *
122      * @param contained The StructDef to load.
123      */

124     protected void
125     load(org.omg.CORBA.Contained JavaDoc contained)
126     {
127         struct_def_ = StructDefHelper.narrow(contained);
128         org.omg.CORBA.StructMember JavaDoc[] members = struct_def_.members();
129
130         // load as scope now to prevent infinite loop in the case
131
// of recursive struct.
132
super.load(contained);
133
134         for (int i=0;i<members.length;i++)
135             members_.addMember(members[i].name,
136                                getRepository().
137                                    getAsTypeRef(members[i].type_def));
138     }
139
140     /**
141      * Loads infos of the CORBA 3.0 StructDef.
142      *
143      * @param contained The StructDef to load.
144      */

145     protected void
146     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
147     {
148         struct_def_ = StructDefHelper.narrow(contained);
149         org.omg.CORBA.StructMember JavaDoc[] members = struct_def_.members();
150
151         // load as scope now to prevent infinite loop in the case
152
// of recursive struct.
153
super.loadAsMapping(contained);
154
155         for (int i=0;i<members.length;i++)
156             members_.addMember(members[i].name,
157                                getRepository().
158                                  getAsMappedTypeRef(members[i].type_def));
159     }
160
161     /**
162      * Obtain its CORBA 3.0 Contained reference.
163      *
164      * @return The Contained object associated with the struct declaration.
165      */

166     protected org.omg.CORBA.Contained JavaDoc
167     getContained()
168     {
169         return struct_def_;
170     }
171
172     // ==================================================================
173
//
174
// Internal methods for ScopeImpl.
175
//
176
// ==================================================================
177

178     /**
179      * Obtain its CORBA 3.0 Container reference.
180      *
181      * @return The Container object associated with the struct declaration.
182      */

183     protected org.omg.CORBA.Container JavaDoc
184     getContainer()
185     {
186         return struct_def_;
187     }
188
189     // ==================================================================
190
//
191
// Internal methods for ForwardScopeImpl.
192
//
193
// ==================================================================
194

195     // ==================================================================
196
//
197
// Internal methods for ForwardScopeIDLImpl.
198
//
199
// ==================================================================
200

201     /**
202      * Create the container object.
203      */

204     protected void
205     createContainer()
206     {
207         struct_def_ = the_parent_.getContainer().
208                      create_struct(getId(), getName(), getVersion(),
209                                    members_.getStructMemberSeq());
210     }
211
212     /**
213      * Complete the container object.
214      */

215     protected void
216     completeContainer()
217     {
218         struct_def_.members(members_.getStructMemberSeq());
219     }
220
221     // ==================================================================
222
//
223
// Public methods.
224
//
225
// ==================================================================
226

227     // ==================================================================
228
//
229
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
230
//
231
// ==================================================================
232

233     /**
234      * Obtain the declaration external dependencies.
235      *
236      * Note: for scopes, contained objects are not considered
237      * as dependencies.
238      *
239      * @return The list of dependencies as an array of Declaration.
240      */

241     public Declaration[]
242     getDependencies()
243     {
244         if (dependencies_!=null)
245             return dependencies_;
246
247         dependencies_ = new Declaration[0];
248
249         // members
250
java.util.List JavaDoc struct_depend = new java.util.ArrayList JavaDoc();
251         Declaration[] depend = null;
252
253         StructMember[] members = members_.getStructMembers();
254         for (int i=0; i<members.length; i++)
255         {
256             TypeRef member_type = members[i].getType();
257             if (member_type.isDeclaration())
258             {
259                 if ((!containsDecl((Declaration)member_type)) &&
260                     (struct_depend.indexOf(member_type)==-1))
261                     struct_depend.add(member_type);
262             }
263
264             depend = member_type.getDependencies();
265             for (int j=0; j<depend.length; j++)
266             {
267                 if ((struct_depend.indexOf(depend[j])==-1) &&
268                     (!containsDecl(depend[j])) &&
269                     (depend[j]!=this))
270                     struct_depend.add(depend[j]);
271             }
272         }
273
274         dependencies_ = (Declaration[])struct_depend.toArray(new Declaration[0]);
275         return dependencies_;
276     }
277
278     // ==================================================================
279
//
280
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
281
//
282
// ==================================================================
283

284     /**
285      * Obtain its DeclarationKind.
286      *
287      * @return The DeclarationKind of the object.
288      */

289     public long
290     getDeclKind()
291     {
292         return DeclarationKind.dk_struct;
293     }
294
295     // ==================================================================
296
//
297
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
298
//
299
// ==================================================================
300

301     // ==================================================================
302
//
303
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
304
//
305
// ==================================================================
306

307     // ==================================================================
308
//
309
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDeclarators
310
//
311
// ==================================================================
312

313     /**
314      * Find the declarator associated to an index.
315      *
316      * @param index The index of the declarator that should be returned.
317      *
318      * @return The name of the declarator at the specified index.
319      */

320     public String JavaDoc
321     declaratorAt(int index)
322     {
323         return members_.nameAt(index);
324     }
325
326     // ==================================================================
327
//
328
// Methods for OMG IDL org.objectweb.openccm.ast.api.TypeRef
329
//
330
// ==================================================================
331

332     /**
333      * Obtain its associated TypeKind.
334      *
335      * @return The associated TypeKind.
336      */

337     public TypeKind
338     getTypeKind()
339     {
340         return TypeKind.tk_struct;
341     }
342
343     // ==================================================================
344
//
345
// Methods for OMG IDL org.objectweb.openccm.ast.api.StructDecl
346
//
347
// ==================================================================
348

349     /**
350      * Obtain the struct member list.
351      *
352      * @return The members of the struct declaration.
353      */

354     public StructMemberList
355     getMemberList()
356     {
357         return members_;
358     }
359
360     // ==================================================================
361
//
362
// Methods for interface IDLTypeWrapper
363
//
364
// ==================================================================
365

366     /**
367      * Obtain its IDLType reference.
368      *
369      * @return The IDLType associated with the struct declaration.
370      */

371     public org.omg.CORBA.IDLType JavaDoc
372     getIDLType()
373     {
374         return struct_def_;
375     }
376 }
377
Popular Tags