/* * @(#)DynAnyComplexImpl.java 1.10 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.sun.corba.se.impl.dynamicany; import org.omg.CORBA.TypeCode; import org.omg.CORBA.TCKind; import org.omg.CORBA.Any; import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.Bounds; import org.omg.CORBA.portable.InputStream; import org.omg.DynamicAny.*; import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; import org.omg.DynamicAny.DynAnyPackage.InvalidValue; import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; import com.sun.corba.se.spi.orb.ORB ; import com.sun.corba.se.spi.logging.CORBALogDomains ; import com.sun.corba.se.impl.logging.ORBUtilSystemException ; abstract class DynAnyComplexImpl extends DynAnyConstructedImpl { // // Instance variables // String[] names = null; // Instance variables components and names above are kept in sync // with these two arrays at all times. NameValuePair[] nameValuePairs = null; NameDynAnyPair[] nameDynAnyPairs = null; // // Constructors // private DynAnyComplexImpl() { this(null, (Any)null, false); } protected DynAnyComplexImpl(ORB orb, Any any, boolean copyValue) { // We can be sure that typeCode is of kind tk_struct super(orb, any, copyValue); // Initialize components lazily, on demand. // This is an optimization in case the user is only interested in storing Anys. } protected DynAnyComplexImpl(ORB orb, TypeCode typeCode) { // We can be sure that typeCode is of kind tk_struct super(orb, typeCode); // For DynAnyComplex, the operation sets the current position to -1 // for empty exceptions and to zero for all other TypeCodes. // The members (if any) are (recursively) initialized to their default values. index = 0; } // // DynAny interface methods // // _REVISIT_ Overridden to provide more efficient copying. // Copies all the internal representations which is faster than reconstructing them. /* public org.omg.DynamicAny.DynAny copy() { if (status == STATUS_DESTROYED) { throw new OBJECT_NOT_EXIST(); } DynAnyComplexImpl returnValue = null; if ((representations & REPRESENTATION_ANY) != 0) { // The flag "true" indicates copying the Any value returnValue = (DynAnyComplexImpl)DynAnyUtil.createMostDerivedDynAny(any, orb, true); } if ((representations & REPRESENTATION_COMPONENTS) != 0) { } return returnValue; } */ // // Complex methods // public String current_member_name () throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, org.omg.DynamicAny.DynAnyPackage.InvalidValue { if (status == STATUS_DESTROYED) { throw wrapper.dynAnyDestroyed() ; } if( ! checkInitComponents() || index < 0 || index >= names.length) { throw new InvalidValue(); } return names[index]; } public TCKind current_member_kind () throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, org.omg.DynamicAny.DynAnyPackage.InvalidValue { if (status == STATUS_DESTROYED) { throw wrapper.dynAnyDestroyed() ; } if( ! checkInitComponents() || index < 0 || index >= components.length) { throw new InvalidValue(); } return components[index].type().kind(); } // Creates references to the parameter instead of copying it. public void set_members (org.omg.DynamicAny.NameValuePair[] value) throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, org.omg.DynamicAny.DynAnyPackage.InvalidValue { if (status == STATUS_DESTROYED) { throw wrapper.dynAnyDestroyed() ; } if (value == null || value.length == 0) { clearData(); return; } Any memberAny; DynAny memberDynAny = null; String memberName; // We know that this is of kind tk_struct TypeCode expectedTypeCode = any.type(); int expectedMemberCount = 0; try { expectedMemberCount = expectedTypeCode.member_count(); } catch (BadKind badKind) { // impossible } if (expectedMemberCount != value.length) { clearData(); throw new InvalidValue(); } allocComponents(value); for (int i=0; i