corba/src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 7059 79caba0caf4f
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) 1998, 2004, 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
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package com.sun.corba.se.impl.io;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import javax.rmi.PortableRemoteObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.util.Stack;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.util.EmptyStackException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.impl.io.IIOPInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import com.sun.corba.se.impl.io.IIOPOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.impl.util.RepositoryId;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import org.omg.CORBA.TCKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import org.omg.CORBA.MARSHAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import org.omg.CORBA.BAD_PARAM;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import org.omg.CORBA.portable.IndirectionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.org.omg.SendingContext.CodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.org.omg.SendingContext.CodeBaseHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import com.sun.corba.se.impl.io.IIOPInputStream.ActiveRecursionManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import com.sun.corba.se.impl.logging.OMGSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import com.sun.corba.se.impl.logging.UtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
public class ValueHandlerImpl implements javax.rmi.CORBA.ValueHandlerMultiFormat {
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    // Property to override our maximum stream format version
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    public static final String FORMAT_VERSION_PROPERTY
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        = "com.sun.CORBA.MaxStreamFormatVersion";
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    private static final byte MAX_SUPPORTED_FORMAT_VERSION = (byte)2;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    private static final byte STREAM_FORMAT_VERSION_1 = (byte)1;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    // The ValueHandler's maximum stream format version to advertise,
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    // set in a static initializer.
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    private static final byte MAX_STREAM_FORMAT_VERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        MAX_STREAM_FORMAT_VERSION = getMaxStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    // Looks for the FORMAT_VERSION_PROPERTY system property
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    // to allow the user to override our default stream format
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    // version.  Note that this still only allows them to pick
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    // a supported version (1 through MAX_STREAM_FORMAT_VERSION).
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    private static byte getMaxStreamFormatVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
            String propValue = (String) AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
                                        new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
                public java.lang.Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
                    return System.getProperty(ValueHandlerImpl.FORMAT_VERSION_PROPERTY);
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            });
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            // The property wasn't set
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            if (propValue == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
                return MAX_SUPPORTED_FORMAT_VERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            byte result = Byte.parseByte(propValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
            // REVISIT.  Just set to MAX_SUPPORTED_FORMAT_VERSION
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            // or really let the system shutdown with this Error?
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
            if (result < 1 || result > MAX_SUPPORTED_FORMAT_VERSION)
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
                // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
                throw new ExceptionInInitializerError("Invalid stream format version: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
                                                      + result
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
                                                      + ".  Valid range is 1 through "
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
                                                      + MAX_SUPPORTED_FORMAT_VERSION);
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            // REVISIT.  Swallow this or really let
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            // the system shutdown with this Error?
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            Error err = new ExceptionInInitializerError(ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            err.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    public static final short kRemoteType = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    public static final short kAbstractType = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    public static final short kValueType = 2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    private Hashtable inputStreamPairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    private Hashtable outputStreamPairs = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    private CodeBase codeBase = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    private boolean useHashtables = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    private boolean isInputStream = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    private IIOPOutputStream outputStreamBridge = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    private IIOPInputStream inputStreamBridge = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    private OMGSystemException omgWrapper = OMGSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    private UtilSystemException utilWrapper = UtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    // See javax.rmi.CORBA.ValueHandlerMultiFormat
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    public byte getMaximumStreamFormatVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        return MAX_STREAM_FORMAT_VERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    // See javax.rmi.CORBA.ValueHandlerMultiFormat
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    public void writeValue(org.omg.CORBA.portable.OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                           java.io.Serializable value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                           byte streamFormatVersion) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        if (streamFormatVersion == 2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            if (!(out instanceof org.omg.CORBA.portable.ValueOutputStream)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                throw omgWrapper.notAValueoutputstream() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        } else if (streamFormatVersion != 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
            throw omgWrapper.invalidStreamFormatVersion(
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
                new Integer(streamFormatVersion) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        writeValueWithVersion(out, value, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    public ValueHandlerImpl(){}
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    public ValueHandlerImpl(boolean isInputStream) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        this();
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        useHashtables = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        this.isInputStream = isInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
     * Writes the value to the stream using java semantics.
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
     * @param out The stream to write the value to
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     * @param value The value to be written to the stream
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    public void writeValue(org.omg.CORBA.portable.OutputStream _out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                           java.io.Serializable value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        writeValueWithVersion(_out, value, STREAM_FORMAT_VERSION_1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    private void writeValueWithVersion(org.omg.CORBA.portable.OutputStream _out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
                                       java.io.Serializable value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                                       byte streamFormatVersion) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        org.omg.CORBA_2_3.portable.OutputStream out =
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
            (org.omg.CORBA_2_3.portable.OutputStream) _out;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
        if (!useHashtables) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            if (outputStreamBridge == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                outputStreamBridge = createOutputStream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                outputStreamBridge.setOrbStream(out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                outputStreamBridge.increaseRecursionDepth();
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                writeValueInternal(outputStreamBridge, out, value, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                outputStreamBridge.decreaseRecursionDepth();
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
        IIOPOutputStream jdkToOrbOutputStreamBridge = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        if (outputStreamPairs == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
            outputStreamPairs = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
        jdkToOrbOutputStreamBridge = (IIOPOutputStream)outputStreamPairs.get(_out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        if (jdkToOrbOutputStreamBridge == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
            jdkToOrbOutputStreamBridge = createOutputStream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
            jdkToOrbOutputStreamBridge.setOrbStream(out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            outputStreamPairs.put(_out, jdkToOrbOutputStreamBridge);
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
            jdkToOrbOutputStreamBridge.increaseRecursionDepth();
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
            writeValueInternal(jdkToOrbOutputStreamBridge, out, value, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            if (jdkToOrbOutputStreamBridge.decreaseRecursionDepth() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
                outputStreamPairs.remove(_out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    private void writeValueInternal(IIOPOutputStream bridge,
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
                                    org.omg.CORBA_2_3.portable.OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
                                    java.io.Serializable value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
                                    byte streamFormatVersion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        Class clazz = value.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        if (clazz.isArray())
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
            write_Array(out, value, clazz.getComponentType());
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
            bridge.simpleWriteObject(value, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
     * Reads a value from the stream using java semantics.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
     * @param in The stream to read the value from
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
     * @param clazz The type of the value to be read in
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
     * @param sender The sending context runtime
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    public java.io.Serializable readValue(org.omg.CORBA.portable.InputStream _in,
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                                          int offset,
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                                          java.lang.Class clazz,
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                                          String repositoryID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
                                          org.omg.SendingContext.RunTime _sender)
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        // Must use narrow rather than a direct cast to a com.sun
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        // class.  Fix for bug 4379539.
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
        CodeBase sender = CodeBaseHelper.narrow(_sender);
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        org.omg.CORBA_2_3.portable.InputStream in =
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
            (org.omg.CORBA_2_3.portable.InputStream) _in;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        if (!useHashtables) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            if (inputStreamBridge == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
                inputStreamBridge = createInputStream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
                inputStreamBridge.setOrbStream(in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
                inputStreamBridge.setSender(sender); //d11638
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                // backward compatability 4365188
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                inputStreamBridge.setValueHandler(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            java.io.Serializable result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                inputStreamBridge.increaseRecursionDepth();
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
                result = (java.io.Serializable) readValueInternal(inputStreamBridge, in, offset, clazz, repositoryID, sender);
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
                if (inputStreamBridge.decreaseRecursionDepth() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
                    // Indirections are resolved immediately since
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
                    // the change to the active recursion manager,
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
                    // so this will never happen.
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
        IIOPInputStream jdkToOrbInputStreamBridge = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        if (inputStreamPairs == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
            inputStreamPairs = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        jdkToOrbInputStreamBridge = (IIOPInputStream)inputStreamPairs.get(_in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        if (jdkToOrbInputStreamBridge == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
            jdkToOrbInputStreamBridge = createInputStream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            jdkToOrbInputStreamBridge.setOrbStream(in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
            jdkToOrbInputStreamBridge.setSender(sender); //d11638
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            // backward compatability 4365188
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            jdkToOrbInputStreamBridge.setValueHandler(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
            inputStreamPairs.put(_in, jdkToOrbInputStreamBridge);
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        java.io.Serializable result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
            jdkToOrbInputStreamBridge.increaseRecursionDepth();
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
            result = (java.io.Serializable) readValueInternal(jdkToOrbInputStreamBridge, in, offset, clazz, repositoryID, sender);
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
            if (jdkToOrbInputStreamBridge.decreaseRecursionDepth() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
                inputStreamPairs.remove(_in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    private java.io.Serializable readValueInternal(IIOPInputStream bridge,
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
                                                  org.omg.CORBA_2_3.portable.InputStream in,
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
                                                  int offset,
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
                                                  java.lang.Class clazz,
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
                                                  String repositoryID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
                                                  com.sun.org.omg.SendingContext.CodeBase sender)
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        java.io.Serializable result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        if (clazz == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
            // clazz == null indicates an FVD situation for a nonexistant class
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
            if (isArray(repositoryID)){
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
                read_Array(bridge, in, null, sender, offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
                bridge.simpleSkipObject(repositoryID, sender);
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        if (clazz.isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
            result = (java.io.Serializable)read_Array(bridge, in, clazz, sender, offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
            result = (java.io.Serializable)bridge.simpleReadObject(clazz, repositoryID, sender, offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
     * Returns the repository ID for the given RMI value Class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
     * @param clz The class to return a repository ID for.
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
     * @return the repository ID of the Class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    public java.lang.String getRMIRepositoryID(java.lang.Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        return RepositoryId.createForJavaType(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
     * Indicates whether the given Class performs custom or
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
     * default marshaling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
     * @param clz The class to test for custom marshaling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
     * @return True if the class performs custom marshaling, false
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
     * if it does not.
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    public boolean isCustomMarshaled(java.lang.Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        return ObjectStreamClass.lookup(clz).isCustomMarshaled();
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
     * Returns the CodeBase for this ValueHandler.  This is used by
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
     * the ORB runtime.  The server sends the service context containing
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
     * the IOR for this CodeBase on the first GIOP reply.  The clients
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
     * do the same on the first GIOP request.
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
     * @return the SendingContext.CodeBase of this ValueHandler.
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
    public org.omg.SendingContext.RunTime getRunTimeCodeBase() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        if (codeBase != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
            return codeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
            codeBase = new FVDCodeBaseImpl();
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
            // backward compatability 4365188
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
            // set the valueHandler so that correct/incorrect RepositoryID
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
            // calculations can be done based on the ORB version
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
            FVDCodeBaseImpl fvdImpl = (FVDCodeBaseImpl) codeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
            fvdImpl.setValueHandler(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            return codeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    // methods supported for backward compatability so that the appropriate
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
    // Rep-id calculations take place based on the ORB version
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
     *  Returns a boolean of whether or not RepositoryId indicates
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
     *  FullValueDescriptor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
     *  used for backward compatability
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
     public boolean useFullValueDescription(Class clazz, String repositoryID)
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        return RepositoryId.useFullValueDescription(clazz, repositoryID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
     public String getClassName(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        RepositoryId repID = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        return repID.getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
     public Class getClassFromType(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        return repId.getClassFromType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
     public Class getAnyClassFromType(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
        throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
        return repId.getAnyClassFromType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
     public String createForAnyType(Class cl)
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        return RepositoryId.createForAnyType(cl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
     public String getDefinedInId(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        return repId.getDefinedInId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
     public String getUnqualifiedName(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        return repId.getUnqualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
     public String getSerialVersionUID(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
        return repId.getSerialVersionUID();
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
     public boolean isAbstractBase(Class clazz)
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
        return RepositoryId.isAbstractBase(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
     public boolean isSequence(String id)
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
     {
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        RepositoryId repId = RepositoryId.cache.getId(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        return repId.isSequence();
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
     }
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
     * If the value contains a writeReplace method then the result
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
     * is returned.  Otherwise, the value itself is returned.
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
     * @return the true value to marshal on the wire.
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    public java.io.Serializable writeReplace(java.io.Serializable value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        return ObjectStreamClass.lookup(value.getClass()).writeReplace(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
     * Encapsulates writing of Java char arrays so that the 1.3 subclass
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
     * can override it without exposing internals across packages.  This
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
     * is a fix for bug 4367783.
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
    protected void writeCharArray(org.omg.CORBA_2_3.portable.OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
                                char[] array,
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
                                int offset,
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
                                int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
        out.write_wchar_array(array, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    private void write_Array(org.omg.CORBA_2_3.portable.OutputStream out, java.io.Serializable obj, Class type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
        int i, length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        if (type.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
            if (type == Integer.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
                int[] array = (int[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
                out.write_long_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
            } else if (type == Byte.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
                byte[] array = (byte[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
                out.write_octet_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            } else if (type == Long.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                long[] array = (long[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
                out.write_longlong_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
            } else if (type == Float.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
                float[] array = (float[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
                out.write_float_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
            } else if (type == Double.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
                double[] array = (double[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
                out.write_double_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
            } else if (type == Short.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
                short[] array = (short[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                out.write_short_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
            } else if (type == Character.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                char[] array = (char[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                writeCharArray(out, array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
            } else if (type == Boolean.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                boolean[] array = (boolean[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
                length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                out.write_boolean_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
                // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                throw new Error("Invalid primitive type : " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
                    obj.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        } else if (type == java.lang.Object.class) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            Object[] array = (Object[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
            length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
            out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            for (i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
                Util.writeAny(out, array[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
            Object[] array = (Object[])((Object)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
            length = array.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
            out.write_ulong(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
            int callType = kValueType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
            if (type.isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
                String className = type.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
                if (java.rmi.Remote.class.isAssignableFrom(type)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
                    // RMI Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                    callType = kRemoteType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
                } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)){
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                    // IDL Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
                    callType = kRemoteType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                } else if (RepositoryId.isAbstractBase(type)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
                    // IDL Abstract Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                    callType = kAbstractType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                } else if (ObjectStreamClassCorbaExt.isAbstractInterface(type)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
                    callType = kAbstractType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
            for (i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
                switch (callType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
                case kRemoteType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                    Util.writeRemoteObject(out, array[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                case kAbstractType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
                    Util.writeAbstractObject(out,array[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
                case kValueType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
                    try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
                        out.write_value((java.io.Serializable)array[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
                    } catch(ClassCastException cce){
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
                        if (array[i] instanceof java.io.Serializable)
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
                            throw cce;
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
                        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
                            Utility.throwNotSerializableForCorba(
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
                                array[i].getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
     * Encapsulates reading of Java char arrays so that the 1.3 subclass
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
     * can override it without exposing internals across packages.  This
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
     * is a fix for bug 4367783.
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
    protected void readCharArray(org.omg.CORBA_2_3.portable.InputStream in,
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                                 char[] array,
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
                                 int offset,
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
                                 int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
        in.read_wchar_array(array, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    private java.lang.Object read_Array(IIOPInputStream bridge,
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
                                        org.omg.CORBA_2_3.portable.InputStream in,
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
                                        Class sequence,
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
                                        com.sun.org.omg.SendingContext.CodeBase sender,
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
                                        int offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
            // Read length of coming array
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
            int length = in.read_ulong();
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
            int i;
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
            if (sequence == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
                for (i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                    in.read_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            Class componentType = sequence.getComponentType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            Class actualType = componentType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            if (componentType.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
                if (componentType == Integer.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
                    int[] array = new int[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
                    in.read_long_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
                } else if (componentType == Byte.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
                    byte[] array = new byte[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
                    in.read_octet_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
                } else if (componentType == Long.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                    long[] array = new long[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
                    in.read_longlong_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
                } else if (componentType == Float.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                    float[] array = new float[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                    in.read_float_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
                } else if (componentType == Double.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                    double[] array = new double[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
                    in.read_double_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
                } else if (componentType == Short.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
                    short[] array = new short[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
                    in.read_short_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
                } else if (componentType == Character.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
                    char[] array = new char[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
                    readCharArray(in, array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
                } else if (componentType == Boolean.TYPE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
                    boolean[] array = new boolean[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
                    in.read_boolean_array(array, 0, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
                    return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
                    // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
                    throw new Error("Invalid primitive componentType : " + sequence.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
            } else if (componentType == java.lang.Object.class) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
                Object[] array = (Object[])java.lang.reflect.Array.newInstance(
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
                    componentType, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                // Store this object and its beginning position
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
                // since there might be indirections to it while
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
                // it's been unmarshalled.
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
                bridge.activeRecursionMgr.addObject(offset, array);
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
                for (i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
                    Object objectValue = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
                        objectValue = Util.readAny(in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
                    } catch(IndirectionException cdrie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
                            // The CDR stream had never seen the given offset
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
                            // before, so check the recursion manager (it will
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
                            // throw an IOException if it doesn't have a
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
                            // reference, either).
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
                            objectValue = bridge.activeRecursionMgr.getObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
                                cdrie.offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
                        } catch (IOException ie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
                            // Translate to a MARSHAL exception since
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
                            // ValueHandlers aren't allowed to throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
                            // IOExceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
                            throw utilWrapper.invalidIndirection( ie,
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
                                new Integer( cdrie.offset ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
                    array[i] = objectValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
                return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
                Object[] array = (Object[])java.lang.reflect.Array.newInstance(
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
                    componentType, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
                // Store this object and its beginning position
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
                // since there might be indirections to it while
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
                // it's been unmarshalled.
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
                bridge.activeRecursionMgr.addObject(offset, array);
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
                // Decide what method call to make based on the componentType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
                // If it is a componentType for which we need to load a stub,
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
                // convert the componentType to the correct stub type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
                int callType = kValueType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
                boolean narrow = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
                if (componentType.isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
                    boolean loadStubClass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
                    // String className = componentType.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
                    if (java.rmi.Remote.class.isAssignableFrom(componentType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
                        // RMI Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
                        callType = kRemoteType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
                        // for better performance, load the stub class once
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
                        // instead of for each element of the array
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
                        loadStubClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
                    } else if (org.omg.CORBA.Object.class.isAssignableFrom(componentType)){
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
                        // IDL Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
                        callType = kRemoteType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
                        loadStubClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
                    } else if (RepositoryId.isAbstractBase(componentType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
                        // IDL Abstract Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
                        callType = kAbstractType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
                        loadStubClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
                    } else if (ObjectStreamClassCorbaExt.isAbstractInterface(componentType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
                        // RMI Abstract Object reference...
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
                        // componentType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
                        callType = kAbstractType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
                    if (loadStubClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
                            String codebase = Util.getCodebase(componentType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
                            String repID = RepositoryId.createForAnyType(componentType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
                            Class stubType =
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
                                Utility.loadStubClass(repID, codebase, componentType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
                            actualType = stubType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
                        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
                            narrow = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
                        narrow = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
                for (i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
                        switch (callType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
                        case kRemoteType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
                            if (!narrow)
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
                                array[i] = (Object)in.read_Object(actualType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
                            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
                                array[i] = Utility.readObjectAndNarrow(in, actualType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
                        case kAbstractType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
                            if (!narrow)
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
                                array[i] = (Object)in.read_abstract_interface(actualType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
                            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
                                array[i] = Utility.readAbstractAndNarrow(in, actualType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
                        case kValueType:
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
                            array[i] = (Object)in.read_value(actualType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
                    } catch(IndirectionException cdrie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
                        // The CDR stream had never seen the given offset before,
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
                        // so check the recursion manager (it will throw an
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
                        // IOException if it doesn't have a reference, either).
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
                            array[i] = bridge.activeRecursionMgr.getObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
                                cdrie.offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
                        } catch (IOException ioe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
                            // Translate to a MARSHAL exception since
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
                            // ValueHandlers aren't allowed to throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
                            // IOExceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
                            throw utilWrapper.invalidIndirection( ioe,
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
                                new Integer( cdrie.offset ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
                return ((java.io.Serializable)((Object)array));
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
            // We've completed deserializing this object.  Any
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
            // future indirections will be handled correctly at the
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
            // CDR level.  The ActiveRecursionManager only deals with
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
            // objects currently being deserialized.
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
            bridge.activeRecursionMgr.removeObject(offset);
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
    private boolean isArray(String repId){
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        return RepositoryId.cache.getId(repId).isSequence();
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
    protected String getOutputStreamClassName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        return "com.sun.corba.se.impl.io.IIOPOutputStream";
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
    private com.sun.corba.se.impl.io.IIOPOutputStream createOutputStream() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
        return (com.sun.corba.se.impl.io.IIOPOutputStream)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
            new StreamFactory(getOutputStreamClassName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    protected String getInputStreamClassName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        return "com.sun.corba.se.impl.io.IIOPInputStream";
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
    private com.sun.corba.se.impl.io.IIOPInputStream createInputStream() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        return (com.sun.corba.se.impl.io.IIOPInputStream)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
            new StreamFactory(getInputStreamClassName()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
     * Instantiates a class of the given name using the system ClassLoader
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
     * as part of a PrivilegedAction.
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
     * It's private final so hopefully people can't grab it outside of
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
     * this class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
     * If you're worried that someone could subclass ValueHandlerImpl,
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
     * install his own streams, and snoop what's on the wire:
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
     * Someone can do that only if he's allowed to use the feature
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
     * of installing his own javax.rmi.CORBA.Util delegate (via a
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
     * JVM property or orb.properties file, read the first time the
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
     * Util class is used).  If he can do that, he can snoop
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
     * anything on the wire, anyway, without abusing the
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
     * StreamFactory class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
    private static final class StreamFactory implements PrivilegedAction {
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        private String className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
        public StreamFactory (String _className) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
            className = _className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
        public Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
                // Note: We must use the system ClassLoader here
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
                // since we want to load classes outside of the
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                // core JDK when running J2EE Pure ORB and
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
                // talking to Kestrel.
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                if (cl == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                    cl = ClassLoader.getSystemClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
                Class streamClass = cl.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
                // Since the ClassLoader should cache the class, this isn't
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
                // as expensive as it looks.
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
                return streamClass.newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
            } catch(Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
                InternalError ie = new InternalError( "Error loading " + className ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                ie.initCause( t ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
                throw ie ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
     * Our JDK 1.3 and JDK 1.3.1 behavior subclasses override this.
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
     * The correct behavior is for a Java char to map to a CORBA wchar,
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
     * but our older code mapped it to a CORBA char.
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
    protected TCKind getJavaCharTCKind() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
        return TCKind.tk_wchar;
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
}