/* * @(#)DynEnumImpl.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.INTERNAL; import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.Bounds; import org.omg.DynamicAny.*; import org.omg.DynamicAny.DynAnyPackage.*; import com.sun.corba.se.spi.orb.ORB ; import com.sun.corba.se.spi.logging.CORBALogDomains ; import com.sun.corba.se.impl.logging.ORBUtilSystemException ; public class DynEnumImpl extends DynAnyBasicImpl implements DynEnum { // // Instance variables // // This int and the any value are kept in sync at all times int currentEnumeratorIndex = NO_INDEX; // // Constructors // private DynEnumImpl() { this(null, (Any)null, false); } // The current position of a DynEnum is always -1. protected DynEnumImpl(ORB orb, Any anAny, boolean copyValue) { super(orb, anAny, copyValue); index = NO_INDEX; // The any doesn't have to be initialized. We have a default value in this case. try { currentEnumeratorIndex = any.extract_long(); } catch (BAD_OPERATION e) { // _REVISIT_: Fix Me currentEnumeratorIndex = 0; any.type(any.type()); any.insert_long(0); } } // Sets the current position to -1 and sets the value of the enumerator // to the first enumerator value indicated by the TypeCode. protected DynEnumImpl(ORB orb, TypeCode typeCode) { super(orb, typeCode); index = NO_INDEX; currentEnumeratorIndex = 0; any.insert_long(0); } // // Utility methods // private int memberCount() { int memberCount = 0; try { memberCount = any.type().member_count(); } catch (BadKind bad) { } return memberCount; } private String memberName(int i) { String memberName = null; try { memberName = any.type().member_name(i); } catch (BadKind bad) { } catch (Bounds bounds) { } return memberName; } private int computeCurrentEnumeratorIndex(String value) { int memberCount = memberCount(); for (int i=0; i= memberCount()) { throw new InvalidValue(); } currentEnumeratorIndex = value; any.insert_long(value); } }