KickJava   Java API By Example, From Geeks To Geeks.

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


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 interface 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 InterfaceDeclImpl
39        extends ForwardScopeImpl
40        implements InterfaceRef, InterfaceDecl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

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

51     private org.omg.CORBA.ExtInterfaceDef ext_interface_def_;
52
53     /**
54      ** List of inherited interfaces.
55      **/

56     protected org.objectweb.ccm.util.Vector inherited_interfaces_;
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 interface declaration.
68      **/

69     protected
70     InterfaceDeclImpl(Repository rep, ScopeImpl parent)
71     {
72         // Call the ForwardScopeImpl constructor.
73
super(rep, parent);
74
75         // Init internal state.
76
ext_interface_def_ = null;
77         inherited_interfaces_ = new org.objectweb.ccm.util.Vector();
78         the_declaration_kind_ = DeclarationKind._dk_interface;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     /**
88      ** Obtain its InterfaceDef[].
89      **
90      ** @return An array containing it's inherited InterfaceDef.
91      **/

92     protected org.omg.CORBA.InterfaceDef JavaDoc[]
93     getInterfaceDefs()
94     {
95         org.omg.CORBA.InterfaceDef JavaDoc[] result =
96             new org.omg.CORBA.InterfaceDef JavaDoc[inherited_interfaces_.size()];
97
98         for(int i=0; i<result.length; i++)
99         {
100             result[i] = ((InterfaceRef)(inherited_interfaces_.get(i))).getExtInterfaceDef();
101         }
102
103         return result;
104     }
105
106     /**
107      ** Find a declaration into inherited interfaces.
108      **
109      ** @param name The name of the searched declaration.
110      ** @return The declaration that was searched
111      ** or null if it does not exist.
112      **/

113     protected Declaration
114     findInInheritedInterfaces(String JavaDoc name)
115     {
116         for(int i=0; i<inherited_interfaces_.size(); i++)
117         {
118             Declaration decl = ((InterfaceDecl)(inherited_interfaces_.get(i))).find(name);
119             // If found then returns it.
120
if (decl != null) return decl;
121         }
122
123         // Else not found.
124
return null;
125     }
126
127     /**
128      ** Loads infos of the CORBA 3.0 InterfaceDef.
129      **
130      ** @param interfaceDef The InterfaceDef to load.
131      **/

132     protected void
133     load(org.omg.CORBA.Contained JavaDoc contained)
134     {
135         ext_interface_def_ = org.omg.CORBA.ExtInterfaceDefHelper.narrow(contained);
136         org.omg.CORBA.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
addInterface((InterfaceRef)getRepository().lookupId(base_interfaces[i].id()));
141
142         super.load(contained);
143     }
144
145     /**
146      ** Loads infos of the CORBA 3.0 InterfaceDef.
147      **
148      ** @param interfaceDef The InterfaceDef to load.
149      **/

150     protected void
151     loadAsMapping(org.omg.CORBA.Contained JavaDoc contained)
152     {
153         ext_interface_def_ = org.omg.CORBA.ExtInterfaceDefHelper.narrow(contained);
154         org.omg.CORBA.InterfaceDef JavaDoc[] base_interfaces = ext_interface_def_.base_interfaces();
155
156         for (int i=0;i<base_interfaces.length;i++)
157         // WARNING: This will break consistency of array items!!!
158
addInterface((InterfaceRef)getRepository().lookupMappedId(base_interfaces[i].id()));
159
160         super.loadAsMapping(contained);
161     }
162
163     // ==================================================================
164
//
165
// Methods for the Scope interface.
166
//
167
// ==================================================================
168

169     /**
170      ** Find a declaration.
171      **
172      ** Note that the declaration is also recursively searched
173      ** in the parent scope.
174      **
175      ** @param name The name of the searched declaration.
176      **
177      ** @return The declaration that was searched
178      ** or null if it does not exist.
179      **/

180     public Declaration
181     find(String JavaDoc name)
182     {
183         // Finds in the scope.
184
Declaration decl = super.find(name);
185
186         // If found then returns it.
187
if(decl != null) return decl;
188
189         // If not found then finds in inherited interfaces.
190
return findInInheritedInterfaces(name);
191     }
192
193     /**
194      ** Obtain the declaration external dependencies.
195      ** Note: for scopes, contained objects are not considered
196      ** as dependencies.
197      **
198      ** @return The list of dependencies as an array of Declaration.
199      **/

200     public Declaration[]
201     getDependencies()
202     {
203         if (dependencies_!=null)
204             return dependencies_;
205
206         dependencies_ = new Declaration[0];
207         org.objectweb.ccm.util.Vector itf_depend = new org.objectweb.ccm.util.Vector();
208         Declaration[] depend = null;
209
210         // base interfaces
211
InterfaceDecl[] bases = getBaseInterfaces();
212         for (int i=0;i<bases.length;i++)
213         {
214             itf_depend.add(bases[i]);
215             depend = bases[i].getDependencies();
216             for (int j=0;j<depend.length;j++)
217             {
218                 if ((depend[j]!=this) &&
219                     (itf_depend.indexOf(depend[j])==-1))
220                     itf_depend.add(depend[j]);
221             }
222         }
223
224         // contents
225
Declaration[] decls = getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_all);
226         for (int i=0;i<decls.length;i++)
227         {
228             depend = decls[i].getDependencies();
229             for (int j=0;j<depend.length;j++)
230             {
231                 if ((!containsDecl(depend[j])) &&
232                     (depend[j]!=this) &&
233                     (itf_depend.indexOf(depend[j])==-1))
234                     itf_depend.add(depend[j]);
235             }
236         }
237
238         dependencies_ = (Declaration[])itf_depend.toArray(new Declaration[0]);
239         return dependencies_;
240     }
241
242     // ==================================================================
243
//
244
// Methods for the TypeRef interface.
245
//
246
// ==================================================================
247

