corba/src/share/classes/com/sun/corba/se/impl/dynamicany/DynUnionImpl.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
public class DynUnionImpl extends DynAnyConstructedImpl implements DynUnion
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
    DynAny discriminator = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
    // index either points to the discriminator or the named member is it exists.
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    // The currently active member, which is of the same type as the discriminator.
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    DynAny currentMember = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
    int currentMemberIndex = NO_INDEX;
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 DynUnionImpl() {
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 DynUnionImpl(ORB orb, Any any, boolean copyValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
        // We can be sure that typeCode is of kind tk_union
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        super(orb, any, copyValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    protected DynUnionImpl(ORB orb, TypeCode typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        // We can be sure that typeCode is of kind tk_union
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        super(orb, typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    protected boolean initializeComponentsFromAny() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
            InputStream input = any.create_input_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
            Any discriminatorAny = DynAnyUtil.extractAnyFromStream(discriminatorType(), input, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
            discriminator = DynAnyUtil.createMostDerivedDynAny(discriminatorAny, orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
            currentMemberIndex = currentUnionMemberIndex(discriminatorAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
            Any memberAny = DynAnyUtil.extractAnyFromStream(memberType(currentMemberIndex), input, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
            components = new DynAny[] {discriminator, currentMember};
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        } catch (InconsistentTypeCode ictc) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    // Sets the current position to zero.
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    // The discriminator value is set to a value consistent with the first named member
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    // of the union. That member is activated and (recursively) initialized to its default value.
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    protected boolean initializeComponentsFromTypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        //System.out.println(this + " initializeComponentsFromTypeCode");
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            // We can be sure that memberCount() > 0 according to the IDL language spec
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
            discriminator = DynAnyUtil.createMostDerivedDynAny(memberLabel(0), orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            currentMemberIndex = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(0), orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            components = new DynAny[] {discriminator, currentMember};
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        } catch (InconsistentTypeCode ictc) { // impossible
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    // Convenience methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    private TypeCode discriminatorType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        TypeCode discriminatorType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            discriminatorType = any.type().discriminator_type();
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
        return discriminatorType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    private int memberCount() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        int memberCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            memberCount = any.type().member_count();
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        return memberCount;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    private Any memberLabel(int i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        Any memberLabel = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            memberLabel = any.type().member_label(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        } catch (Bounds bounds) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        return memberLabel;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    private TypeCode memberType(int i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        TypeCode memberType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
            memberType = any.type().member_type(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        } catch (Bounds bounds) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        return memberType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    private String memberName(int i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        String memberName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
            memberName = any.type().member_name(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        } catch (Bounds bounds) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        return memberName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    private int defaultIndex() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        int defaultIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
            defaultIndex = any.type().default_index();
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        } catch (BadKind bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        return defaultIndex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    private int currentUnionMemberIndex(Any discriminatorValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        int memberCount = memberCount();
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        Any memberLabel;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        for (int i=0; i<memberCount; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
            memberLabel = memberLabel(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
            if (memberLabel.equal(discriminatorValue)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                return i;
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        if (defaultIndex() != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            return defaultIndex();
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        return NO_INDEX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    protected void clearData() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        super.clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
        discriminator = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        // Necessary to guarantee OBJECT_NOT_EXIST in member()
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        currentMember.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        currentMember = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        currentMemberIndex = NO_INDEX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    // DynAny interface methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    // _REVISIT_ More efficient copy operation
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    // DynUnion interface methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    * Returns the current discriminator value.
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    public org.omg.DynamicAny.DynAny get_discriminator () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        return (checkInitComponents() ? discriminator : null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    // Sets the discriminator of the DynUnion to the specified value.
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    // If the TypeCode of the parameter is not equivalent
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    // to the TypeCode of the unions discriminator, the operation raises TypeMismatch.
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    // Setting the discriminator to a value that is consistent with the currently
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    // active union member does not affect the currently active member.
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    // Setting the discriminator to a value that is inconsistent with the currently
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    // active member deactivates the member and activates the member that is consistent
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
    // with the new discriminator value (if there is a member for that value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    // by initializing the member to its default value.
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    // If the discriminator value indicates a non-existent union member
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    // this operation sets the current position to 0
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    // (has_no_active_member returns true in this case).
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
    // Otherwise the current position is set to 1 (has_no_active_member returns false and
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    // component_count returns 2 in this case).
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    public void set_discriminator (org.omg.DynamicAny.DynAny newDiscriminator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        if ( ! newDiscriminator.type().equal(discriminatorType())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        newDiscriminator = DynAnyUtil.convertToNative(newDiscriminator, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        Any newDiscriminatorAny = getAny(newDiscriminator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        int newCurrentMemberIndex = currentUnionMemberIndex(newDiscriminatorAny);
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        if (newCurrentMemberIndex == NO_INDEX) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
            index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            // _REVISIT_ Could possibly optimize here if we don't need to initialize components
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            checkInitComponents();
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            if (currentMemberIndex == NO_INDEX || newCurrentMemberIndex != currentMemberIndex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
                clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
                index = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                currentMemberIndex = newCurrentMemberIndex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(currentMemberIndex), orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                } catch (InconsistentTypeCode ictc) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                discriminator = newDiscriminator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
                components = new DynAny[] { discriminator, currentMember };
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
                representations = REPRESENTATION_COMPONENTS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    // Sets the discriminator to a value that is consistent with the value
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    // of the default case of a union; it sets the current position to
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    // zero and causes component_count to return 2.
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    // Calling set_to_default_member on a union that does not have an explicit
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    // default case raises TypeMismatch.
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    public void set_to_default_member ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        int defaultIndex = defaultIndex();
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
        if (defaultIndex == -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            clearData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            index = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
            currentMemberIndex = defaultIndex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
            currentMember = DynAnyUtil.createMostDerivedDynAny(memberType(defaultIndex), orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
            components = new DynAny[] {discriminator, currentMember};
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
            Any discriminatorAny = orb.create_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
            discriminatorAny.insert_octet((byte)0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
            discriminator = DynAnyUtil.createMostDerivedDynAny(discriminatorAny, orb, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
            representations = REPRESENTATION_COMPONENTS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        } catch (InconsistentTypeCode ictc) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    // Sets the discriminator to a value that does not correspond
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    // to any of the unions case labels.
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    // It sets the current position to zero and causes component_count to return 1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    // Calling set_to_no_active_member on a union that has an explicit default case
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
    // or on a union that uses the entire range of discriminator values
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    // for explicit case labels raises TypeMismatch.
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    public void set_to_no_active_member ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
        // _REVISIT_ How does one check for "entire range of discriminator values"?
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
        if (defaultIndex() != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            throw new TypeMismatch();
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        checkInitComponents();
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        Any discriminatorAny = getAny(discriminator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        // erase the discriminators value so that it does not correspond
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        // to any of the unions case labels
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        discriminatorAny.type(discriminatorAny.type());
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        currentMemberIndex = NO_INDEX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        // Necessary to guarantee OBJECT_NOT_EXIST in member()
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        currentMember.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        currentMember = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        components[0] = discriminator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        representations = REPRESENTATION_COMPONENTS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    // Returns true if the union has no active member
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    // (that is, the unions value consists solely of its discriminator because the
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    // discriminator has a value that is not listed as an explicit case label).
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    // Calling this operation on a union that has a default case returns false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    // Calling this operation on a union that uses the entire range of discriminator
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    // values for explicit case labels returns false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    public boolean has_no_active_member () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        // _REVISIT_ How does one check for "entire range of discriminator values"?
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        if (defaultIndex() != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        checkInitComponents();
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        return (checkInitComponents() ? (currentMemberIndex == NO_INDEX) : false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
    public org.omg.CORBA.TCKind discriminator_kind () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
        return discriminatorType().kind();
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    // Returns the currently active member.
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    // If the union has no active member, the operation raises InvalidValue.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    // Note that the returned reference remains valid only for as long
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    // as the currently active member does not change.
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
    // Using the returned reference beyond the life time
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    // of the currently active member raises OBJECT_NOT_EXIST.
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    public org.omg.DynamicAny.DynAny member ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        return currentMember;
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    // Returns the name of the currently active member.
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    // If the unions TypeCode does not contain a member name for the currently active member,
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    // the operation returns an empty string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
    // Calling member_name on a union without an active member raises InvalidValue.
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    public String member_name ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
        String memberName = memberName(currentMemberIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        return (memberName == null ? "" : memberName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    // Returns the TCKind value of the TypeCode of the currently active member.
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
    // If the union has no active member, the operation raises InvalidValue.
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    public org.omg.CORBA.TCKind member_kind ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        throws org.omg.DynamicAny.DynAnyPackage.InvalidValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        if (status == STATUS_DESTROYED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
            throw wrapper.dynAnyDestroyed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        if ( ! checkInitComponents() || currentMemberIndex == NO_INDEX)
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
            throw new InvalidValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        return memberType(currentMemberIndex).kind();
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
}