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

DynAnyComplexImpl

public abstract class DynAnyComplexImpl extends DynAnyConstructedImpl

Fields Summary
String[]
names
NameValuePair[]
nameValuePairs
NameDynAnyPair[]
nameDynAnyPairs
Constructors Summary
private DynAnyComplexImpl()


    //
    // Constructors
    //

      
        this(null, (Any)null, false);
    
protected DynAnyComplexImpl(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_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(com.sun.corba.se.spi.orb.ORB orb, org.omg.CORBA.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;
    
Methods Summary
private voidaddComponent(int i, java.lang.String memberName, org.omg.CORBA.Any memberAny, DynAny memberDynAny)

        components[i] = memberDynAny;
        names[i] = (memberName != null ? memberName : "");
        nameValuePairs[i].id = memberName;
        nameValuePairs[i].value = memberAny;
        nameDynAnyPairs[i].id = memberName;
        nameDynAnyPairs[i].value = memberDynAny;
        if (memberDynAny instanceof DynAnyImpl)
            ((DynAnyImpl)memberDynAny).setStatus(STATUS_UNDESTROYABLE);
    
private voidallocComponents(org.omg.DynamicAny.NameDynAnyPair[] value)

        components = new DynAny[value.length];
        names = new String[value.length];
        nameValuePairs = new NameValuePair[value.length];
        for (int i=0; i<value.length; i++) {
            nameValuePairs[i] = new NameValuePair();
        }
        nameDynAnyPairs = value;
    
private voidallocComponents(int length)

        components = new DynAny[length];
        names = new String[length];
        nameValuePairs = new NameValuePair[length];
        nameDynAnyPairs = new NameDynAnyPair[length];
        for (int i=0; i<length; i++) {
            nameValuePairs[i] = new NameValuePair();
            nameDynAnyPairs[i] = new NameDynAnyPair();
        }
    
private voidallocComponents(org.omg.DynamicAny.NameValuePair[] value)

        components = new DynAny[value.length];
        names = new String[value.length];
        nameValuePairs = value;
        nameDynAnyPairs = new NameDynAnyPair[value.length];
        for (int i=0; i<value.length; i++) {
            nameDynAnyPairs[i] = new NameDynAnyPair();
        }
    
protected voidclearData()

        super.clearData();
        names = null;
        nameValuePairs = null;
        nameDynAnyPairs = null;
    
public org.omg.CORBA.TCKindcurrent_member_kind()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if( ! checkInitComponents() || index < 0 || index >= components.length) {
            throw new InvalidValue();
        }
        return components[index].type().kind();
    
public java.lang.Stringcurrent_member_name()

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if( ! checkInitComponents() || index < 0 || index >= names.length) {
            throw new InvalidValue();
        }
        return names[index];
    
protected booleaninitializeComponentsFromAny()

        // This typeCode is of kind tk_struct.
        TypeCode typeCode = any.type();
        TypeCode memberType = null;
        Any memberAny;
        DynAny memberDynAny = null;
        String memberName = null;
        int length = 0;

        try {
            length = typeCode.member_count();
        } catch (BadKind badKind) { // impossible
        }

        InputStream input = any.create_input_stream();

        allocComponents(length);

        for (int i=0; i<length; i++) {
            try {
                memberName = typeCode.member_name(i);
                memberType = typeCode.member_type(i);
            } catch (BadKind badKind) { // impossible
            } catch (Bounds bounds) { // impossible
            }
            memberAny = DynAnyUtil.extractAnyFromStream(memberType, input, orb);
            try {
                // Creates the appropriate subtype without copying the Any
                memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
                // _DEBUG_
                //System.out.println("Created DynAny for " + memberName +
                //                   ", type " + memberType.kind().value());
            } catch (InconsistentTypeCode itc) { // impossible
            }
            addComponent(i, memberName, memberAny, memberDynAny);
        }
        return true;
    
protected booleaninitializeComponentsFromTypeCode()

        // This typeCode is of kind tk_struct.
        TypeCode typeCode = any.type();
        TypeCode memberType = null;
        Any memberAny;
        DynAny memberDynAny = null;
        String memberName;
        int length = 0;

        try {
            length = typeCode.member_count();
        } catch (BadKind badKind) { // impossible
        }

        allocComponents(length);

        for (int i=0; i<length; i++) {
            memberName = null;
            try {
                memberName = typeCode.member_name(i);
                memberType = typeCode.member_type(i);
            } catch (BadKind badKind) { // impossible
            } catch (Bounds bounds) { // impossible
            }
            try {
                memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberType, orb);
                // _DEBUG_
                //System.out.println("Created DynAny for " + memberName +
                //                   ", type " + memberType.kind().value());
/*
                if (memberDynAny instanceof DynAnyConstructedImpl) {
                    if ( ! ((DynAnyConstructedImpl)memberDynAny).isRecursive()) {
                        // This is the recursive part
                        ((DynAnyConstructedImpl)memberDynAny).initializeComponentsFromTypeCode();
                    }
                } // Other implementations have their own way of dealing with implementing the spec.
*/
            } catch (InconsistentTypeCode itc) { // impossible
            }
            // get a hold of the default initialized Any without copying
            memberAny = getAny(memberDynAny);
            addComponent(i, memberName, memberAny, memberDynAny);
        }
        return true;
    
public voidset_members(org.omg.DynamicAny.NameValuePair[] value)

        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<value.length; i++) {
            if (value[i] != null) {
                memberName = value[i].id;
                String expectedMemberName = null;
                try {
                    expectedMemberName = expectedTypeCode.member_name(i);
                } catch (BadKind badKind) { // impossible
                } catch (Bounds bounds) { // impossible
                }
                if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) {
                    clearData();
                    // _REVISIT_ More info
                    throw new TypeMismatch();
                }
                memberAny = value[i].value;
                TypeCode expectedMemberType = null;
                try {
                    expectedMemberType = expectedTypeCode.member_type(i);
                } catch (BadKind badKind) { // impossible
                } catch (Bounds bounds) { // impossible
                }
                if (! expectedMemberType.equal(memberAny.type())) {
                    clearData();
                    // _REVISIT_ More info
                    throw new TypeMismatch();
                }
                try {
                    // Creates the appropriate subtype without copying the Any
                    memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
                } catch (InconsistentTypeCode itc) {
                    throw new InvalidValue();
                }
                addComponent(i, memberName, memberAny, memberDynAny);
            } else {
                clearData();
                // _REVISIT_ More info
                throw new InvalidValue();
            }
        }
        index = (value.length == 0 ? NO_INDEX : 0);
        representations = REPRESENTATION_COMPONENTS;
    