248     /**
249      ** Obtain its IDLType reference.
250      **
251      ** @return The IDLType associated with the interface declaration.
252      **/

253     public org.omg.CORBA.IDLType JavaDoc
254     getIDLType()
255     {
256         return ext_interface_def_;
257     }
258
259     /**
260      **
261      **/

262     public int
263     getTypeKind()
264     {
265         return TypeKind._tk_interface;
266     }
267
268     // ==================================================================
269
//
270
// Methods for the InterfaceRef interface.
271
//
272
// ==================================================================
273

274     /**
275      ** Obtain its InterfaceDef reference.
276      **
277      ** @return The InterfaceDef object associated with the interface
278      ** declaration.
279      **/

280     public org.omg.CORBA.ExtInterfaceDef
281     getExtInterfaceDef()
282     {
283         return ext_interface_def_;
284     }
285
286     /**
287      ** Obtain its InterfaceDef reference.
288      **
289      ** @return The InterfaceDef object associated with the interface
290      ** declaration.
291      **/

292     public org.omg.CORBA.InterfaceDef JavaDoc
293     getInterfaceDef()
294     {
295         return ext_interface_def_;
296     }
297
298     // ==================================================================
299
//
300
// Methods for the InterfaceDecl interface (parser view).
301
//
302
// ==================================================================
303

304     /**
305      ** Add an interface.
306      **
307      ** @param itf The base interface to add.
308      **/

309     public void
310     addInterface(InterfaceRef itf)
311     {
312         if(itf != null)
313         {
314             itf.addRef();
315             inherited_interfaces_.add(itf);
316         }
317     }
318
319     // ==================================================================
320
//
321
// Methods for the InterfaceDecl interface (visitor view).
322
//
323
// ==================================================================
324

325     /**
326      **
327      **/

328     public InterfaceDecl[]
329     getBaseInterfaces()
330     {
331         InterfaceDecl[] result = new InterfaceDecl[inherited_interfaces_.size()];
332
333         for(int i=0; i<result.length; i++)
334         {
335             result[i] = (InterfaceDecl)inherited_interfaces_.get(i);
336         }
337         return result;
338     }
339
340     // ==================================================================
341
//
342
// Methods for the inherited DeclarationImpl class.
343
//
344
// ==================================================================
345

346     /**
347      **
348      **/

349     public void
350     destroy()
351     {
352         for (int i=0;i<inherited_interfaces_.size();i++)
353         {
354             ((InterfaceRef)inherited_interfaces_.get(i)).removeRef();
355         }
356         super.destroy();
357     }
358
359     /**
360      ** Obtain its CORBA 3.0 Contained reference.
361      **
362      ** @return The Contained object associated with the interface
363      ** declaration.
364      **/

365     protected org.omg.CORBA.Contained JavaDoc
366     getContained()
367     {
368         return ext_interface_def_;
369     }
370
371     // ==================================================================
372
//
373
// Methods for the inherited ScopeImpl class.
374
//
375
// ==================================================================
376

377     /**
378      ** Obtain its CORBA 3.0 Container reference.
379      **
380      ** @return The Container object associated with the interface
381      ** declaration.
382      **/

