KickJava   Java API By Example, From Geeks To Geeks.

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


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 DeclarationKind. */
30 import org.objectweb.openccm.ast.api.DeclarationKind;
31
32 /** To access AST Declaration. */
33 import org.objectweb.openccm.ast.api.Declaration;
34
35 /**
36  * ModuleDeclImpl is a wrapper class for IDL module declarations.
37  *
38  * Inherits from:
39  * - Scope as IDL modules are IDL scopes.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
42  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
43  *
44  * @version 0.3
45  */

46
47 public class ModuleDeclImpl
48      extends ForwardScopeIDLImpl
49   implements org.objectweb.openccm.ast.api.ModuleDecl,
50              org.objectweb.openccm.ast.api.PsdlModuleDecl,
51              org.objectweb.openccm.ast.api.CidlModuleDecl
52 {
53     // ==================================================================
54
//
55
// Internal state.
56
//
57
// ==================================================================
58

59     /** Reference to the CORBA 3.0 ModuleDef. */
60     private org.omg.CORBA.ComponentIR.ModuleDef component_module_def_;
61
62     /**
63      * TODO: This variable is already defined in ForwardScopeImpl!
64      */

65     private boolean completed_;
66
67     // ==================================================================
68
//
69
// Constructor.
70
//
71
// ==================================================================
72

73     /**
74      * The constructor with the parent scope.
75      *
76      * @param rep The repository of the declaration.
77      * @param parent The parent scope of the module declaration.
78      */

79     protected
80     ModuleDeclImpl(Repository rep,
81                    ScopeImpl parent)
82     {
83         // Call the ForwardScopeIDLImpl constructor.
84
super(rep, parent);
85
86         // Init internal state.
87
component_module_def_ = null;
88         completed_ = false;
89
90     // System.out.println("ModuleDeclImpl::ModuleDeclImpl " + this + " in " + parent);
91
}
92
93     // ==================================================================
94
//
95
// Internal methods.
96
//
97
// ==================================================================
98

99     // ==================================================================
100
//
101
// Internal methods for DeclarationImpl.
102
//
103
// ==================================================================
104

105     /**
106      * Loads infos of the CORBA 3.0 ModuleDef.
107      *
108      * @param moduleDef The ModuleDef to load.
109      */

110     protected void
111     load(org.omg.CORBA.Contained JavaDoc contained)
112     {
113         component_module_def_ = org.omg.CORBA.ComponentIR.ModuleDefHelper.
114                                 narrow(contained);
115         super.load(contained);
116     }
117
118     /**
119      * Loads infos of the CORBA 3.0 ModuleDef.
120      *
121      * @param moduleDef The ModuleDef to load.
122      */

123     protected void
124     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
125     {
126         component_module_def_ = org.omg.CORBA.ComponentIR.ModuleDefHelper.
127                                 narrow(contained);
128         super.loadAsMapping(contained);
129     }
130
131     /**
132      * Obtain its CORBA 3.0 Contained reference.
133      *
134      * @return The Contained object associated with the module declaration.
135      */

136     protected org.omg.CORBA.Contained JavaDoc
137     getContained()
138     {
139        return component_module_def_;
140     }
141
142     // ==================================================================
143
//
144
// Internal methods for ScopeImpl.
145
//
146
// ==================================================================
147

148     /**
149      ** Obtain its CORBA 3.0 Container reference.
150      **
151      ** @return The Container object associated with the module declaration.
152      **/

153     protected org.omg.CORBA.Container JavaDoc
154     getContainer()
155     {
156        return component_module_def_;
157     }
158
159     /**
160      ** Obtain its CORBA 3.0 Container reference.
161      **
162      ** @return The Container object associated with the module declaration.
163      **/

164     protected org.omg.CORBA.ComponentIR.Container
165     getComponentContainer()
166     {
167        return component_module_def_;
168     }
169
170     // ==================================================================
171
//
172
// Internal methods for ForwardScopeImpl.
173
//
174
// ==================================================================
175

176     // ==================================================================
177
//
178
// Internal methods for ForwardScopeIDLImpl.
179
//
180
// ==================================================================
181

182     /**
183      * Create the container object.
184      */

185     protected void
186     createContainer()
187     {
188         // Create it only if it was not previously created.
189
if (component_module_def_ == null)
190         {
191            // Create a ModuleDef into the IFR.
192
component_module_def_ =
193                the_parent_.getComponentContainer().
194                create_component_module(getId(), getName(), getVersion());
195         }
196     }
197
198     /**
199      * Complete the container object.
200      */

201     protected void
202     completeContainer()
203     {
204         completed_ = true;
205     }
206
207     // ==================================================================
208
//
209
// Public methods.
210
//
211
// ==================================================================
212

213     // ==================================================================
214
//
215
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
216
//
217
// ==================================================================
218

219     /**
220      * Obtain the declaration external dependencies.
221      *
222      * Note: for scopes, contained objects are not considered
223      * as dependencies.
224      *
225      * @return The list of dependencies as an array of Declaration.
226      */

227     public Declaration[]
228     getDependencies()
229     {
230         if (dependencies_!=null)
231             return dependencies_;
232
233         Declaration[] decls = getContents(true,
234              org.objectweb.openccm.ast.api.DeclarationKind.dk_all);
235         Declaration[] depend = null;
236         java.util.List JavaDoc module_depend = new java.util.ArrayList JavaDoc();
237
238         // contents
239
for (int i=0; i<decls.length; i++)
240         {
241             depend = decls[i].getDependencies();
242             for (int j=0; j<depend.length; j++)
243             {
244                 if ((!containsDecl(depend[j])) &&
245                     (module_depend.indexOf(depend[j])==-1))
246                     module_depend.add(depend[j]);
247             }
248         }
249
250         dependencies_ = (Declaration[])module_depend.toArray(
251                                           new Declaration[0]);
252         return dependencies_;
253     }
254
255     // ==================================================================
256
//
257
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
258
//
259
// ==================================================================
260

261     /**
262      * Obtain its DeclarationKind.
263      *
264      * @return The DeclarationKind of the object.
265      */

266     public long
267     getDeclKind()
268     {
269         return DeclarationKind.dk_module;
270     }
271
272     /**
273      * Create the interface declaration into the IFR.
274      */

275     public void
276     create()
277     {
278         if (getContainer() == null)
279         {
280             createContainer();
281             if (the_parent_!=null)
282                 the_parent_.addDecl(this);
283         }
284         else if (!completed_)
285             completeContainer();
286     }
287
288 //
289
// Added to correct the Bug #300511
290
// Contributor: Philippe Merle - Pawel Rzepa
291
//
292
/**
293      * Destroy all the contained declarations of the scope in the IR3.
294      */

295     public void
296     destroy()
297     {
298         // Destroy the declarations locally present in the AST.
299
for (int i=contained_decls_.size()-1; i>=0; i--)
300         {
301             Declaration decl = (Declaration)contained_decls_.get(i);
302             decl.destroy();
303         }
304
305         // Obtain the content of the module from the Interface Repository.
306
org.omg.CORBA.Contained JavaDoc[] contents =
307             getContainer().contents(org.omg.CORBA.DefinitionKind.dk_all, true);
308
309         // Destroy the module if it is empty in the Interface Repository.
310
if (contents.length==0)
311         {
312             super.destroy();
313         }
314     }
315
316     // ==================================================================
317
//
318
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
319
//
320
// ==================================================================
321

322     // ==================================================================
323
//
324
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
325
//
326
// ==================================================================
327

328     // ==================================================================
329
//
330
// Methods for OMG IDL org.objectweb.openccm.ast.api.ModuleDecl
331
//
332
// ==================================================================
333

334     // ==================================================================
335
//
336
// Methods for OMG IDL org.objectweb.openccm.ast.api.PsdlModuleDecl
337
//
338
// ==================================================================
339

340     // ==================================================================
341
//
342
// Methods for OMG IDL org.objectweb.openccm.ast.api.CidlModuleDecl
343
//
344
// ==================================================================
345
}
346
Popular Tags