KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ir > InterfaceDefImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software 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 software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.rmi.ir;
23
24 import org.omg.CORBA.InterfaceDefOperations JavaDoc;
25 import org.omg.CORBA.InterfaceDefPOATie;
26 import org.omg.CORBA.InterfaceDefHelper;
27 import org.omg.CORBA.Any JavaDoc;
28 import org.omg.CORBA.TypeCode JavaDoc;
29 import org.omg.CORBA.IRObject JavaDoc;
30 import org.omg.CORBA.Contained JavaDoc;
31 import org.omg.CORBA.ContainedPackage.Description;
32 import org.omg.CORBA.DefinitionKind JavaDoc;
33 import org.omg.CORBA.IDLType JavaDoc;
34 import org.omg.CORBA.StructMember JavaDoc;
35 import org.omg.CORBA.UnionMember JavaDoc;
36 import org.omg.CORBA.InterfaceDef JavaDoc;
37 import org.omg.CORBA.ConstantDef JavaDoc;
38 import org.omg.CORBA.EnumDef JavaDoc;
39 import org.omg.CORBA.ValueDef JavaDoc;
40 import org.omg.CORBA.ValueBoxDef JavaDoc;
41 import org.omg.CORBA.Initializer JavaDoc;
42 import org.omg.CORBA.StructDef JavaDoc;
43 import org.omg.CORBA.UnionDef JavaDoc;
44 import org.omg.CORBA.ModuleDef JavaDoc;
45 import org.omg.CORBA.AliasDef JavaDoc;
46 import org.omg.CORBA.NativeDef JavaDoc;
47 import org.omg.CORBA.OperationDef JavaDoc;
48 import org.omg.CORBA.OperationMode JavaDoc;
49 import org.omg.CORBA.ParameterDescription JavaDoc;
50 import org.omg.CORBA.AttributeDef JavaDoc;
51 import org.omg.CORBA.AttributeMode JavaDoc;
52 import org.omg.CORBA.ExceptionDef JavaDoc;
53 import org.omg.CORBA.OperationDescription JavaDoc;
54 import org.omg.CORBA.AttributeDescription JavaDoc;
55 import org.omg.CORBA.InterfaceDescription JavaDoc;
56 import org.omg.CORBA.InterfaceDescriptionHelper;
57 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
58 import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription;
59
60 /**
61  * Interface IR object.
62  *
63  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
64  * @version $Revision: 37459 $
65  */