383     protected org.omg.CORBA.Container JavaDoc
384     getContainer()
385     {
386         return ext_interface_def_;
387     }
388
389     /**
390      ** Create an attribute definition.
391      **
392      ** @param attribute The attribute declaration.
393      ** @param type The attribute IDLType.
394      ** @param mode The attribute mode.
395      ** @param get_exceptions An array containing the getRaises
396      ** (or raises for readonly attributes) exceptions.
397      ** @param put_exceptions An array containing the setRaises exceptions.
398      **
399      ** @return The new created AttributeDef.
400      **/

401     protected org.omg.CORBA.ExtAttributeDef
402     createExtAttribute(AttributeDecl attribute,
403                        org.omg.CORBA.IDLType JavaDoc type,
404                        org.omg.CORBA.AttributeMode JavaDoc mode,
405                        org.omg.CORBA.ExceptionDef JavaDoc[] get_exceptions,
406                        org.omg.CORBA.ExceptionDef JavaDoc[] set_exceptions)
407     {
408        // Create an AttributeDef into the IFR.
409
org.omg.CORBA.ExtAttributeDef ext_attribute_def =
410             getExtInterfaceDef().create_ext_attribute(attribute.getId(),
411                                                       attribute.getName(),
412                                                       attribute.getVersion(),
413                                                       type, mode,
414                                                       get_exceptions,
415                                                       set_exceptions);
416         return ext_attribute_def;
417     }
418
419     /**
420      ** Create an operation.
421      **
422      ** @param operation The operation declaration.
423      ** @param type The operation return IDLType.
424      ** @param mode The mode of the operation.
425      ** @param params An array containing the parameters description.
426      ** @param exceptions An array containing the exceptions that
427      ** can be raised.
428      ** @param contexts An array containing the possible context values.
429      **
430      ** @return The new created OperationDef.
431      **/

432     protected org.omg.CORBA.OperationDef JavaDoc
433     createOperation(OperationDecl operation,
434                     org.omg.CORBA.IDLType JavaDoc type,
435                     org.omg.CORBA.OperationMode JavaDoc mode,
436                     org.omg.CORBA.ParameterDescription JavaDoc[] params,
437                     org.omg.CORBA.ExceptionDef JavaDoc[] exceptions,
438                     String JavaDoc[] contexts)
439     {
440         // Create an OperationDef into the IFR.
441
org.omg.CORBA.OperationDef JavaDoc operation_def =
442             getExtInterfaceDef().create_operation(operation.getId(),
443                                                   operation.getName(),
444                                                   operation.getVersion(),
445                                                   type, mode,
446                                                   params,
447                                                   exceptions,
448                                                   contexts);
449         return operation_def;
450     }
451
452     /**
453      ** To obtain all the contained Declaration objects.
454      **
455      ** @param exclude_inherited If false return also objects contained in inherited scopes.
456      ** @param limited_types A logical combination of DeclarationKind.
457      **
458      ** @return An array of Declaration objects.
459      **/

460     public Declaration[]
461     getContents(boolean exclude_inherited, int limited_types)
462     {
463         if (exclude_inherited)
464             return super.getContents(exclude_inherited, limited_types);
465
466         // if it's a mapping scope, then use the OpenCCM repository as an IDL2 repository
467
// to retrieve contained objects.
468
if (is_mapping_)
469             getRepository().useIDL2Repository();
470
471         Declaration[] res = super.getContents(exclude_inherited, limited_types);
472         InterfaceDecl[] itfs = getBaseInterfaces();
473         for (int i=0;i<itfs.length;i++)
474         {
475             Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types);
476             Declaration[] tmp2 = res;
477             res = new Declaration[tmp1.length+tmp2.length];
478             System.arraycopy(tmp2, 0, res, 0, tmp2.length);
479             System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length);
480         }
481
482         // get back to an IDL3 repository.
483
if (is_mapping_)
484             getRepository().useIDL3Repository();
485
486         return res;
487     }
488
489     // ==================================================================
490
//
491
// Methods for the inherited ForwardScopeImpl class.
492
//
493
// ==================================================================
494

495     /**
496      ** Create the container object.
497      **/

498     protected void
499     createContainer()
500     {
501         ext_interface_def_ = the_parent_.getContainer().create_ext_interface(getId(),getName(), getVersion(),
502                                                                              getInterfaceDefs());
503     }
504
505     /**
506      ** Complete the container object.
507      **/

508     protected void
509     completeContainer()
510     {
511         org.omg.CORBA.InterfaceDef JavaDoc[] inherited_interfaces = getInterfaceDefs();
512         if (inherited_interfaces.length != 0)
513             getExtInterfaceDef().base_interfaces(inherited_interfaces);
514     }
515 }
516
Popular Tags