/* * @(#)DynSequenceImpl.java 1.8 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.Any; import org.omg.CORBA.BAD_OPERATION; import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.Bounds; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.OutputStream; 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 ; // _REVIST_ Could make this a subclass of DynArrayImpl // But that would mean that an object that implements DynSequence also implements DynArray // which the spec doesn't mention (it also doesn't forbid it). public class DynSequenceImpl extends DynAnyCollectionImpl implements DynSequence { // // Constructors // private DynSequenceImpl() { this(null, (Any)null, false); } protected DynSequenceImpl(ORB orb, Any any, boolean copyValue) { super(orb, any, copyValue); } // Sets the current position to -1 and creates an empty sequence. protected DynSequenceImpl(ORB orb, TypeCode typeCode) { super(orb, typeCode); } // Initializes components and anys representation // from the Any representation protected boolean initializeComponentsFromAny() { // This typeCode is of kind tk_sequence. TypeCode typeCode = any.type(); int length; TypeCode contentType = getContentType(); InputStream input; try { input = any.create_input_stream(); } catch (BAD_OPERATION e) { return false; } length = input.read_long(); components = new DynAny[length]; anys = new Any[length]; for (int i=0; i 0 && len > bound) { throw new InvalidValue(); } checkInitComponents(); int oldLength = components.length; if (len > oldLength) { // Increase length DynAny[] newComponents = new DynAny[len]; Any[] newAnys = new Any[len]; System.arraycopy(components, 0, newComponents, 0, oldLength); System.arraycopy(anys, 0, newAnys, 0, oldLength); components = newComponents; anys = newAnys; // Newly added elements are default-initialized TypeCode contentType = getContentType(); for (int i=oldLength; i= len) { index = NO_INDEX; } } else { // Length unchanged // Maybe components is now default initialized from type code if (index == NO_INDEX && len > 0) { index = 0; } } } // Initializes the elements of the sequence. // The length of the DynSequence is set to the length of value. // The current position is set to zero if value has non-zero length // and to -1 if value is a zero-length sequence. // If the length of value exceeds the bound of a bounded sequence, // the operation raises InvalidValue. // If value contains one or more elements whose TypeCode is not equivalent // to the element TypeCode of the DynSequence, the operation raises TypeMismatch. /* public void set_elements(org.omg.CORBA.Any[] value) throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch, org.omg.DynamicAny.DynAnyPackage.InvalidValue; */ // // Utility methods // protected void checkValue(Object[] value) throws org.omg.DynamicAny.DynAnyPackage.InvalidValue { if (value == null || value.length == 0) { clearData(); index = NO_INDEX; return; } else { index = 0; } int bound = getBound(); if (bound > 0 && value.length > bound) { throw new InvalidValue(); } } }