KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > InterfaceDef_impl


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.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.*;
31 import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription;
32
33 /**
34  * Implementation of the CORBA::InterfaceDef interface.
35  *
36  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
37  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
38  *
39  * @version 0.5
40  */

41
42 public class InterfaceDef_impl
43      extends Container_impl
44   implements InterfaceDefOperations
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** The base interfaces. */
53     protected InterfaceDef_ref[] base_interfaces_;
54
55     // ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     /** The default contructor. */
62     public
63     InterfaceDef_impl(IFR ifr,
64                       Container_impl container)
65     {
66         this(ifr, container, false);
67
68         // Sets the tie servant object.
69
setServant(new InterfaceDefPOATie(this));
70     }
71
72     /** The default contructor. */
73     public
74     InterfaceDef_impl(IFR ifr,
75                       Container_impl container,
76                       boolean dummy)
77     {
78         // Calls the Container_impl contructor.
79
super(ifr, container);
80
81         // Inits internal state.
82
base_interfaces_ = new InterfaceDef_ref[0];
83     }
84
85     // ==================================================================
86
//
87
// Internal methods.
88
//
89
// ==================================================================
90

91     /**
92      * To obtain the list of base interfaces.
93      */

94     protected InterfaceDef_ref[]
95     getBaseInterfaces()
96     {
97         return base_interfaces_;
98     }
99
100     // ==================================================================
101
//
102
// Internal methods for the inherited IRObject_impl class.
103
//
104
// ==================================================================
105

106     /**
107      * Warning : this operation must be implemented by subclasses.
108      * It allows us to avoid some casts while creating ::CORBA::TypeCode
109      */

110     protected TypeCode
111     recursiveType(java.util.List JavaDoc idSeq)
112     {
113         return type();
114     }
115
116     // ==================================================================
117
//
118
// Public methods.
119
//
120
// ==================================================================
121

122     /**
123         Obtain its CORBA::InterfaceDef object reference.
124      */

125     public InterfaceDef
126     asInterfaceDef()
127     {
128         return InterfaceDefHelper.narrow(asObject());
129     }
130
131     // ==================================================================
132
//
133
// For Contained_impl class.
134
//
135
// ==================================================================
136

137     /**
138      * To set the value field of the CORBA::Contained::Description struct.
139      */

140     public void
141     setDescriptionValue(Any any)
142     {
143         // create the CORBA::InterfaceDescription.
144
InterfaceDescription description = new InterfaceDescription();
145         description.name = name();
146         description.id = id();
147         description.defined_in = getContainerID();
148         description.version = version();
149         description.base_interfaces =
150                 InterfaceDef_ref.computeRepositoryIdSeq(getBaseInterfaces());
151
152         // insert it into the any.
153
InterfaceDescriptionHelper.insert(any, description);
154     }
155
156     // ==================================================================
157
//
158
// For Container_impl class.
159
//
160
// ==================================================================
161

162     /**
163      * Check if this kind of objects is accepted by the container.
164      */

165     public boolean
166     checkDefinitionKind(DefinitionKind dk)
167     {
168         return (dk == DefinitionKind.dk_Attribute)
169             || (dk == DefinitionKind.dk_Constant)
170             || (dk == DefinitionKind.dk_Exception)
171             || (dk == DefinitionKind.dk_Operation)
172             || (dk == DefinitionKind.dk_Alias)
173             || (dk == DefinitionKind.dk_Struct)
174             || (dk == DefinitionKind.dk_Union)
175             || (dk == DefinitionKind.dk_Enum)
176             || (dk == DefinitionKind.dk_Native);
177     }
178
179     /**
180      * Check a new name according to already contained names.
181      */

182     public void
183     checkName(String JavaDoc name,
184               boolean exclude_inherited,
185               boolean in_inherited)
186     {
187         // calls the Container_impl::validateName operations.
188
super.checkName(name, exclude_inherited, in_inherited);
189
190         if(!exclude_inherited)
191         {
192             InterfaceDef_ref[] bases = getBaseInterfaces();
193             for(int i=0; i<bases.length; i++)
194                 bases[i].getImpl().checkName(name, false, true);
195         }
196     }
197
198     /**
199      * Select named contained objects.
200      */

