KickJava   Java API By Example, From Geeks To Geeks.

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


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 struct 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 StructDeclImpl
39        extends ForwardScopeImpl
40        implements TypeRef, StructDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

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

51     protected org.omg.CORBA.StructDef JavaDoc struct_def_;
52
53     /**
54      ** List of members.
55      **/

56     protected StructMembersImpl 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     StructDeclImpl(Repository rep, ScopeImpl parent)
71     {
72         // Call the ScopeImpl constructor.
73
super(rep, parent);
74
75         // Init internal state.
76
struct_def_ = null;
77         members_ = new StructMembersImpl();
78         the_declaration_kind_ = DeclarationKind._dk_struct;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

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

92     protected void
93     load(org.omg.CORBA.Contained JavaDoc contained)
94     {
95         struct_def_ = org.omg.CORBA.StructDefHelper.narrow(contained);
96         org.omg.CORBA.StructMember JavaDoc[] members = struct_def_.members();
97
98         // load as scope now to prevent infinite loop in the case
99
// of recursive struct.
100
super.load(contained);
101
102         for (int i=0;i<members.length;i++)
103             members_.addMember(members[i].name,
104                                getRepository().getAsTypeRef(members[i].type_def));
105     }
106
107     /**
108      ** Loads infos of the CORBA 3.0 StructDef.
109      **
110      ** @param structDef The StructDef to load.
111      **/

112     protected void
113     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
114     {
115         struct_def_ = org.omg.CORBA.StructDefHelper.narrow(contained);
116         org.omg.CORBA.StructMember JavaDoc[] members = struct_def_.members();
117
118         // load as scope now to prevent infinite loop in the case
119
// of recursive struct.
120
super.loadAsMapping(contained);
121
122         for (int i=0;i<members.length;i++)
123             members_.addMember(members[i].name,
124                                getRepository().getAsMappedTypeRef(members[i].type_def));
125     }
126
127     // ==================================================================
128
//
129
// Methods for the Declaration interface.
130
//
131
// ==================================================================
132

133     /**
134      ** Return the index declarator.
135      **
136      ** @param index The index of the declarator that should be returned.
137      **
138      ** @return The name of the declarator at the specified index.
139      **/

140     public String JavaDoc
141     declaratorAt(int index)
142     {
143         return members_.nameAt(index);
144     }
145
146     /**
147      ** Obtain the declaration external dependencies.
148      ** Note: for scopes, contained objects are not considered
149      ** as dependencies.
150      **
151      ** @return The list of dependencies as an array of Declaration.
152      **/

153     public Declaration[]
154     getDependencies()
155     {
156         if (dependencies_!=null)
157             return dependencies_;
158
159         dependencies_ = new Declaration[0];
160
161         // members
162
org.objectweb.ccm.util.Vector struct_depend = new org.objectweb.ccm.util.Vector();
163         Declaration[] depend = null;
164         TypeRef[] member_types = getMembers().getMemberTypes();
165
166         for (int i=0;i<member_types.length;i++)
167         {
168             if (member_types[i].isDeclaration())
169             {
170                 if ((!containsDecl((Declaration)member_types[i])) &&
171                     (struct_depend.indexOf(member_types[i])==-1))
172                     struct_depend.add(member_types[i]);
173             }
174
175             depend = member_types[i].getDependencies();
176             for (int j=0;j<depend.length;j++)
177             {
178                 if ((struct_depend.indexOf(depend[j])==-1) &&
179                     (!containsDecl(depend[j])) &&
180                     (depend[j]!=this))
181                     struct_depend.add(depend[j]);
182             }
183         }
184
185         dependencies_ = (Declaration[])struct_depend.toArray(new Declaration[0]);
186         return dependencies_;
187     }
188
189     // ==================================================================
190
//
191
// Methods for the Scope interface.
192
//
193
// ==================================================================
194

195     // ==================================================================
196
//
197
// Methods for the TypeRef interface.
198
//
199
// ==================================================================
200

201     /**
202      ** Obtain its IDLType reference.
203      **
204      ** @return The IDLType associated with the struct declaration.
205      **/

206     public org.omg.CORBA.IDLType JavaDoc
207     getIDLType()
208     {
209         return struct_def_;
210     }
211
212     /**
213      **
214      **/

215     public int
216     getTypeKind()
217     {
218         return TypeKind._tk_struct;
219     }
220
221     // ==================================================================
222
//
223
// Methods for the StructDecl interface.
224
//
225
// ==================================================================
226

227     /**
228      ** Obtain the member list.
229      **
230      ** @return The members of the struct declaration.
231      **/

232     public StructMembers
233     getMembers()
234     {
235         return members_;
236     }
237
238     // ==================================================================
239
//
240
// Methods for the inherited ScopeImpl class.
241
//
242
// ==================================================================
243

244     /**
245      ** Obtain its CORBA 3.0 Container reference.
246      **
247      ** @return The Container object associated with the struct declaration.
248      **/

249     protected org.omg.CORBA.Container JavaDoc
250     getContainer()
251     {
252         return struct_def_;
253     }
254
255     // ==================================================================
256
//
257
// Methods for the inherited DeclarationImpl class.
258
//
259
// ==================================================================
260

261     /**
262      **
263      **/

264     public void
265     destroy()
266     {
267         members_.destroy();
268         super.destroy();
269     }
270
271     /**
272      ** Obtain its CORBA 3.0 Contained reference.
273      **
274      ** @return The Contained object associated with the struct declaration.
275      **/

276     protected org.omg.CORBA.Contained JavaDoc
277     getContained()
278     {
279         return struct_def_;
280     }
281
282     // ==================================================================
283
//
284
// Methods for the inherited ForwardScopeImpl class.
285
//
286
// ==================================================================
287

288     /**
289      ** Create the container object.
290      **/

291     protected void
292     createContainer()
293     {
294         struct_def_ = the_parent_.getContainer().create_struct(getId(), getName(), getVersion(),
295                                                                members_.getMemberDefs());
296     }
297
298     /**
299      ** Complete the container object.
300      **/

301     protected void
302     completeContainer()
303     {
304         struct_def_.members(members_.getMemberDefs());
305     }
306 }
307
Popular Tags