KickJava   Java API By Example, From Geeks To Geeks.

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


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.ValueDef JavaDoc;
25 import org.omg.CORBA.ValueDefOperations JavaDoc;
26 import org.omg.CORBA.ValueDefPOATie;
27 import org.omg.CORBA.ValueDefHelper;
28 import org.omg.CORBA.ValueDescription JavaDoc;
29 import org.omg.CORBA.ValueDescriptionHelper;
30 import org.omg.CORBA.ValueMemberDef JavaDoc;
31 import org.omg.CORBA.ValueMember JavaDoc;
32 import org.omg.CORBA.Any JavaDoc;
33 import org.omg.CORBA.TypeCode JavaDoc;
34 import org.omg.CORBA.TypeCodePackage.BadKind JavaDoc;
35 import org.omg.CORBA.TCKind JavaDoc;
36 import org.omg.CORBA.IRObject JavaDoc;
37 import org.omg.CORBA.Contained JavaDoc;
38 import org.omg.CORBA.ContainedPackage.Description;
39 import org.omg.CORBA.DefinitionKind JavaDoc;
40 import org.omg.CORBA.IDLType JavaDoc;
41 import org.omg.CORBA.StructMember JavaDoc;
42 import org.omg.CORBA.UnionMember JavaDoc;
43 import org.omg.CORBA.ConstantDef JavaDoc;
44 import org.omg.CORBA.EnumDef JavaDoc;
45 import org.omg.CORBA.ValueBoxDef JavaDoc;
46 import org.omg.CORBA.InterfaceDef JavaDoc;
47 import org.omg.CORBA.InterfaceDefHelper;
48 import org.omg.CORBA.Initializer JavaDoc;
49 import org.omg.CORBA.StructDef JavaDoc;
50 import org.omg.CORBA.UnionDef JavaDoc;
51 import org.omg.CORBA.ModuleDef JavaDoc;
52 import org.omg.CORBA.AliasDef JavaDoc;
53 import org.omg.CORBA.NativeDef JavaDoc;
54 import org.omg.CORBA.OperationDef JavaDoc;
55 import org.omg.CORBA.OperationMode JavaDoc;
56 import org.omg.CORBA.ParameterDescription JavaDoc;
57 import org.omg.CORBA.AttributeDef JavaDoc;
58 import org.omg.CORBA.AttributeMode JavaDoc;
59 import org.omg.CORBA.ExceptionDef JavaDoc;
60 import org.omg.CORBA.OperationDescription JavaDoc;
61 import org.omg.CORBA.AttributeDescription JavaDoc;
62 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
63 import org.omg.CORBA.VM_NONE JavaDoc;
64 import org.omg.CORBA.VM_CUSTOM JavaDoc;
65 import org.omg.CORBA.VM_ABSTRACT JavaDoc;
66
67 import org.omg.CORBA.ValueDefPackage.FullValueDescription;
68
69 /**
70  * Interface IR object.
71  *
72  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
73  * @version $Revision: 37459 $
74  */