201     public java.util.List JavaDoc
202     selectNamedContained(java.util.List JavaDoc selection,
203                          String JavaDoc search_name,
204                          int levels_to_search,
205                          DefinitionKind limit_type,
206                          boolean exclude_inherited)
207     {
208         // call the Container_impl::selectContained operation.
209
super.selectNamedContained(selection, search_name, levels_to_search,
210                                    limit_type, exclude_inherited);
211
212         if(!exclude_inherited)
213         {
214             InterfaceDef_ref[] bases = getBaseInterfaces();
215             for(int i=0; i<bases.length; i++)
216             {
217                 bases[i].getImpl().selectNamedContained(selection,
218                                     search_name, levels_to_search,
219                                     limit_type, false);
220             }
221         }
222
223         return selection;
224     }
225
226     /**
227      * Select contained objects.
228      */

229     public java.util.List JavaDoc
230     selectContained(java.util.List JavaDoc selection,
231                     DefinitionKind limit_type,
232                     boolean exclude_inherited)
233     {
234         // call the Container_impl::selectContained operation.
235
super.selectContained(selection, limit_type, exclude_inherited);
236
237         if(!exclude_inherited)
238         {
239             InterfaceDef_ref[] bases = getBaseInterfaces();
240             for(int i=0; i<bases.length; i++)
241             {
242                 bases[i].getImpl().selectContained(
243                                            selection, limit_type, false);
244             }
245         }
246
247         return selection;
248     }
249
250     // ==================================================================
251
//
252
// Internal methods for managing dependencies.
253
//
254
// ==================================================================
255

256     /**
257      * Cuts dependencies to other objects.
258      */

259     protected void
260     cutDependencies()
261     {
262         // Cuts the dependency to base interfaces.
263
InterfaceDef_ref.cutDependencies(base_interfaces_);
264         base_interfaces_ = null;
265
266         // Calls the Container_impl::cutDependencies operation.
267
super.cutDependencies();
268     }
269
270     // ==================================================================
271
//
272
// For CORBA::IRObject interface.
273
//
274
// ==================================================================
275

276     /**
277      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
278      */

279     public DefinitionKind
280     def_kind()
281     {
282         return DefinitionKind.dk_Interface;
283     }
284
285     // ==================================================================
286
//
287
// For CORBA::IDLType interface.
288
//
289
// ==================================================================
290

291     /**
292      * IDL:omg.org/CORBA/IDLType/type:1.0
293      */

294     public TypeCode
295     type()
296     {
297         // delegate to the TypeCodeFactory.
298
return getIFR().getTCF().create_interface_tc(id(), name());
299     }
300
301     // ==================================================================
302
//
303
// For CORBA::Container interface.
304
//
305
// ==================================================================
306

307     /**
308      * IDL:omg.org/CORBA/Container/lookup:1.0
309      */

310     public Contained
311     lookup(String JavaDoc search_name)
312     {
313         // call the Container_impl::lookup operation.
314
Contained contained1 = super.lookup(search_name);
315
316         if (contained1 == null)
317         {
318             InterfaceDef_ref[] bases = getBaseInterfaces();
319             for(int i=0; i<bases.length; i++)
320             {
321                 Contained contained2 = bases[i].getImpl().lookup(search_name);
322                 if(contained2 != null)
323                 {
324                     if(contained1 != null)
325                     {
326                         String JavaDoc id1 = contained1.id();
327                         String JavaDoc id2 = contained2.id();
328                         if(!id1.equals(id2))
329                             throw exceptionAmbiguousLookup(id1, id2);
330                     }
331
332                     contained1 = contained2;
333                 }
334             }
335         }
336
337         return contained1;
338     }
339
340     // ==================================================================
341
//
342
// For CORBA::InterfaceDef interface.
343
//
344
// ==================================================================
345