public voidset_members_as_dyn_any(org.omg.DynamicAny.NameDynAnyPair[] value)

        if (status == STATUS_DESTROYED) {
	    throw wrapper.dynAnyDestroyed() ;
        }
        if (value == null || value.length == 0) {
            clearData();
            return;
        }

        Any memberAny;
        DynAny memberDynAny;
        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<value.length; i++) {
            if (value[i] != null) {
                memberName = value[i].id;
                String expectedMemberName = null;
                try {
                    expectedMemberName = expectedTypeCode.member_name(i);
                } catch (BadKind badKind) { // impossible
                } catch (Bounds bounds) { // impossible
                }
                if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) {
                    clearData();
                    // _REVISIT_ More info
                    throw new TypeMismatch();
                }
                memberDynAny = value[i].value;
                memberAny = getAny(memberDynAny);
                TypeCode expectedMemberType = null;
                try {
                    expectedMemberType = expectedTypeCode.member_type(i);
                } catch (BadKind badKind) { // impossible
                } catch (Bounds bounds) { // impossible
                }
                if (! expectedMemberType.equal(memberAny.type())) {
                    clearData();
                    // _REVISIT_ More info
                    throw new TypeMismatch();
                }

                addComponent(i, memberName, memberAny, memberDynAny);
            } else {
                clearData();
                // _REVISIT_ More info
                throw new InvalidValue();
            }
        }
        index = (value.length == 0 ? NO_INDEX : 0);
        representations = REPRESENTATION_COMPONENTS;