75 class ValueDefImpl
76    extends ContainedImpl
77    implements ValueDefOperations JavaDoc, LocalContainer, LocalContainedIDLType
78 {
79    // Constants -----------------------------------------------------
80

81    // Attributes ----------------------------------------------------
82

83    // Static --------------------------------------------------------
84

85    private static final org.jboss.logging.Logger logger =
86                org.jboss.logging.Logger.getLogger(ValueDefImpl.class);
87
88    // Constructors --------------------------------------------------
89

90    ValueDefImpl(String JavaDoc id, String JavaDoc name, String JavaDoc version,
91                     LocalContainer defined_in,
92                     boolean is_abstract, boolean is_custom,
93                     String JavaDoc[] supported_interfaces,
94                     String JavaDoc[] abstract_base_valuetypes,
95                     TypeCode JavaDoc baseValueTypeCode,
96                     RepositoryImpl repository)
97    {
98       super(id, name, version, defined_in,
99             DefinitionKind.dk_Value, repository);
100
101       this.is_abstract = is_abstract;
102       this.is_custom = is_custom;
103       this.supported_interfaces = supported_interfaces;
104       this.abstract_base_valuetypes = abstract_base_valuetypes;
105       this.baseValueTypeCode = baseValueTypeCode;
106       this.delegate = new ContainerImplDelegate(this);
107    }
108
109    // Public --------------------------------------------------------
110

111    // LocalContainer implementation ---------------------------------
112

113    public LocalContained _lookup(String JavaDoc search_name)
114    {
115       return delegate._lookup(search_name);
116    }
117  
118    public LocalContained[] _contents(DefinitionKind JavaDoc limit_type,
119                                      boolean exclude_inherited)
120    {
121       return delegate._contents(limit_type, exclude_inherited);
122    }
123  
124    public LocalContained[] _lookup_name(String JavaDoc search_name,
125                                         int levels_to_search,
126                                         DefinitionKind JavaDoc limit_type,
127                                         boolean exclude_inherited)
128    {
129       return delegate._lookup_name(search_name, levels_to_search, limit_type,
130                                    exclude_inherited);
131    }
132
133    public void add(String JavaDoc name, LocalContained contained)
134       throws IRConstructionException
135    {
136       delegate.add(name, contained);
137    }
138
139    // LocalIRObject implementation ---------------------------------
140

141    public IRObject JavaDoc getReference()
142    {
143       if (ref == null) {
144          ref = org.omg.CORBA.ValueDefHelper.narrow(
145                                 servantToReference(new ValueDefPOATie(this)) );
146       }
147       return ref;
148    }
149
150    public void allDone()
151       throws IRConstructionException
152    {
153       getReference();
154       delegate.allDone();
155
156       logger.debug("ValueDefImpl.allDone(): baseValueTypeCode is " +
157                    ((baseValueTypeCode==null) ? "null" : "NOT null") );
158       if (baseValueTypeCode != null)
159          logger.debug("ValueDefImpl.allDone(): " +
160                       "baseValueTypeCode.kind().value()=" +
161                       baseValueTypeCode.kind().value() );
162       if (baseValueTypeCode != null &&
163           baseValueTypeCode.kind() != TCKind.tk_null) {
164          try {
165             baseValue = baseValueTypeCode.id();
166             logger.debug("ValueDefImpl.allDone(): baseValue=\""
167                          + baseValue + "\".");
168          } catch (BadKind JavaDoc ex) {
169             throw new IRConstructionException(
170                                     "Bad kind for super-valuetype of " + id());
171          }
172          Contained JavaDoc c = repository.lookup_id(baseValue);
173          logger.debug("ValueDefImpl.allDone(): c is " +
174                       ((c==null) ? "null" : "NOT null") );
175          base_value_ref = ValueDefHelper.narrow(c);
176          logger.debug("ValueDefImpl.allDone(): base_value_ref is " +
177                       ((base_value_ref==null) ? "null" : "NOT null") );
178          //base_value_ref = ValueDefHelper.narrow(repository.lookup_id(baseValue));
179
} else
180          baseValue = "IDL:omg.org/CORBA/ValueBase:1.0"; // TODO: is this right?
181

182       // Resolve supported interfaces
183
supported_interfaces_ref = new InterfaceDef JavaDoc[supported_interfaces.length];
184       for (int i = 0; i < supported_interfaces.length; ++i) {
185          InterfaceDef JavaDoc iDef = InterfaceDefHelper.narrow(
186                                 repository.lookup_id(supported_interfaces[i]));
187          if (iDef == null)
188             throw new IRConstructionException(
189                          "ValueDef \"" + id() + "\" unable to resolve " +
190                          "reference to implemented interface \"" +
191                          supported_interfaces[i] + "\".");
192          supported_interfaces_ref[i] = iDef;
193       }
194
195       // Resolve abstract base valuetypes
196
abstract_base_valuetypes_ref =
197          new ValueDef JavaDoc[abstract_base_valuetypes.length];
198       for (int i = 0; i < abstract_base_valuetypes.length; ++i) {
199          ValueDef JavaDoc vDef = ValueDefHelper.narrow(
200                             repository.lookup_id(abstract_base_valuetypes[i]));
201          if (vDef == null)
202             throw new IRConstructionException(
203                          "ValueDef \"" + id() + "\" unable to resolve " +
204                          "reference to abstract base valuetype \"" +
205                          abstract_base_valuetypes[i] + "\".");
206          abstract_base_valuetypes_ref[i] = vDef;
207       }
208    }
209
210    public void shutdown()
211    {
212       delegate.shutdown();
213       super.shutdown();
214    }
215
216
217    // ContainerOperations implementation ----------------------------
218

219    public Contained JavaDoc lookup(String JavaDoc search_name)
220    {
221       logger.debug("ValueDefImpl.lookup(\"" + search_name + "\") entered.");
222       Contained JavaDoc res = delegate.lookup(search_name);
223       logger.debug("ValueDefImpl.lookup(\"" + search_name +
224                    "\") returning " + ((res == null) ? "null" : "non-null") );
225       return res;
226       //return delegate.lookup(search_name);
227
}
228    
229    public Contained JavaDoc[] contents(DefinitionKind JavaDoc limit_type,
230                                boolean exclude_inherited)
231    {
232       logger.debug("ValueDefImpl.contents() entered.");
233       Contained JavaDoc[] res = delegate.contents(limit_type, exclude_inherited);
234       logger.debug("ValueDefImpl.contents() " + res.length +
235                    " contained to return.");
236       for (int i = 0; i < res.length; ++i)
237          logger.debug(" ValueDefImpl.contents() [" + i + "]: " + res[i].id());
238       return res;
239       //return delegate.contents(limit_type, exclude_inherited);
240
}
241
242    public Contained JavaDoc[] lookup_name(String JavaDoc search_name, int levels_to_search,
243                                   DefinitionKind JavaDoc limit_type,
244                                   boolean exclude_inherited)
245    {
246       return delegate.lookup_name(search_name, levels_to_search, limit_type,
247                                   exclude_inherited);
248    }
249
250    public org.omg.CORBA.ContainerPackage.Description[]
251                         describe_contents(DefinitionKind JavaDoc limit_type,
252                                           boolean exclude_inherited,
253                                           int max_returned_objs)
254    {
255       return delegate.describe_contents(limit_type, exclude_inherited,
256                                         max_returned_objs);
257    }
258
259    public ModuleDef JavaDoc create_module(String JavaDoc id, String JavaDoc name, String JavaDoc version)
260    {
261       return delegate.create_module(id, name, version);
262    }
263
264    public ConstantDef JavaDoc create_constant(String JavaDoc id, String JavaDoc name, String JavaDoc version,
265                                       IDLType JavaDoc type, Any JavaDoc value)
266    {
267       return delegate.create_constant(id, name, version, type, value);
268    }
269
270    public StructDef JavaDoc create_struct(String JavaDoc id, String JavaDoc name, String JavaDoc version,
271                                   StructMember JavaDoc[] members)
272    {
273       return delegate.create_struct(id, name, version, members);
274    }
275
276    public UnionDef JavaDoc create_union(String JavaDoc id, String JavaDoc name, String JavaDoc version,
277                                 IDLType JavaDoc discriminator_type,
278                                 UnionMember JavaDoc[] members)
279    {
280       return delegate.create_union(id, name, version, discriminator_type,
281                                    members);
282    }
283
284    public EnumDef JavaDoc create_enum(String JavaDoc id, String JavaDoc name, String JavaDoc version,
285                               String JavaDoc[] members)
286    {
287       return delegate.create_enum(id, name, version, members);
288    }
289
290    public AliasDef JavaDoc create_alias(String JavaDoc id, String JavaDoc name, String JavaDoc version,
291                                 IDLType JavaDoc original_type)
292    {
293       return delegate.create_alias(id, name, version, original_type);
294    }
295
296    public InterfaceDef JavaDoc create_interface(String JavaDoc id, String JavaDoc name, String JavaDoc version,
297                                         InterfaceDef JavaDoc[] base_interfaces,
298                                         boolean is_abstract)
299    {
300       return delegate.create_interface(id, name, version,
301                                        base_interfaces, is_abstract);
302    }
303
304    public ValueDef JavaDoc create_value(String JavaDoc id, String JavaDoc name, String JavaDoc version,
305                                 boolean is_custom, boolean is_abstract,
306                                 ValueDef JavaDoc base_value, boolean is_truncatable,
307                                 ValueDef JavaDoc[] abstract_base_values,
308                                 InterfaceDef JavaDoc[] supported_interfaces,
309                                 Initializer JavaDoc[] initializers)
310    {
311       return delegate.create_value(id, name, version, is_custom, is_abstract,
312                                    base_value, is_truncatable,
313                                    abstract_base_values, supported_interfaces,
314                                    initializers);
315    }
316
317    public ValueBoxDef JavaDoc create_value_box(String JavaDoc id, String JavaDoc name, String JavaDoc version,
318                                        IDLType JavaDoc original_type_def)
319    {
320       return delegate.create_value_box(id, name, version, original_type_def);
321    }
322
323    public ExceptionDef JavaDoc create_exception(String JavaDoc id, String JavaDoc name, String JavaDoc version,
324                                         StructMember JavaDoc[] members)
325    {
326       return delegate.create_exception(id, name, version, members);
327    }
328
329    public NativeDef JavaDoc create_native(String JavaDoc id, String JavaDoc name, String JavaDoc version)
330    {
331       return delegate.create_native(id, name, version);
332    }
333
334
335    // ValueDefOperations implementation -------------------------
336

337    public InterfaceDef JavaDoc[] supported_interfaces()
338    {
339       return supported_interfaces_ref;
340    }
341
342    public void supported_interfaces(InterfaceDef JavaDoc[] arg)
343    {
344       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
345    }
346
347    public Initializer JavaDoc[] initializers()
348    {
349       // We do not (currently) map constructors, as that is optional according
350
// to the specification.
351
return new Initializer JavaDoc[0];
352    }
353
354    public void initializers(Initializer JavaDoc[] arg)
355    {
356       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
357    }
358
359    public ValueDef JavaDoc base_value()
360    {
361       logger.debug("ValueDefImpl[" + id + "].base_value() entered.");
362       if (base_value_ref == null)
363          logger.debug("ValueDefImpl[" + id + "].base_value() returning NULL.");
364       else
365          logger.debug("ValueDefImpl[" + id + "].base_value() returning \"" +
366                       base_value_ref.id() + "\".");
367       return base_value_ref;
368    }
369
370    public void base_value(ValueDef JavaDoc arg)
371    {
372       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
373    }
374
375    public ValueDef JavaDoc[] abstract_base_values()
376    {
377       return abstract_base_valuetypes_ref;
378    }
379
380    public void abstract_base_values(ValueDef JavaDoc[] arg)
381    {
382       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
383    }
384
385    public boolean is_abstract()
386    {
387       return is_abstract;
388    }
389
390    public void is_abstract(boolean arg)
391    {
392       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
393    }
394
395    public boolean is_custom()
396    {
397       return is_custom;
398    }
399
400    public void is_custom(boolean arg)
401    {
402       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
403    }
404
405    public boolean is_truncatable()
406    {
407       return false;
408    }
409
410    public void is_truncatable(boolean arg)
411    {
412       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
413    }
414
415    public boolean is_a(String JavaDoc id)
416    {
417       // TODO
418
return id().equals(id);
419    }
420
421    public FullValueDescription describe_value()
422    {
423       if (fullValueDescription != null)
424          return fullValueDescription;
425
426       // Has to create the FullValueDescription
427

428       // TODO
429
OperationDescription JavaDoc[] operations = new OperationDescription JavaDoc[0];
430       AttributeDescription JavaDoc[] attributes = new AttributeDescription JavaDoc[0];
431
432       String JavaDoc defined_in_id = "IDL:Global:1.0";
433       if (defined_in instanceof org.omg.CORBA.ContainedOperations JavaDoc)
434          defined_in_id = ((org.omg.CORBA.ContainedOperations JavaDoc)defined_in).id();
435
436       fullValueDescription = new FullValueDescription(name, id,
437                                                  is_abstract, is_custom,
438                                                  defined_in_id, version,
439                                                  operations, attributes,
440                                                  getValueMembers(),
441                                                  new Initializer JavaDoc[0], // TODO
442
supported_interfaces,
443                                                  abstract_base_valuetypes,
444                                                  false,
445                                                  baseValue,
446                                                  typeCode);
447
448       return fullValueDescription;
449    }
450
451    public ValueMemberDef JavaDoc create_value_member(String JavaDoc id, String JavaDoc name,
452                                              String JavaDoc version, IDLType JavaDoc type,
453                                              short access)
454    {
455       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
456    }
457
458    public AttributeDef JavaDoc create_attribute(String JavaDoc id, String JavaDoc name, String JavaDoc version,
459                                         IDLType JavaDoc type, AttributeMode JavaDoc mode)
460    {
461       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
462    }
463
464    public OperationDef JavaDoc create_operation(String JavaDoc id, String JavaDoc name, String JavaDoc version,
465                                         IDLType JavaDoc result, OperationMode JavaDoc mode,
466                                         ParameterDescription JavaDoc[] params,
467                                         ExceptionDef JavaDoc[] exceptions,
468                                         String JavaDoc[] contexts)
469    {
470       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
471    }
472
473
474    // IDLTypeOperations implementation ------------------------------
475

476    public TypeCode JavaDoc type()
477    {
478       logger.debug("ValueDefImpl.type() entered.");
479       if (typeCode == null) {
480          short modifier = VM_NONE.value;
481          if (is_custom)
482             modifier = VM_CUSTOM.value;
483          else if (is_abstract)
484             modifier = VM_ABSTRACT.value;
485
486          typeCode = getORB().create_value_tc(id, name, modifier,
487                                              baseValueTypeCode,
488                                              getValueMembersForTypeCode());
489       }
490       logger.debug("ValueDefImpl.type() returning.");
491       return typeCode;
492    }
493
494
495    // ContainedImpl implementation ----------------------------------
496

497    public Description JavaDoc describe()
498    {
499       String JavaDoc defined_in_id = "IR";
500  
501       if (defined_in instanceof org.omg.CORBA.ContainedOperations JavaDoc)
502          defined_in_id = ((org.omg.CORBA.ContainedOperations JavaDoc)defined_in).id();
503  
504       ValueDescription JavaDoc md = new ValueDescription JavaDoc(name, id, is_abstract,
505                                                  is_custom,
506                                                  defined_in_id, version,
507                                                  supported_interfaces,
508                                                  abstract_base_valuetypes,
509                                                  false,
510                                                  baseValue);
511  
512       Any JavaDoc any = getORB().create_any();
513
514       ValueDescriptionHelper.insert(any, md);
515
516       return new Description JavaDoc(DefinitionKind.dk_Value, any);
517    }
518
519    // Y overrides ---------------------------------------------------
520

521    // Package protected ---------------------------------------------
522

523    // Protected -----------------------------------------------------
524

525    // Private -------------------------------------------------------
526

527    /**
528     * My delegate for Container functionality.
529     */

530    private ContainerImplDelegate delegate;
531
532    /**
533     * My CORBA reference.
534     */

535    private ValueDef JavaDoc ref = null;
536
537    /**
538     * Flag that I am abstract.
539     */

540    private boolean is_abstract;
541
542    /**
543     * Flag that I use custom marshaling.
544     */

545    private boolean is_custom;
546
547    /**
548     * IDs of my implemented interfaces.
549     */

550    private String JavaDoc[] supported_interfaces;
551
552    /**
553     * CORBA references to my implemented interfaces.
554     */

555    private InterfaceDef JavaDoc[] supported_interfaces_ref;
556
557    /**
558     * IR ID of my base value (the class I extend from).
559     */

560    private String JavaDoc baseValue;
561
562    /**
563     * TypeCode of my base value (the class I extend from).
564     */

565    private TypeCode JavaDoc baseValueTypeCode;
566
567    /**
568     * CORBA reference to my base type.
569     */

570    private ValueDef JavaDoc base_value_ref;
571
572    /**
573     * IDs of my abstract base valuetypes.
574     */

575    private String JavaDoc[] abstract_base_valuetypes;
576
577    /**
578     * CORBA references to my abstract base valuetypes.
579     */

580    private ValueDef JavaDoc[] abstract_base_valuetypes_ref;
581
582    /**
583     * My cached TypeCode.
584     */

585    private TypeCode JavaDoc typeCode;
586
587    /**
588     * My Cached ValueMember[].
589     */

590    private ValueMember JavaDoc[] valueMembers;
591
592    /**
593     * My cached FullValueDescription.
594     */

595    private FullValueDescription fullValueDescription;
596
597
598    /**
599     * Create the valueMembers array, and return it.
600     */

601    private ValueMember JavaDoc[] getValueMembers()
602    {
603       if (valueMembers != null)
604          return valueMembers;
605
606       LocalContained[] c = _contents(DefinitionKind.dk_ValueMember, false);
607       valueMembers = new ValueMember JavaDoc[c.length];
608       for (int i = 0; i < c.length; ++i) {
609          ValueMemberDefImpl vmdi = (ValueMemberDefImpl)c[i];
610
611          valueMembers[i] = new ValueMember JavaDoc(vmdi.name(), vmdi.id(),
612                                          ((LocalContained)vmdi.defined_in).id(),
613                                            vmdi.version(),
614                                            vmdi.type(), vmdi.type_def(),
615                                            vmdi.access());
616       }
617
618       return valueMembers;
619    }
620
621    /**
622     * Create a valueMembers array for TypeCode creation only, and return it.
623     */

624    private ValueMember JavaDoc[] getValueMembersForTypeCode()
625    {
626       LocalContained[] c = _contents(DefinitionKind.dk_ValueMember, false);
627       ValueMember JavaDoc[] vms = new ValueMember JavaDoc[c.length];
628       for (int i = 0; i < c.length; ++i) {
629          ValueMemberDefImpl vmdi = (ValueMemberDefImpl)c[i];
630
631          vms[i] = new ValueMember JavaDoc(vmdi.name(),
632                                   null, // ignore id
633
null, // ignore defined_in
634
null, // ignore version
635
vmdi.type(),
636                                   null, // ignore type_def
637
vmdi.access());
638       }
639
640       return vms;
641    }
642
643    // Inner classes -------------------------------------------------
644
}
645
Popular Tags