KickJava   Java API By Example, From Geeks To Geeks.

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


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 TypeKind. */
30 import org.objectweb.openccm.ast.api.TypeKind;
31
32 /** Used to access AST DeclarationKind. */
33 import org.objectweb.openccm.ast.api.DeclarationKind;
34
35 /** Used to access AST Declaration. */
36 import org.objectweb.openccm.ast.api.Declaration;
37
38 /** Used to access AST InterfaceDecl. */
39 import org.objectweb.openccm.ast.api.InterfaceDecl;
40
41 /** Used to access AST InterfaceList. */
42 import org.objectweb.openccm.ast.api.InterfaceList;
43
44 /** Used to access AST AttributeDecl. */
45 import org.objectweb.openccm.ast.api.AttributeDecl;
46
47 /** Used to access AST OperationDecl. */
48 import org.objectweb.openccm.ast.api.OperationDecl;
49
50 /** To use CORBA::InterfaceDef. */
51 import org.omg.CORBA.InterfaceDef JavaDoc;
52
53 /** To use CORBA::ExtInterfaceDef. */
54 import org.omg.CORBA.ExtInterfaceDef;
55 import org.omg.CORBA.ExtInterfaceDefHelper;
56
57 /**
58  * InterfaceDeclImpl is a wrapper class for IDL interface declarations.
59  *
60  * Inherits from:
61  * - ForwardScope as interfaces are also IDL forward scopes.
62  * - TypeRef as interfaces are IDL types.
63  *
64  * Provides:
65  * - The list of inherited interfaces
66  * i.e. the getInheritedInterfaceList operation
67  *
68  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
69  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
70  *
71  * @version 0.3
72  */

