001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.rmi.ir;
023:
024: import org.omg.CORBA.ValueDef;
025: import org.omg.CORBA.ValueDefOperations;
026: import org.omg.CORBA.ValueDefPOATie;
027: import org.omg.CORBA.ValueDefHelper;
028: import org.omg.CORBA.ValueDescription;
029: import org.omg.CORBA.ValueDescriptionHelper;
030: import org.omg.CORBA.ValueMemberDef;
031: import org.omg.CORBA.ValueMember;
032: import org.omg.CORBA.ValueMemberHelper;
033: import org.omg.CORBA.Any;
034: import org.omg.CORBA.TypeCode;
035: import org.omg.CORBA.TypeCodePackage.BadKind;
036: import org.omg.CORBA.TCKind;
037: import org.omg.CORBA.IRObject;
038: import org.omg.CORBA.Contained;
039: import org.omg.CORBA.ContainedPackage.Description;
040: import org.omg.CORBA.Container;
041: import org.omg.CORBA.DefinitionKind;
042: import org.omg.CORBA.IDLType;
043: import org.omg.CORBA.StructMember;
044: import org.omg.CORBA.UnionMember;
045: import org.omg.CORBA.ValueDef;
046: import org.omg.CORBA.ConstantDef;
047: import org.omg.CORBA.EnumDef;
048: import org.omg.CORBA.ValueBoxDef;
049: import org.omg.CORBA.InterfaceDef;
050: import org.omg.CORBA.InterfaceDefHelper;
051: import org.omg.CORBA.Initializer;
052: import org.omg.CORBA.StructDef;
053: import org.omg.CORBA.UnionDef;
054: import org.omg.CORBA.ModuleDef;
055: import org.omg.CORBA.AliasDef;
056: import org.omg.CORBA.NativeDef;
057: import org.omg.CORBA.OperationDef;
058: import org.omg.CORBA.OperationMode;
059: import org.omg.CORBA.ParameterDescription;
060: import org.omg.CORBA.AttributeDef;
061: import org.omg.CORBA.AttributeMode;
062: import org.omg.CORBA.ExceptionDef;
063: import org.omg.CORBA.OperationDescription;
064: import org.omg.CORBA.AttributeDescription;
065: import org.omg.CORBA.InterfaceDescription;
066: import org.omg.CORBA.InterfaceDescriptionHelper;
067: import org.omg.CORBA.BAD_INV_ORDER;
068: import org.omg.CORBA.VM_NONE;
069: import org.omg.CORBA.VM_CUSTOM;
070: import org.omg.CORBA.VM_ABSTRACT;
071:
072: import org.omg.PortableServer.POA;
073: import org.omg.CORBA.ValueDefPackage.FullValueDescription;
074:
075: /**
076: * Interface IR object.
077: *
078: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
079: * @version $Revision: 57194 $
080: */
081: class ValueDefImpl extends ContainedImpl implements ValueDefOperations,
082: LocalContainer, LocalContainedIDLType {
083: // Constants -----------------------------------------------------
084:
085: // Attributes ----------------------------------------------------
086:
087: // Static --------------------------------------------------------
088:
089: private static final org.jboss.logging.Logger logger = org.jboss.logging.Logger
090: .getLogger(ValueDefImpl.class);
091:
092: // Constructors --------------------------------------------------
093:
094: ValueDefImpl(String id, String name, String version,
095: LocalContainer defined_in, boolean is_abstract,
096: boolean is_custom, String[] supported_interfaces,
097: String[] abstract_base_valuetypes,
098: TypeCode baseValueTypeCode, RepositoryImpl repository) {
099: super (id, name, version, defined_in, DefinitionKind.dk_Value,
100: repository);
101:
102: this .is_abstract = is_abstract;
103: this .is_custom = is_custom;
104: this .supported_interfaces = supported_interfaces;
105: this .abstract_base_valuetypes = abstract_base_valuetypes;
106: this .baseValueTypeCode = baseValueTypeCode;
107: this .delegate = new ContainerImplDelegate(this );
108: }
109:
110: // Public --------------------------------------------------------
111:
112: // LocalContainer implementation ---------------------------------
113:
114: public LocalContained _lookup(String search_name) {
115: return delegate._lookup(search_name);
116: }
117:
118: public LocalContained[] _contents(DefinitionKind limit_type,
119: boolean exclude_inherited) {
120: return delegate._contents(limit_type, exclude_inherited);
121: }
122:
123: public LocalContained[] _lookup_name(String search_name,
124: int levels_to_search, DefinitionKind limit_type,
125: boolean exclude_inherited) {
126: return delegate._lookup_name(search_name, levels_to_search,
127: limit_type, exclude_inherited);
128: }
129:
130: public void add(String name, LocalContained contained)
131: throws IRConstructionException {
132: delegate.add(name, contained);
133: }
134:
135: // LocalIRObject implementation ---------------------------------
136:
137: public IRObject getReference() {
138: if (ref == null) {
139: ref = org.omg.CORBA.ValueDefHelper
140: .narrow(servantToReference(new ValueDefPOATie(this )));
141: }
142: return ref;
143: }
144:
145: public void allDone() throws IRConstructionException {
146: getReference();
147: delegate.allDone();
148:
149: logger.debug("ValueDefImpl.allDone(): baseValueTypeCode is "
150: + ((baseValueTypeCode == null) ? "null" : "NOT null"));
151: if (baseValueTypeCode != null)
152: logger.debug("ValueDefImpl.allDone(): "
153: + "baseValueTypeCode.kind().value()="
154: + baseValueTypeCode.kind().value());
155: if (baseValueTypeCode != null
156: && baseValueTypeCode.kind() != TCKind.tk_null) {
157: try {
158: baseValue = baseValueTypeCode.id();
159: logger.debug("ValueDefImpl.allDone(): baseValue=\""
160: + baseValue + "\".");
161: } catch (BadKind ex) {
162: throw new IRConstructionException(
163: "Bad kind for super-valuetype of " + id());
164: }
165: Contained c = repository.lookup_id(baseValue);
166: logger.debug("ValueDefImpl.allDone(): c is "
167: + ((c == null) ? "null" : "NOT null"));
168: base_value_ref = ValueDefHelper.narrow(c);
169: logger.debug("ValueDefImpl.allDone(): base_value_ref is "
170: + ((base_value_ref == null) ? "null" : "NOT null"));
171: //base_value_ref = ValueDefHelper.narrow(repository.lookup_id(baseValue));
172: } else
173: baseValue = "IDL:omg.org/CORBA/ValueBase:1.0"; // TODO: is this right?
174:
175: // Resolve supported interfaces
176: supported_interfaces_ref = new InterfaceDef[supported_interfaces.length];
177: for (int i = 0; i < supported_interfaces.length; ++i) {
178: InterfaceDef iDef = InterfaceDefHelper.narrow(repository
179: .lookup_id(supported_interfaces[i]));
180: if (iDef == null)
181: throw new IRConstructionException("ValueDef \"" + id()
182: + "\" unable to resolve "
183: + "reference to implemented interface \""
184: + supported_interfaces[i] + "\".");
185: supported_interfaces_ref[i] = iDef;
186: }
187:
188: // Resolve abstract base valuetypes
189: abstract_base_valuetypes_ref = new ValueDef[abstract_base_valuetypes.length];
190: for (int i = 0; i < abstract_base_valuetypes.length; ++i) {
191: ValueDef vDef = ValueDefHelper.narrow(repository
192: .lookup_id(abstract_base_valuetypes[i]));
193: if (vDef == null)
194: throw new IRConstructionException("ValueDef \"" + id()
195: + "\" unable to resolve "
196: + "reference to abstract base valuetype \""
197: + abstract_base_valuetypes[i] + "\".");
198: abstract_base_valuetypes_ref[i] = vDef;
199: }
200: }
201:
202: public void shutdown() {
203: delegate.shutdown();
204: super .shutdown();
205: }
206:
207: // ContainerOperations implementation ----------------------------
208:
209: public Contained lookup(String search_name) {
210: logger.debug("ValueDefImpl.lookup(\"" + search_name
211: + "\") entered.");
212: Contained res = delegate.lookup(search_name);
213: logger.debug("ValueDefImpl.lookup(\"" + search_name
214: + "\") returning "
215: + ((res == null) ? "null" : "non-null"));
216: return res;
217: //return delegate.lookup(search_name);
218: }
219:
220: public Contained[] contents(DefinitionKind limit_type,
221: boolean exclude_inherited) {
222: logger.debug("ValueDefImpl.contents() entered.");
223: Contained[] res = delegate.contents(limit_type,
224: exclude_inherited);
225: logger.debug("ValueDefImpl.contents() " + res.length
226: + " contained to return.");
227: for (int i = 0; i < res.length; ++i)
228: logger.debug(" ValueDefImpl.contents() [" + i + "]: "
229: + res[i].id());
230: return res;
231: //return delegate.contents(limit_type, exclude_inherited);
232: }
233:
234: public Contained[] lookup_name(String search_name,
235: int levels_to_search, DefinitionKind limit_type,
236: boolean exclude_inherited) {
237: return delegate.lookup_name(search_name, levels_to_search,
238: limit_type, exclude_inherited);
239: }
240:
241: public org.omg.CORBA.ContainerPackage.Description[] describe_contents(
242: DefinitionKind limit_type, boolean exclude_inherited,
243: int max_returned_objs) {
244: return delegate.describe_contents(limit_type,
245: exclude_inherited, max_returned_objs);
246: }
247:
248: public ModuleDef create_module(String id, String name,
249: String version) {
250: return delegate.create_module(id, name, version);
251: }
252:
253: public ConstantDef create_constant(String id, String name,
254: String version, IDLType type, Any value) {
255: return delegate.create_constant(id, name, version, type, value);
256: }
257:
258: public StructDef create_struct(String id, String name,
259: String version, StructMember[] members) {
260: return delegate.create_struct(id, name, version, members);
261: }
262:
263: public UnionDef create_union(String id, String name,
264: String version, IDLType discriminator_type,
265: UnionMember[] members) {
266: return delegate.create_union(id, name, version,
267: discriminator_type, members);
268: }
269:
270: public EnumDef create_enum(String id, String name, String version,
271: String[] members) {
272: return delegate.create_enum(id, name, version, members);
273: }
274:
275: public AliasDef create_alias(String id, String name,
276: String version, IDLType original_type) {
277: return delegate.create_alias(id, name, version, original_type);
278: }
279:
280: public InterfaceDef create_interface(String id, String name,
281: String version, InterfaceDef[] base_interfaces,
282: boolean is_abstract) {
283: return delegate.create_interface(id, name, version,
284: base_interfaces, is_abstract);
285: }
286:
287: public ValueDef create_value(String id, String name,
288: String version, boolean is_custom, boolean is_abstract,
289: ValueDef base_value, boolean is_truncatable,
290: ValueDef[] abstract_base_values,
291: InterfaceDef[] supported_interfaces,
292: Initializer[] initializers) {
293: return delegate.create_value(id, name, version, is_custom,
294: is_abstract, base_value, is_truncatable,
295: abstract_base_values, supported_interfaces,
296: initializers);
297: }
298:
299: public ValueBoxDef create_value_box(String id, String name,
300: String version, IDLType original_type_def) {
301: return delegate.create_value_box(id, name, version,
302: original_type_def);
303: }
304:
305: public ExceptionDef create_exception(String id, String name,
306: String version, StructMember[] members) {
307: return delegate.create_exception(id, name, version, members);
308: }
309:
310: public NativeDef create_native(String id, String name,
311: String version) {
312: return delegate.create_native(id, name, version);
313: }
314:
315: // ValueDefOperations implementation -------------------------
316:
317: public InterfaceDef[] supported_interfaces() {
318: return supported_interfaces_ref;
319: }
320:
321: public void supported_interfaces(InterfaceDef[] arg) {
322: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
323: }
324:
325: public Initializer[] initializers() {
326: // We do not (currently) map constructors, as that is optional according
327: // to the specification.
328: return new Initializer[0];
329: }
330:
331: public void initializers(Initializer[] arg) {
332: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
333: }
334:
335: public ValueDef base_value() {
336: logger.debug("ValueDefImpl[" + id + "].base_value() entered.");
337: if (base_value_ref == null)
338: logger.debug("ValueDefImpl[" + id
339: + "].base_value() returning NULL.");
340: else
341: logger.debug("ValueDefImpl[" + id
342: + "].base_value() returning \""
343: + base_value_ref.id() + "\".");
344: return base_value_ref;
345: }
346:
347: public void base_value(ValueDef arg) {
348: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
349: }
350:
351: public ValueDef[] abstract_base_values() {
352: return abstract_base_valuetypes_ref;
353: }
354:
355: public void abstract_base_values(ValueDef[] arg) {
356: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
357: }
358:
359: public boolean is_abstract() {
360: return is_abstract;
361: }
362:
363: public void is_abstract(boolean arg) {
364: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
365: }
366:
367: public boolean is_custom() {
368: return is_custom;
369: }
370:
371: public void is_custom(boolean arg) {
372: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
373: }
374:
375: public boolean is_truncatable() {
376: return false;
377: }
378:
379: public void is_truncatable(boolean arg) {
380: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
381: }
382:
383: public boolean is_a(String id) {
384: // TODO
385: return id().equals(id);
386: }
387:
388: public FullValueDescription describe_value() {
389: if (fullValueDescription != null)
390: return fullValueDescription;
391:
392: // Has to create the FullValueDescription
393:
394: // TODO
395: OperationDescription[] operations = new OperationDescription[0];
396: AttributeDescription[] attributes = new AttributeDescription[0];
397:
398: String defined_in_id = "IDL:Global:1.0";
399: if (defined_in instanceof org.omg.CORBA.ContainedOperations)
400: defined_in_id = ((org.omg.CORBA.ContainedOperations) defined_in)
401: .id();
402:
403: fullValueDescription = new FullValueDescription(name, id,
404: is_abstract, is_custom, defined_in_id, version,
405: operations, attributes,
406: getValueMembers(),
407: new Initializer[0], // TODO
408: supported_interfaces, abstract_base_valuetypes, false,
409: baseValue, typeCode);
410:
411: return fullValueDescription;
412: }
413:
414: public ValueMemberDef create_value_member(String id, String name,
415: String version, IDLType type, short access) {
416: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
417: }
418:
419: public AttributeDef create_attribute(String id, String name,
420: String version, IDLType type, AttributeMode mode) {
421: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
422: }
423:
424: public OperationDef create_operation(String id, String name,
425: String version, IDLType result, OperationMode mode,
426: ParameterDescription[] params, ExceptionDef[] exceptions,
427: String[] contexts) {
428: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
429: }
430:
431: // IDLTypeOperations implementation ------------------------------
432:
433: public TypeCode type() {
434: logger.debug("ValueDefImpl.type() entered.");
435: if (typeCode == null) {
436: short modifier = VM_NONE.value;
437: if (is_custom)
438: modifier = VM_CUSTOM.value;
439: else if (is_abstract)
440: modifier = VM_ABSTRACT.value;
441:
442: typeCode = getORB().create_value_tc(id, name, modifier,
443: baseValueTypeCode, getValueMembersForTypeCode());
444: }
445: logger.debug("ValueDefImpl.type() returning.");
446: return typeCode;
447: }
448:
449: // ContainedImpl implementation ----------------------------------
450:
451: public Description describe() {
452: String defined_in_id = "IR";
453:
454: if (defined_in instanceof org.omg.CORBA.ContainedOperations)
455: defined_in_id = ((org.omg.CORBA.ContainedOperations) defined_in)
456: .id();
457:
458: ValueDescription md = new ValueDescription(name, id,
459: is_abstract, is_custom, defined_in_id, version,
460: supported_interfaces, abstract_base_valuetypes, false,
461: baseValue);
462:
463: Any any = getORB().create_any();
464:
465: ValueDescriptionHelper.insert(any, md);
466:
467: return new Description(DefinitionKind.dk_Value, any);
468: }
469:
470: // Y overrides ---------------------------------------------------
471:
472: // Package protected ---------------------------------------------
473:
474: // Protected -----------------------------------------------------
475:
476: // Private -------------------------------------------------------
477:
478: /**
479: * My delegate for Container functionality.
480: */
481: private ContainerImplDelegate delegate;
482:
483: /**
484: * My CORBA reference.
485: */
486: private ValueDef ref = null;
487:
488: /**
489: * Flag that I am abstract.
490: */
491: private boolean is_abstract;
492:
493: /**
494: * Flag that I use custom marshaling.
495: */
496: private boolean is_custom;
497:
498: /**
499: * IDs of my implemented interfaces.
500: */
501: private String[] supported_interfaces;
502:
503: /**
504: * CORBA references to my implemented interfaces.
505: */
506: private InterfaceDef[] supported_interfaces_ref;
507:
508: /**
509: * IR ID of my base value (the class I extend from).
510: */
511: private String baseValue;
512:
513: /**
514: * TypeCode of my base value (the class I extend from).
515: */
516: private TypeCode baseValueTypeCode;
517:
518: /**
519: * CORBA reference to my base type.
520: */
521: private ValueDef base_value_ref;
522:
523: /**
524: * IDs of my abstract base valuetypes.
525: */
526: private String[] abstract_base_valuetypes;
527:
528: /**
529: * CORBA references to my abstract base valuetypes.
530: */
531: private ValueDef[] abstract_base_valuetypes_ref;
532:
533: /**
534: * My cached TypeCode.
535: */
536: private TypeCode typeCode;
537:
538: /**
539: * My Cached ValueMember[].
540: */
541: private ValueMember[] valueMembers;
542:
543: /**
544: * My cached FullValueDescription.
545: */
546: private FullValueDescription fullValueDescription;
547:
548: /**
549: * Create the valueMembers array, and return it.
550: */
551: private ValueMember[] getValueMembers() {
552: if (valueMembers != null)
553: return valueMembers;
554:
555: LocalContained[] c = _contents(DefinitionKind.dk_ValueMember,
556: false);
557: valueMembers = new ValueMember[c.length];
558: for (int i = 0; i < c.length; ++i) {
559: ValueMemberDefImpl vmdi = (ValueMemberDefImpl) c[i];
560:
561: valueMembers[i] = new ValueMember(vmdi.name(), vmdi.id(),
562: ((LocalContained) vmdi.defined_in).id(), vmdi
563: .version(), vmdi.type(), vmdi.type_def(),
564: vmdi.access());
565: }
566:
567: return valueMembers;
568: }
569:
570: /**
571: * Create a valueMembers array for TypeCode creation only, and return it.
572: */
573: private ValueMember[] getValueMembersForTypeCode() {
574: LocalContained[] c = _contents(DefinitionKind.dk_ValueMember,
575: false);
576: ValueMember[] vms = new ValueMember[c.length];
577: for (int i = 0; i < c.length; ++i) {
578: ValueMemberDefImpl vmdi = (ValueMemberDefImpl) c[i];
579:
580: vms[i] = new ValueMember(vmdi.name(), null, // ignore id
581: null, // ignore defined_in
582: null, // ignore version
583: vmdi.type(), null, // ignore type_def
584: vmdi.access());
585: }
586:
587: return vms;
588: }
589:
590: // Inner classes -------------------------------------------------
591: }
|