66 class InterfaceDefImpl
67    extends ContainedImpl
68    implements InterfaceDefOperations JavaDoc, LocalContainer
69 {
70    // Constants -----------------------------------------------------
71

72    // Attributes ----------------------------------------------------
73

74    // Static --------------------------------------------------------
75

76    private static final org.jboss.logging.Logger logger =
77                org.jboss.logging.Logger.getLogger(InterfaceDefImpl.class);
78
79    // Constructors --------------------------------------------------
80

81    InterfaceDefImpl(String JavaDoc id, String JavaDoc name, String JavaDoc version,
82                     LocalContainer defined_in, String JavaDoc[] base_interfaces,
83                     RepositoryImpl repository)
84    {
85       super(id, name, version, defined_in,
86             DefinitionKind.dk_Interface, repository);
87
88       this.base_interfaces = base_interfaces;
89       this.delegate = new ContainerImplDelegate(this);
90    }
91
92    // Public --------------------------------------------------------
93

94    // LocalContainer implementation ---------------------------------
95

96    public LocalContained _lookup(String JavaDoc search_name)
97    {
98       return delegate._lookup(search_name);
99    }
100  
101    public LocalContained[] _contents(DefinitionKind JavaDoc limit_type,
102                                     boolean exclude_inherited)
103    {
104       return delegate._contents(limit_type, exclude_inherited);
105    }
106  
107    public LocalContained[] _lookup_name(String JavaDoc search_name,
108                                          int levels_to_search,
109                                          DefinitionKind JavaDoc limit_type,
110                                          boolean exclude_inherited)
111    {
112       return delegate._lookup_name(search_name, levels_to_search, limit_type,
113                                    exclude_inherited);
114    }
115
116    public void add(String JavaDoc name, LocalContained contained)
117       throws IRConstructionException
118    {
119       delegate.add(name, contained);
120    }
121
122    // LocalIRObject implementation ---------------------------------
123

124    public IRObject JavaDoc getReference()
125    {
126       if (ref == null) {
127          ref = org.omg.CORBA.InterfaceDefHelper.narrow(
128                             servantToReference(new InterfaceDefPOATie(this)) );
129       }
130       return ref;
131    }
132
133    public void allDone()
134       throws IRConstructionException
135    {
136       getReference();
137       delegate.allDone();
138    }
139
140    public void shutdown()
141    {
142       delegate.shutdown();
143       super.shutdown();
144    }
145
146    // ContainerOperations implementation ----------------------------
147

148    public Contained JavaDoc lookup(String JavaDoc search_name)
149    {
150       logger.debug("InterfaceDefImpl.lookup(\"" + search_name +
151                    "\") entered.");
152       Contained JavaDoc res = delegate.lookup(search_name);
153       logger.debug("InterfaceDefImpl.lookup(\"" + search_name +
154                    "\") returning " + ((res == null) ? "null" : "non-null") );
155       return res;
156       //return delegate.lookup(search_name);
157
}
158
159    public Contained JavaDoc[] contents(DefinitionKind JavaDoc limit_type,
160                                boolean exclude_inherited)
161    {
162       logger.debug("InterfaceDefImpl.contents() entered.");
163       Contained JavaDoc[] res = delegate.contents(limit_type, exclude_inherited);
164       logger.debug("InterfaceDefImpl.contents() " + res.length +
165                    " contained to return.");
166       for (int i = 0; i < res.length; ++i)
167          logger.debug(" InterfaceDefImpl.contents() [" + i + "]: " +
168                       res[i].id());
169       return res;
170       //return delegate.contents(limit_type, exclude_inherited);
171
}
172
173    public Contained JavaDoc[] lookup_name(String JavaDoc search_name, int levels_to_search,
174                                   DefinitionKind JavaDoc limit_type,
175                                   boolean exclude_inherited)
176    {
177       return delegate.lookup_name(search_name, levels_to_search, limit_type,
178                                   exclude_inherited);
179    }
180
181    public org.omg.CORBA.ContainerPackage.Description[]
182                         describe_contents(DefinitionKind JavaDoc limit_type,
183                                           boolean exclude_inherited,
184                                           int max_returned_objs)
185    {
186       return delegate.describe_contents(limit_type, exclude_inherited,
187                                         max_returned_objs);
188    }
189
190    public ModuleDef JavaDoc create_module(String JavaDoc id, String JavaDoc name, String JavaDoc version)
191    {
192       return delegate.create_module(id, name, version);
193    }
194
195    public ConstantDef JavaDoc create_constant(String JavaDoc id, String JavaDoc name, String JavaDoc version,
196                                       IDLType JavaDoc type, Any JavaDoc value)
197    {
198       return delegate.create_constant(id, name, version, type, value);
199    }
200
201    public StructDef JavaDoc create_struct(String JavaDoc id, String JavaDoc name, String JavaDoc version,
202                                   StructMember JavaDoc[] members)
203    {
204       return delegate.create_struct(id, name, version, members);
205    }
206
207    public UnionDef JavaDoc create_union(String JavaDoc id, String JavaDoc name, String JavaDoc version,
208                                 IDLType JavaDoc discriminator_type,
209                                 UnionMember JavaDoc[] members)
210    {
211       return delegate.create_union(id, name, version, discriminator_type,
212                                    members);
213    }
214
215    public EnumDef JavaDoc create_enum(String JavaDoc id, String JavaDoc name, String JavaDoc version,
216                               String JavaDoc[] members)
217    {
218       return delegate.create_enum(id, name, version, members);
219    }
220
221    public AliasDef JavaDoc create_alias(String JavaDoc id, String JavaDoc name, String JavaDoc version,
222                                 IDLType JavaDoc original_type)
223    {
224       return delegate.create_alias(id, name, version, original_type);
225    }
226
227    public InterfaceDef JavaDoc create_interface(String JavaDoc id, String JavaDoc name, String JavaDoc version,
228                                         InterfaceDef JavaDoc[] base_interfaces,
229                                         boolean is_abstract)
230    {
231       return delegate.create_interface(id, name, version,
232                                        base_interfaces, is_abstract);
233    }
234
235    public ValueDef JavaDoc create_value(String JavaDoc id, String JavaDoc name, String JavaDoc version,
236                                 boolean is_custom, boolean is_abstract,
237                                 ValueDef JavaDoc base_value, boolean is_truncatable,
238                                 ValueDef JavaDoc[] abstract_base_values,
239                                 InterfaceDef JavaDoc[] supported_interfaces,
240                                 Initializer JavaDoc[] initializers)
241    {
242       return delegate.create_value(id, name, version, is_custom, is_abstract,
243                                    base_value, is_truncatable,
244                                    abstract_base_values, supported_interfaces,
245                                    initializers);
246    }
247
248    public ValueBoxDef JavaDoc create_value_box(String JavaDoc id, String JavaDoc name, String JavaDoc version,
249                                        IDLType JavaDoc original_type_def)
250    {
251       return delegate.create_value_box(id, name, version, original_type_def);
252    }
253
254    public ExceptionDef JavaDoc create_exception(String JavaDoc id, String JavaDoc name, String JavaDoc version,
255                                         StructMember JavaDoc[] members)
256    {
257       return delegate.create_exception(id, name, version, members);
258    }
259
260    public NativeDef JavaDoc create_native(String JavaDoc id, String JavaDoc name, String JavaDoc version)
261    {
262       return delegate.create_native(id, name, version);
263    }
264
265
266    // InterfaceDefOperations implementation -------------------------
267

268    public InterfaceDef JavaDoc[] base_interfaces()
269    {
270       if (base_interfaces_ref == null) {
271          base_interfaces_ref = new InterfaceDef JavaDoc[base_interfaces.length];
272          for (int i = 0; i < base_interfaces_ref.length; ++i) {
273             logger.debug("InterfaceDefImpl.base_interfaces(): " +
274                          "looking up \"" + base_interfaces[i] + "\".");
275             Contained JavaDoc c = repository.lookup_id(base_interfaces[i]);
276             logger.debug("InterfaceDefImpl.base_interfaces(): " +
277                          "Got: " + ((c==null)? "null" : c.id()));
278             base_interfaces_ref[i] = InterfaceDefHelper.narrow(c);
279             logger.debug("InterfaceDefImpl.base_interfaces(): " +
280                          "ref: " + ((c==null)? "null" : "not null"));
281          }
282       }
283
284       return base_interfaces_ref;
285    }
286
287    public void base_interfaces(org.omg.CORBA.InterfaceDef JavaDoc[] arg)
288    {
289       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
290    }
291
292    public boolean is_abstract()
293    {
294       return false;
295    }
296
297    public void is_abstract(boolean arg)
298    {
299       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
300    }
301
302    public boolean is_a(java.lang.String JavaDoc interface_id)
303    {
304       // TODO
305
return false;
306    }
307
308    public FullInterfaceDescription describe_interface()
309    {
310       if (fullInterfaceDescription != null)
311          return fullInterfaceDescription;
312
313       // Has to create the FullInterfaceDescription
314

315       // TODO
316
OperationDescription JavaDoc[] operations = new OperationDescription JavaDoc[0];
317       AttributeDescription JavaDoc[] attributes = new AttributeDescription JavaDoc[0];
318
319       String JavaDoc defined_in_id = "IDL:Global:1.0";
320       if (defined_in instanceof org.omg.CORBA.ContainedOperations JavaDoc)
321          defined_in_id = ((org.omg.CORBA.ContainedOperations JavaDoc)defined_in).id();
322
323       fullInterfaceDescription = new FullInterfaceDescription(name, id,
324                                                               defined_in_id,
325                                                               version,
326                                                               operations,
327                                                               attributes,
328                                                               base_interfaces,
329                                                               type(),
330                                                               is_abstract);
331
332       return fullInterfaceDescription;
333    }
334
335    public AttributeDef JavaDoc create_attribute(String JavaDoc id, String JavaDoc name,
336                                         String JavaDoc version, IDLType JavaDoc type,
337                                         AttributeMode JavaDoc mode)
338    {
339       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
340    }
341
342    public OperationDef JavaDoc create_operation(String JavaDoc id, String JavaDoc name, String JavaDoc version,
343                                         IDLType JavaDoc result, OperationMode JavaDoc mode,
344                                         ParameterDescription JavaDoc[] params,
345                                         ExceptionDef JavaDoc[] exceptions,
346                                         String JavaDoc[] contexts)
347    {
348       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
349    }
350
351
352    // IDLTypeOperations implementation ------------------------------
353

354    public TypeCode JavaDoc type()
355    {
356       if (typeCode == null)
357          typeCode = getORB().create_interface_tc(id, name);
358
359       return typeCode;
360    }
361
362    // ContainedImpl implementation ----------------------------------
363

364    public Description describe()
365    {
366       String JavaDoc defined_in_id = "IR";
367  
368       if (defined_in instanceof org.omg.CORBA.ContainedOperations JavaDoc)
369          defined_in_id = ((org.omg.CORBA.ContainedOperations JavaDoc)defined_in).id();
370  
371       org.omg.CORBA.InterfaceDescription JavaDoc md =
372                    new InterfaceDescription JavaDoc(name, id, defined_in_id, version,
373                                             base_interfaces, false);
374  
375       Any JavaDoc any = getORB().create_any();
376
377       InterfaceDescriptionHelper.insert(any, md);
378
379       return new Description(DefinitionKind.dk_Interface, any);
380    }
381
382    // Y overrides ---------------------------------------------------
383

384    // Package protected ---------------------------------------------
385

386    // Protected -----------------------------------------------------
387

388    /**
389     * My CORBA reference.
390     */

391    protected InterfaceDef JavaDoc ref = null;
392
393    /**
394     * My cached TypeCode.
395     */

396    protected TypeCode JavaDoc typeCode;
397
398    // Private -------------------------------------------------------
399

400    /**
401     * My delegate for Container functionality.
402     */

403    private ContainerImplDelegate delegate;
404
405    /**
406     * Flag that I am abstract.
407     */

408    private boolean is_abstract;
409
410    /**
411     * IDs of my superinterfaces.
412     */

413    private String JavaDoc[] base_interfaces;
414
415    /**
416     * CORBA references of my superinterfaces.
417     */

418    private InterfaceDef JavaDoc[] base_interfaces_ref;
419
420    /**
421     * My cached FullInterfaceDescription.
422     */

423    private FullInterfaceDescription fullInterfaceDescription;
424
425    // Inner classes -------------------------------------------------
426
}
427
Popular Tags