corba/src/share/classes/com/sun/corba/se/impl/dynamicany/DynAnyComplexImpl.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.dynamicany;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import org.omg.CORBA.TCKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import org.omg.CORBA.TypeCodePackage.BadKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import org.omg.CORBA.TypeCodePackage.Bounds;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import org.omg.CORBA.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import org.omg.DynamicAny.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
abstract class DynAnyComplexImpl extends DynAnyConstructedImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
    // Instance variables
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
    String[] names = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
    // Instance variables components and names above are kept in sync
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    // with these two arrays at all times.
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    NameValuePair[] nameValuePairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
    NameDynAnyPair[] nameDynAnyPairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    // Constructors
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    private DynAnyComplexImpl() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
        this(null, (Any)null, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    protected DynAnyComplexImpl(ORB orb, Any any, boolean copyValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
        // We can be sure that typeCode is of kind tk_struct
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        super(orb, any, copyValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        // Initialize components lazily, on demand.
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        // This is an optimization in case the user is only interested in storing Anys.
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    protected DynAnyComplexImpl(ORB orb, TypeCode typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        // We can be sure that typeCode is of kind tk_struct
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        super(orb, typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
        // For DynAnyComplex, the operation sets the current position to -1
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        // for empty exceptions and to zero for all other TypeCodes.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        // The members (if any) are (recursively) initialized to their default values.
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    // DynAny interface methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    // _REVISIT_ Overridden to provide more efficient copying.
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    // Copies all the internal representations which is faster than reconstructing them.
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    public org.omg.DynamicAny.DynAny copy() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
            throw new OBJECT_NOT_EXIST();
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        DynAnyComplexImpl returnValue = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        if ((representations & REPRESENTATION_ANY) != 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
            // The flag "true" indicates copying the Any value
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            returnValue = (DynAnyComplexImpl)DynAnyUtil.createMostDerivedDynAny(any, orb, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        if ((representations & REPRESENTATION_COMPONENTS) != 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        return returnValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
*/
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    // Complex methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    public String current_member_name ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
               org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
        if( ! checkInitComponents() || index < 0 || index >= names.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        return names[index];
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    public TCKind current_member_kind ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
               org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        if( ! checkInitComponents() || index < 0 || index >= components.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
        return components[index].type().kind();
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    // Creates references to the parameter instead of copying it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    public void set_members (org.omg.DynamicAny.NameValuePair[] value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
               org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        if (value == null || value.length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        Any memberAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        DynAny memberDynAny = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        String memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        // We know that this is of kind tk_struct
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        TypeCode expectedTypeCode = any.type();
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        int expectedMemberCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            expectedMemberCount = expectedTypeCode.member_count();
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        if (expectedMemberCount != value.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        allocComponents(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        for (int i=0; i<value.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
            if (value[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
                memberName = value[i].id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
                String expectedMemberName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                    expectedMemberName = expectedTypeCode.member_name(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
                } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                    clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                    // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                    throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
                memberAny = value[i].value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                TypeCode expectedMemberType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
                    expectedMemberType = expectedTypeCode.member_type(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
                } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                if (! expectedMemberType.equal(memberAny.type())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
                    clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                    // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
                    throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                    // Creates the appropriate subtype without copying the Any
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                    memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                } catch (InconsistentTypeCode itc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                    throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                addComponent(i, memberName, memberAny, memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
                // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        index = (value.length == 0 ? NO_INDEX : 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        representations = REPRESENTATION_COMPONENTS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    // Creates references to the parameter instead of copying it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    public void set_members_as_dyn_any (org.omg.DynamicAny.NameDynAnyPair[] value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
               org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        if (value == null || value.length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
        Any memberAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        DynAny memberDynAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        String memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        // We know that this is of kind tk_struct
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        TypeCode expectedTypeCode = any.type();
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
        int expectedMemberCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
            expectedMemberCount = expectedTypeCode.member_count();
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        if (expectedMemberCount != value.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        allocComponents(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        for (int i=0; i<value.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            if (value[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
                memberName = value[i].id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
                String expectedMemberName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
                    expectedMemberName = expectedTypeCode.member_name(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
                } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
                } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
                if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                    clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
                    // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                    throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                memberDynAny = value[i].value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
                memberAny = getAny(memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
                TypeCode expectedMemberType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
                    expectedMemberType = expectedTypeCode.member_type(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
                } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
                } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
                if (! expectedMemberType.equal(memberAny.type())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
                    clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
                    // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
                    throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
                addComponent(i, memberName, memberAny, memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                // _REVISIT_ More info
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
                throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        index = (value.length == 0 ? NO_INDEX : 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        representations = REPRESENTATION_COMPONENTS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    // Utility methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    private void allocComponents(int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        components = new DynAny[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        names = new String[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        nameValuePairs = new NameValuePair[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        nameDynAnyPairs = new NameDynAnyPair[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        for (int i=0; i<length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            nameValuePairs[i] = new NameValuePair();
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
            nameDynAnyPairs[i] = new NameDynAnyPair();
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    private void allocComponents(org.omg.DynamicAny.NameValuePair[] value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        components = new DynAny[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        names = new String[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        nameValuePairs = value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        nameDynAnyPairs = new NameDynAnyPair[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
        for (int i=0; i<value.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
            nameDynAnyPairs[i] = new NameDynAnyPair();
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    private void allocComponents(org.omg.DynamicAny.NameDynAnyPair[] value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        components = new DynAny[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        names = new String[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        nameValuePairs = new NameValuePair[value.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        for (int i=0; i<value.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
            nameValuePairs[i] = new NameValuePair();
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        nameDynAnyPairs = value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    private void addComponent(int i, String memberName, Any memberAny, DynAny memberDynAny) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        components[i] = memberDynAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        names[i] = (memberName != null ? memberName : "");
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        nameValuePairs[i].id = memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        nameValuePairs[i].value = memberAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        nameDynAnyPairs[i].id = memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        nameDynAnyPairs[i].value = memberDynAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
        if (memberDynAny instanceof DynAnyImpl)
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
            ((DynAnyImpl)memberDynAny).setStatus(STATUS_UNDESTROYABLE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    // Initializes components, names, nameValuePairs and nameDynAnyPairs representation
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    // from the Any representation
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    protected boolean initializeComponentsFromAny() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        // This typeCode is of kind tk_struct.
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        TypeCode typeCode = any.type();
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        TypeCode memberType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        Any memberAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        DynAny memberDynAny = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        String memberName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        int length = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            length = typeCode.member_count();
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
        InputStream input = any.create_input_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        allocComponents(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        for (int i=0; i<length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                memberName = typeCode.member_name(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                memberType = typeCode.member_type(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
            } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            memberAny = DynAnyUtil.extractAnyFromStream(memberType, input, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                // Creates the appropriate subtype without copying the Any
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
                memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                // _DEBUG_
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
                //System.out.println("Created DynAny for " + memberName +
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
                //                   ", type " + memberType.kind().value());
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            } catch (InconsistentTypeCode itc) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
            addComponent(i, memberName, memberAny, memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
    // Initializes components, names, nameValuePairs and nameDynAnyPairs representation
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    // from the internal TypeCode information with default values
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    // This is not done recursively, only one level.
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    // More levels are initialized lazily, on demand.
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    protected boolean initializeComponentsFromTypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        // This typeCode is of kind tk_struct.
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
        TypeCode typeCode = any.type();
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
        TypeCode memberType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        Any memberAny;
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        DynAny memberDynAny = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        String memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        int length = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            length = typeCode.member_count();
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
        allocComponents(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        for (int i=0; i<length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
            memberName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
                memberName = typeCode.member_name(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
                memberType = typeCode.member_type(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            } catch (BadKind badKind) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
            } catch (Bounds bounds) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
                memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberType, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
                // _DEBUG_
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                //System.out.println("Created DynAny for " + memberName +
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                //                   ", type " + memberType.kind().value());
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
                if (memberDynAny instanceof DynAnyConstructedImpl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
                    if ( ! ((DynAnyConstructedImpl)memberDynAny).isRecursive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
                        // This is the recursive part
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
                        ((DynAnyConstructedImpl)memberDynAny).initializeComponentsFromTypeCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                } // Other implementations have their own way of dealing with implementing the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
*/
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
            } catch (InconsistentTypeCode itc) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
            // get a hold of the default initialized Any without copying
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
            memberAny = getAny(memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            addComponent(i, memberName, memberAny, memberDynAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    // It is probably right not to destroy the released component DynAnys.
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    // Some other DynAny or a user variable might still hold onto them
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
    // and if not then the garbage collector will take care of it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    protected void clearData() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        super.clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        names = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        nameValuePairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        nameDynAnyPairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
}