FileDocCategorySizeDatePackage
DynUnionImpl.javaAPI DocJava SE 5 API13811Fri Aug 26 14:54:20 BST 2005com.sun.corba.se.impl.dynamicany

DynUnionImpl

public class DynUnionImpl extends DynAnyConstructedImpl implements DynUnion

Fields Summary
DynAny
discriminator
DynAny
currentMember
int
currentMemberIndex
Constructors Summary
private DynUnionImpl()


    //
    // Constructors
    //

      
        this(null, (Any)null, false);
    
protected DynUnionImpl(com.sun.corba.se.spi.orb.ORB orb, org.omg.CORBA.Any any, boolean copyValue)

        // We can be sure that typeCode is of kind tk_union
        super(orb, any, copyValue);
    
protected DynUnionImpl(com.sun.corba.se.spi.orb.ORB orb, org.omg.CORBA.TypeCode typeCode)

        // We can be sure that typeCode is of kind tk_union
        super(orb, typeCode);
    
Methods Summary
protected voidclearData()

        super.clearData();
        discriminator = null;
        // Necessary to guarantee OBJECT_NOT_EXIST in member()
        currentMember.destroy();
        currentMember = null;
        currentMemberIndex = NO_INDEX;
    
private intcurrentUnionMemberIndex(org.omg.CORBA.Any discriminatorValue)

        int memberCount = memberCount();
        Any memberLabel;
        for (int i=0; i<memberCount; i++) {
            memberLabel = memberLabel(i);
            if (memberLabel.equal(discriminatorValue)) {
                return i;
            }
        }
        if (defaultIndex() != -1) {
            return defaultIndex();
        }
        return NO_INDEX;
    
private intdefaultIndex()

        int defaultIndex = -1;
        try {
            defaultIndex = any.type().default_index();
        } catch (BadKind bad) {
        }
        return defaultIndex;
    
private org.omg.CORBA.TypeCodediscriminatorType()

        TypeCode discriminatorType = null;
        try {
            discriminatorType = any.type().discriminator_type();
        } catch (BadKind bad) {
        }
        return discriminatorType;
    
public org.omg.CORBA.TCKinddiscriminator_kind()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        return discriminatorType().kind();
    
public org.omg.DynamicAny.DynAnyget_discriminator()
Returns the current discriminator value.

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        return (checkInitComponents() ? discriminator : null);
    
public booleanhas_no_active_member()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        // _REVISIT_ How does one check for "entire range of discriminator values"?
        if (defaultIndex() != -1) {
            return false;
        }
        checkInitComponents();
        return (checkInitComponents() ? (currentMemberIndex == NO_INDEX) : false);
    
protected booleaninitializeComponentsFromAny()

        try {
            InputStream input = any.create_input_stream();
            Any discriminatorAny = DynAnyUtil.extractAnyFromStream(discriminatorType(), input, orb);
            discriminator = DynAnyUtil.createMostDerivedDynAny(discriminatorAny, orb, false);
            currentMemberIndex = currentUnionMemberIndex(discriminatorAny);
            Any memberAny = DynAnyUtil.extractAnyFromStream(memberType(currentMemberIndex), input, orb);
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
            components = new DynAny[] {discriminator, currentMember};
        } catch (InconsistentTypeCode ictc) { // impossible
        }
        return true;
    
protected booleaninitializeComponentsFromTypeCode()

        //System.out.println(this + " initializeComponentsFromTypeCode");
        try {
            // We can be sure that memberCount() > 0 according to the IDL language spec
            discriminator = DynAnyUtil.createMostDerivedDynAny(memberLabel(0), orb, false);
            index = 0;
            currentMemberIndex = 0;
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(0), orb);
            components = new DynAny[] {discriminator, currentMember};
        } catch (InconsistentTypeCode ictc) { // impossible
        }
        return true;
    
public org.omg.DynamicAny.DynAnymember()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
            throw new InvalidValue();
        return currentMember;
    
private intmemberCount()

        int memberCount = 0;
        try {
            memberCount = any.type().member_count();
        } catch (BadKind bad) {
        }
        return memberCount;
    
private org.omg.CORBA.AnymemberLabel(int i)

        Any memberLabel = null;
        try {
            memberLabel = any.type().member_label(i);
        } catch (BadKind bad) {
        } catch (Bounds bounds) {
        }
        return memberLabel;
    
private java.lang.StringmemberName(int i)

        String memberName = null;
        try {
            memberName = any.type().member_name(i);
        } catch (BadKind bad) {
        } catch (Bounds bounds) {
        }
        return memberName;
    
private org.omg.CORBA.TypeCodememberType(int i)

        TypeCode memberType = null;
        try {
            memberType = any.type().member_type(i);
        } catch (BadKind bad) {
        } catch (Bounds bounds) {
        }
        return memberType;
    
public org.omg.CORBA.TCKindmember_kind()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
            throw new InvalidValue();
        return memberType(currentMemberIndex).kind();
    
public java.lang.Stringmember_name()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
            throw new InvalidValue();
        String memberName = memberName(currentMemberIndex);
        return (memberName == null ? "" : memberName);
    
public voidset_discriminator(org.omg.DynamicAny.DynAny newDiscriminator)

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if ( ! newDiscriminator.type().equal(discriminatorType())) {
            throw new TypeMismatch();
        }
        newDiscriminator = DynAnyUtil.convertToNative(newDiscriminator, orb);
        Any newDiscriminatorAny = getAny(newDiscriminator);
        int newCurrentMemberIndex = currentUnionMemberIndex(newDiscriminatorAny);
        if (newCurrentMemberIndex == NO_INDEX) {
            clearData();
            index = 0;
        } else {
            // _REVISIT_ Could possibly optimize here if we don't need to initialize components
            checkInitComponents();
            if (currentMemberIndex == NO_INDEX || newCurrentMemberIndex != currentMemberIndex) {
                clearData();
                index = 1;
                currentMemberIndex = newCurrentMemberIndex;
                try {
                currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(currentMemberIndex), orb);
                } catch (InconsistentTypeCode ictc) {}
                discriminator = newDiscriminator;
                components = new DynAny[] { discriminator, currentMember };
                representations = REPRESENTATION_COMPONENTS;
            }
        }
    
public voidset_to_default_member()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        int defaultIndex = defaultIndex();
        if (defaultIndex == -1) {
            throw new TypeMismatch();
        }
        try {
            clearData();
            index = 1;
            currentMemberIndex = defaultIndex;
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(defaultIndex), orb);
            components = new DynAny[] {discriminator, currentMember};
            Any discriminatorAny = orb.create_any();
            discriminatorAny.insert_octet((byte)0);
            discriminator = DynAnyUtil.createMostDerivedDynAny(discriminatorAny, orb, false);
            representations = REPRESENTATION_COMPONENTS;
        } catch (InconsistentTypeCode ictc) {}
    
public voidset_to_no_active_member()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        // _REVISIT_ How does one check for "entire range of discriminator values"?
        if (defaultIndex() != -1) {
            throw new TypeMismatch();
        }
        checkInitComponents();
        Any discriminatorAny = getAny(discriminator);
        // erase the discriminators value so that it does not correspond
        // to any of the unions case labels
        discriminatorAny.type(discriminatorAny.type());
        index = 0;
        currentMemberIndex = NO_INDEX;
        // Necessary to guarantee OBJECT_NOT_EXIST in member()
        currentMember.destroy();
        currentMember = null;
        components[0] = discriminator;
        representations = REPRESENTATION_COMPONENTS;