73
74 public class InterfaceDeclImpl
75      extends ForwardScopeIDLImpl
76   implements InterfaceDecl,
77              IDLTypeWrapper
78 {
79     // ==================================================================
80
//
81
// Internal state.
82
//
83
// ==================================================================
84

85     /** Reference to the CORBA 3.0 InterfaceDef. */
86     private ExtInterfaceDef ext_interface_def_;
87
88     /** List of inherited interfaces. */
89     protected InterfaceListImpl inherited_interfaces_;
90
91     // ==================================================================
92
//
93
// Constructor.
94
//
95
// ==================================================================
96

97     /**
98      * The constructor with the parent scope.
99      *
100      * @param rep The repository of the declaration.
101      * @param parent The parent scope of the interface declaration.
102      */

103     protected
104     InterfaceDeclImpl(Repository rep,
105                       ScopeImpl parent)
106     {
107         // Call the ForwardScopeIDLImpl constructor.
108
super(rep, parent);
109
110         // Init internal state.
111
ext_interface_def_ = null;
112         inherited_interfaces_ = new InterfaceListImpl();
113     }
114
115     // ==================================================================
116
//
117
// Internal methods.
118
//
119
// ==================================================================
120

121     // ==================================================================
122
//
123
// Internal methods for DeclarationImpl.
124
//
125
// ==================================================================
126

127     /**
128      * Loads infos of the CORBA 3.0 InterfaceDef.
129      *
130      * @param contained The InterfaceDef to load.
131      */

132     protected void
133     load(org.omg.CORBA.Contained JavaDoc contained)
134     {
135         ext_interface_def_ = ExtInterfaceDefHelper.narrow(contained);
136         InterfaceDef JavaDoc[] base_interfaces = ext_interface_def_.base_interfaces();
137
138         for (int i=0; i<base_interfaces.length; i++)
139         // WARNING: This will break consistency of array items!!!
140
inherited_interfaces_.add((InterfaceDecl)
141                        getRepository().lookupId(base_interfaces[i].id()));
142
143         super.load(contained);
144     }
145
146     /**
147      * Loads infos of the CORBA 3.0 InterfaceDef.
148      *
149      * @param contained The InterfaceDef to load.
150      */

151     protected void
152     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
153     {
154         ext_interface_def_ = ExtInterfaceDefHelper.narrow(contained);
155         InterfaceDef JavaDoc[] base_interfaces = ext_interface_def_.base_interfaces();
156
157         for (int i=0; i<base_interfaces.length; i++)
158         // WARNING: This will break consistency of array items!!!
159
inherited_interfaces_.add((InterfaceDecl)
160                 getRepository().lookupMappedId(base_interfaces[i].id()));
161
162         super.loadAsMapping(contained);
163     }
164
165     /**
166      * Obtain its CORBA 3.0 Contained reference.
167      *
168      * @return The Contained object associated with the interface
169      * declaration.
170      */

171     protected org.omg.CORBA.Contained JavaDoc
172     getContained()
173     {
174         return ext_interface_def_;
175     }
176
177     // ==================================================================
178
//
179
// Internal methods for ScopeImpl.
180
//
181
// ==================================================================
182

183     /**
184      * Create an attribute definition.
185      *
186      * @param attribute The attribute declaration.
187      * @param type The attribute IDLType.
188      * @param mode The attribute mode.
189      * @param get_exceptions An array containing the getRaises
190      * (or raises for readonly attributes) exceptions.
191      * @param put_exceptions An array containing the setRaises exceptions.
192      *
193      * @return The new created AttributeDef.
194      */

195     protected org.omg.CORBA.ExtAttributeDef
196     createExtAttribute(AttributeDecl attribute,
197                        org.omg.CORBA.IDLType JavaDoc type,
198                        org.omg.CORBA.AttributeMode JavaDoc mode,
199                        org.omg.CORBA.ExceptionDef JavaDoc[] get_exceptions,
200                        org.omg.CORBA.ExceptionDef JavaDoc[] set_exceptions)
201     {
202        // Create an AttributeDef into the IFR.
203
org.omg.CORBA.ExtAttributeDef ext_attribute_def =
204             getExtInterfaceDef().create_ext_attribute(attribute.getId(),
205                                                       attribute.getName(),
206                                                       attribute.getVersion(),
207                                                       type, mode,
208                                                       get_exceptions,
209                                                       set_exceptions);
210         return ext_attribute_def;
211     }
212
213     /**
214      * Create an operation.
215      *
216      * @param operation The operation declaration.
217      * @param type The operation return IDLType.
218      * @param mode The mode of the operation.
219      * @param params An array containing the parameters description.
220      * @param exceptions An array containing the exceptions that
221      * can be raised.
222      * @param contexts An array containing the possible context values.
223      *
224      * @return The new created OperationDef.
225      */

226     protected org.omg.CORBA.OperationDef JavaDoc
227     createOperation(OperationDecl operation,
228                     org.omg.CORBA.IDLType JavaDoc type,
229                     org.omg.CORBA.OperationMode JavaDoc mode,
230                     org.omg.CORBA.ParameterDescription JavaDoc[] params,
231                     org.omg.CORBA.ExceptionDef JavaDoc[] exceptions,
232                     String JavaDoc[] contexts)
233     {
234         // Create an OperationDef into the IFR.
235
org.omg.CORBA.OperationDef JavaDoc operation_def =
236             getExtInterfaceDef().create_operation(operation.getId(),
237                                                   operation.getName(),
238                                                   operation.getVersion(),
239                                                   type, mode,
240                                                   params,
241                                                   exceptions,
242                                                   contexts);
243         return operation_def;
244     }
245
246     /**
247      * Obtain its CORBA 3.0 Container reference.
248      *
249      * @return The Container object associated with the interface
250      * declaration.
251      */

252     protected org.omg.CORBA.Container JavaDoc
253     getContainer()
254     {
255         return ext_interface_def_;
256     }
257
258     // ==================================================================
259
//
260
// Internal methods for ForwardScopeImpl.
261
//
262
// ==================================================================
263

264     // ==================================================================
265
//
266
// Internal methods for ForwardScopeIDLImpl.
267
//
268
// ==================================================================
269

270     /**
271      * Create the container object.
272      */

273     protected void
274     createContainer()
275     {
276         ext_interface_def_ = the_parent_.getContainer().
277                     create_ext_interface(getId(), getName(), getVersion(),
278                                inherited_interfaces_.getInterfaceDefSeq());
279     }
280
281     /**
282      ** Complete the container object.
283      **/

284     protected void
285     completeContainer()
286     {
287         InterfaceDef JavaDoc[] inherited_interfaces = inherited_interfaces_.getInterfaceDefSeq();
288         if (inherited_interfaces.length != 0)
289             getExtInterfaceDef().base_interfaces(inherited_interfaces);
290     }
291
292     // ==================================================================
293
//
294
// Public methods.
295
//
296
// ==================================================================
297

298     /**
299      * Obtain its InterfaceDef reference.
300      *
301      * @return The InterfaceDef object associated with the interface
302      * declaration.
303      */

304     public ExtInterfaceDef
305     getExtInterfaceDef()
306     {
307         return ext_interface_def_;
308     }
309
310     /**
311      * Obtain its InterfaceDef reference.
312      *
313      * @return The InterfaceDef object associated with the interface
314      * declaration.
315      */

316     public InterfaceDef JavaDoc
317     getInterfaceDef()
318     {
319         return ext_interface_def_;
320     }
321
322     // ==================================================================
323
//
324
// Methods for OMG IDL org.objectweb.openccm.ast.api.WithDependencies
325
//
326
// ==================================================================
327

328     /**
329      * Obtain the declaration external dependencies.
330      *
331      * Note: for scopes, contained objects are not considered
332      * as dependencies.
333      *
334      * @return The list of dependencies as an array of Declaration.
335      */

336     public Declaration[]
337     getDependencies()
338     {
339         if (dependencies_!=null)
340             return dependencies_;
341
342         dependencies_ = new Declaration[0];
343         java.util.List JavaDoc itf_depend = new java.util.ArrayList JavaDoc();
344         Declaration[] depend = null;
345
346         // base interfaces
347
InterfaceDecl[] bases = inherited_interfaces_.getInterfaces();
348         for (int i=0; i<bases.length; i++)
349         {
350             itf_depend.add(bases[i]);
351             depend = bases[i].getDependencies();
352             for (int j=0;j<depend.length;j++)
353             {
354                 if ((depend[j]!=this) &&
355                     (itf_depend.indexOf(depend[j])==-1))
356                     itf_depend.add(depend[j]);
357             }
358         }
359
360         // contents
361
Declaration[] decls = getContents(true, DeclarationKind.dk_all);
362         for (int i=0; i<decls.length; i++)
363         {
364             depend = decls[i].getDependencies();
365             for (int j=0;j<depend.length;j++)
366             {
367                 if ((!containsDecl(depend[j])) &&
368                     (depend[j]!=this) &&
369                     (itf_depend.indexOf(depend[j])==-1))
370                     itf_depend.add(depend[j]);
371             }
372         }
373
374         dependencies_ = (Declaration[])itf_depend.toArray(new Declaration[0]);
375         return dependencies_;
376     }
377
378     // ==================================================================
379
//
380
// Methods for OMG IDL org.objectweb.openccm.ast.api.Declaration
381
//
382
// ==================================================================
383

384     /**
385      * Obtain its DeclarationKind.
386      *
387      * @return The DeclarationKind of the object.
388      */

389     public long
390     getDeclKind()
391     {
392         return DeclarationKind.dk_interface;
393     }
394
395     // ==================================================================
396
//
397
// Methods for OMG IDL org.objectweb.openccm.ast.api.Scope
398
//
399
// ==================================================================
400

401     /**
402      * Find a declaration.
403      *
404      * Note that the declaration is also recursively searched
405      * in the parent scope.
406      *
407      * @param name The name of the searched declaration.
408      *
409      * @return The declaration that was searched
410      * or null if it does not exist.
411      */

412     public Declaration
413     find(String JavaDoc name)
414     {
415         // Finds in the scope.
416
Declaration decl = super.find(name);
417
418         // If found then returns it.
419
if(decl != null) return decl;
420
421         // If not found then finds in inherited interfaces.
422
return inherited_interfaces_.find(name);
423     }
424
425     /**
426      * To obtain all the contained Declaration objects.
427      *
428      * @param exclude_inherited If false return also objects
429      * contained in inherited scopes.
430      * @param limited_types A logical combination of DeclarationKind.
431      *
432      * @return An array of Declaration objects.
433      */

434     public Declaration[]
435     getContents(boolean exclude_inherited,
436                 long limited_types)
437     {
438         if (exclude_inherited)
439             return super.getContents(exclude_inherited, limited_types);
440
441         // if it's a mapping scope, then use the OpenCCM repository
442
// as an IDL2 repository to retrieve contained objects.
443
if (is_mapping_)
444             getRepository().useIDL2Repository();
445
446         Declaration[] res = super.getContents(exclude_inherited, limited_types);
447         InterfaceDecl[] itfs = inherited_interfaces_.getInterfaces();
448         for (int i=0; i<itfs.length; i++)
449         {
450             Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types);
451             Declaration[] tmp2 = res;
452             res = new Declaration[tmp1.length+tmp2.length];
453             System.arraycopy(tmp2, 0, res, 0, tmp2.length);
454             System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length);
455         }
456
457         // get back to an IDL3 repository.
458
if (is_mapping_)
459             getRepository().useIDL3Repository();
460
461         return res;
462     }
463
464     // ==================================================================
465
//
466
// Methods for OMG IDL org.objectweb.openccm.ast.api.ForwardScope
467
//
468
// ==================================================================
469

470     // ==================================================================
471
//
472
// Methods for OMG IDL org.objectweb.openccm.ast.api.TypeRef
473
//
474
// ==================================================================
475

476     /**
477      * Obtain its associated TypeKind.
478      *
479      * @return The associated TypeKind.
480      */

481     public TypeKind
482     getTypeKind()
483     {
484         return TypeKind.tk_interface;
485     }
486
487     // ==================================================================
488
//
489
// Methods for OMG IDL org.objectweb.openccm.ast.api.InterfaceDecl
490
//
491
// ==================================================================
492

493     /**
494      * Obtain the inherited interface list.
495      *
496      * @return The inherited interface list.
497      */

498     public InterfaceList
499     getInheritedInterfaceList()
500     {
501         return inherited_interfaces_;
502     }
503
504     // ==================================================================
505
//
506
// Methods for interface IDLTypeWrapper
507
//
508
// ==================================================================
509

510     /**
511      * Obtain its IDLType reference.
512      *
513      * @return The IDLType associated with the interface declaration.
514      */

515     public org.omg.CORBA.IDLType JavaDoc
516     getIDLType()
517     {
518         return ext_interface_def_;
519     }
520 }
521
Popular Tags