346     /**
347      * IDL:omg.org/CORBA/InterfaceDef/base_interfaces:1.0
348      */

349     public InterfaceDef[]
350     base_interfaces()
351     {
352         return InterfaceDef_ref.computeInterfaceDefSeq(getBaseInterfaces());
353     }
354
355     /**
356      * IDL:omg.org/CORBA/InterfaceDef/base_interfaces:1.0
357      */

358     public void
359     base_interfaces(InterfaceDef[] val)
360     {
361         InterfaceDef_impl[] itfs = new InterfaceDef_impl[val.length];
362         for (int i=0; i<val.length; i++)
363             itfs[i] = castToLocal(val[i]);
364
365         // TODO: check inheritance
366

367         InterfaceDef_ref[] refs = new InterfaceDef_ref[val.length];
368         for (int i=0; i<val.length; i++)
369             refs[i] = new InterfaceDef_ref( this, itfs[i] );
370
371         // cut the previous dependency to base interfaces.
372
InterfaceDef_ref.cutDependencies(getBaseInterfaces());
373
374         base_interfaces_ = refs;
375     }
376
377     /**
378      * IDL:omg.org/CORBA/InterfaceDef/is_a:1.0
379      */

380     public boolean
381     is_a(String JavaDoc interface_id)
382     {
383         if(interface_id.equals(id()))
384             return true;
385
386         if(interface_id.equals("IDL:omg.org/CORBA/Object:1.0"))
387             return true;
388
389         InterfaceDef_ref[] bases = getBaseInterfaces();
390         for(int i=0; i<bases.length; i++)
391             if (bases[i].getImpl().is_a(interface_id))
392                 return true;
393
394         return false;
395     }
396
397     /**
398      * IDL:omg.org/CORBA/InterfaceDef/describe_interface:1.0
399      */

400     public FullInterfaceDescription
401     describe_interface()
402     {
403         FullInterfaceDescription description = new FullInterfaceDescription();
404         description.name = name();
405         description.id = id();
406         description.defined_in = getContainerID();
407         description.version = version();
408         description.operations = getOpDescriptionSeq();
409         description.attributes = getAttrDescriptionSeq();
410         description.base_interfaces =
411                 InterfaceDef_ref.computeRepositoryIdSeq(getBaseInterfaces());
412         description.type = type();
413         return description;
414     }
415
416     /**
417      * IDL:omg.org/CORBA/InterfaceDef/create_attribute:1.0
418      */

419     public AttributeDef
420     create_attribute(String JavaDoc id,
421                      String JavaDoc name,
422                      String JavaDoc version,
423                      IDLType type,
424                      AttributeMode mode)
425     {
426         AttributeDef_impl attr = new AttributeDef_impl(getIFR(), this);
427
428         try
429         {
430             addContained(attr, id, name, version);
431             attr.type_def(type);
432             attr.mode(mode);
433         }
434         catch(SystemException exc)
435         {
436             attr.destroy();
437             throw exc;
438         }
439
440         attr.whenCreated();
441         return attr.asAttributeDef();
442     }
443
444     /**
445      * IDL:omg.org/CORBA/InterfaceDef/create_operation:1.0
446      */

447     public OperationDef
448     create_operation(String JavaDoc id,
449                      String JavaDoc name,
450                      String JavaDoc version,
451                      IDLType result,
452                      OperationMode mode,
453                      ParameterDescription[] params,
454                      ExceptionDef[] exceptions,
455                      String JavaDoc[] contexts)
456     {
457         OperationDef_impl op = new OperationDef_impl(getIFR(), this);
458
459         try
460         {
461             addContained(op, id, name, version);
462             op.result_def(result);
463             op.mode(mode);
464             op.params(params);
465             op.exceptions(exceptions);
466             op.contexts(contexts);
467         }
468         catch(SystemException exc)
469         {
470             op.destroy();
471             throw exc;
472         }
473
474         op.whenCreated();
475         return op.asOperationDef();
476     }
477 }
478
Popular Tags