corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 11044 758078ec0816
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) 1997, 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
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
package com.sun.corba.se.impl.encoding;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.io.Serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.io.ByteArrayInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.io.StreamCorruptedException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.io.OptionalDataException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.Stack;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.net.URL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.net.MalformedURLException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.nio.ByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.lang.reflect.InvocationTargetException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.lang.reflect.Method;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import java.math.BigDecimal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import java.rmi.StubNotFoundException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import java.security.PrivilegedExceptionAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import java.security.PrivilegedActionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import org.omg.CORBA.Object;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import org.omg.CORBA.Principal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import org.omg.CORBA.portable.Delegate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.CORBA.portable.ValueBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import org.omg.CORBA.portable.IndirectionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import org.omg.CORBA.TCKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import org.omg.CORBA.TypeCodePackage.BadKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import org.omg.CORBA.CustomMarshal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import org.omg.CORBA.Principal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import org.omg.CORBA.portable.BoxedValueHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import org.omg.CORBA.portable.ValueFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import org.omg.CORBA.portable.CustomValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import org.omg.CORBA.portable.StreamableValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import org.omg.CORBA.MARSHAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import org.omg.CORBA.portable.IDLEntity;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import javax.rmi.PortableRemoteObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import javax.rmi.CORBA.Tie;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
import javax.rmi.CORBA.ValueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
import com.sun.corba.se.pept.protocol.MessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
import com.sun.corba.se.pept.transport.ByteBufferPool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
import com.sun.corba.se.spi.protocol.CorbaClientDelegate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
import com.sun.corba.se.spi.ior.IORFactories;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
import com.sun.corba.se.spi.orb.ORBVersionFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
import com.sun.corba.se.spi.orb.ORBVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
import com.sun.corba.se.impl.logging.OMGSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
import com.sun.corba.se.impl.corba.PrincipalImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
import com.sun.corba.se.impl.corba.TypeCodeImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
import com.sun.corba.se.impl.corba.CORBAObjectImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
import com.sun.corba.se.impl.encoding.CDROutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
import com.sun.corba.se.impl.encoding.CodeSetConversion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
import com.sun.corba.se.impl.util.RepositoryId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
import com.sun.corba.se.impl.orbutil.RepositoryIdStrings;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
import com.sun.corba.se.impl.orbutil.RepositoryIdInterface;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
import com.sun.corba.se.impl.orbutil.RepositoryIdUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
import com.sun.corba.se.impl.orbutil.RepositoryIdFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
import com.sun.corba.se.impl.orbutil.CacheTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
import com.sun.org.omg.CORBA.portable.ValueHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
import com.sun.org.omg.SendingContext.CodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
public class CDRInputStream_1_0 extends CDRInputStreamBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    implements RestorableInputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    private static final String kReadMethod = "read";
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    private static final int maxBlockLength = 0x7fffff00;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    protected BufferManagerRead bufferManagerRead;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    protected ByteBufferWithInfo bbwi;
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    // Set to the ORB's transportDebugFlag value.  This value is
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    // used if the ORB is null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    private boolean debug = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    protected boolean littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    protected ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    protected ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    protected OMGSystemException omgWrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    protected ValueHandler valueHandler = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    // Value cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    private CacheTable valueCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    // Repository ID cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    private CacheTable repositoryIdCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    // codebase cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    private CacheTable codebaseCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // Current Class Stack (repository Ids of current class being read)
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    // private Stack currentStack = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    // Length of current chunk, or a large positive number if not in a chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    protected int blockLength = maxBlockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    // Read end flag (value nesting depth)
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    protected int end_flag = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    // Beginning with the resolution to interop issue 3526 (4328?),
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    // only enclosing chunked valuetypes are taken into account
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    // when computing the nesting level.  However, we still need
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    // the old computation around for interoperability with our
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    // older ORBs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    private int chunkedValueNestingLevel = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    // Flag used to determine whether blocksize was zero
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    // private int checkForNullBlock = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    // In block flag
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    // private boolean inBlock = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    // Indicates whether we are inside a value
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    // private boolean outerValueDone = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    // Int used by read_value(Serializable) that is set by this class
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    // before calling ValueFactory.read_value
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    protected int valueIndirection = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    // Int set by readStringOrIndirection to communicate the actual
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    // offset of the string length field back to the caller
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    protected int stringIndirection = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    // Flag indicating whether we are unmarshalling a chunked value
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    protected boolean isChunked = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    // Repository ID handlers
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    private RepositoryIdUtility repIdUtil;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
    private RepositoryIdStrings repIdStrs;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    // Code set converters (created when first needed)
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    private CodeSetConversion.BTCConverter charConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    private CodeSetConversion.BTCConverter wcharConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    // RMI-IIOP stream format version 2 case in which we know
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    // that there is no more optional data available.  If the
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    // Serializable's readObject method tries to read anything,
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    // we must throw a MARSHAL with the special minor code
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    // so that the ValueHandler can give the correct exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    // to readObject.  The state is cleared when the ValueHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    // calls end_value after the readObject method exits.
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    private boolean specialNoOptionalDataState = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    // Template method
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    public CDRInputStreamBase dup()
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        CDRInputStreamBase result = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            result = (CDRInputStreamBase)this.getClass().newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
            throw wrapper.couldNotDuplicateCdrInputStream( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        result.init(this.orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
                    this.bbwi.byteBuffer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
                    this.bbwi.buflen,
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
                    this.littleEndian,
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
                    this.bufferManagerRead);
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        ((CDRInputStream_1_0)result).bbwi.position(this.bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        // To ensure we keep bbwi.byteBuffer.limit in sync with bbwi.buflen.
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        ((CDRInputStream_1_0)result).bbwi.byteBuffer.limit(this.bbwi.buflen);
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        return result;
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
     * NOTE:  size passed to init means buffer size
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    public void init(org.omg.CORBA.ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
                     ByteBuffer byteBuffer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                     int size,
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
                     boolean littleEndian,
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                     BufferManagerRead bufferManager)
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        this.orb = (ORB)orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        this.wrapper = ORBUtilSystemException.get( (ORB)orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        this.omgWrapper = OMGSystemException.get( (ORB)orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
            CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
        this.littleEndian = littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        this.bufferManagerRead = bufferManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        this.bbwi = new ByteBufferWithInfo(orb,byteBuffer,0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        this.bbwi.buflen = size;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        this.bbwi.byteBuffer.limit(bbwi.buflen);
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        debug = ((ORB)orb).transportDebugFlag;
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    // See description in CDRInputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    void performORBVersionSpecificInit() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        createRepositoryIdHandlers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    private final void createRepositoryIdHandlers()
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        repIdUtil = RepositoryIdFactory.getRepIdUtility(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    public GIOPVersion getGIOPVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        return GIOPVersion.V1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    // Called by Request and Reply message. Valid for GIOP versions >= 1.2 only.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    // Illegal for GIOP versions < 1.2.
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    void setHeaderPadding(boolean headerPadding) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        throw wrapper.giopVersionError();
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    protected final int computeAlignment(int index, int align) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        if (align > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
            int incr = index & (align - 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
            if (incr != 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                return align - incr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    public int getSize()
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    protected void checkBlockLength(int align, int dataSize) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        // Since chunks can end at arbitrary points (though not within
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        // primitive CDR types, arrays of primitives, strings, wstrings,
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        // or indirections),
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        // we must check here for termination of the current chunk.
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        if (!isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        // RMI-IIOP stream format version 2 case in which we know
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        // that there is no more optional data available.  If the
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        // Serializable's readObject method tries to read anything,
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        // we must throw a MARSHAL exception with the special minor code
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        // so that the ValueHandler can give the correct exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        // to readObject.  The state is cleared when the ValueHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        // calls end_value after the readObject method exits.
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        if (specialNoOptionalDataState) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
            throw omgWrapper.rmiiiopOptionalDataIncompatible1() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        boolean checkForEndTag = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        // Are we at the end of the current chunk?  If so,
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        // try to interpret the next long as a chunk length.
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        // (It has to be either a chunk length, end tag,
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        // or valuetag.)
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        // If it isn't a chunk length, blockLength will
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        // remain set to maxBlockLength.
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        if (blockLength == get_offset()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
            blockLength = maxBlockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            // What's next is either a valuetag or
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            // an end tag.  If it's a valuetag, we're
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
            // probably being called as part of the process
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            // to read the valuetag.  If it's an end tag,
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
            // then there isn't enough data left in
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
            // this valuetype to read!
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
            if (blockLength == maxBlockLength)
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
                checkForEndTag = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        if (blockLength < get_offset()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
            // Are we already past the end of the current chunk?
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            // This is always an error.
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            throw wrapper.chunkOverflow() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        // If what's next on the wire isn't a chunk length or
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        // what we want to read (which can't be split across chunks)
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        // won't fit in the current chunk, throw this exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        // This probably means that we're in an RMI-IIOP
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        // Serializable's readObject method or a custom marshaled
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        // IDL type is reading too much/in an incorrect order
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        int requiredNumBytes =
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                            computeAlignment(bbwi.position(), align) + dataSize;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        if (blockLength != maxBlockLength &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            blockLength < get_offset() + requiredNumBytes) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
            throw omgWrapper.rmiiiopOptionalDataIncompatible2() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        // REVISIT - We should look at using the built in advancement
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        //           of using ByteBuffer.get() rather than explicitly
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        //           advancing the ByteBuffer's position.
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        //           This is true for anywhere we are incrementing
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
        //           the ByteBuffer's position.
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
        if (checkForEndTag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
            int nextLong = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
            bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
            // It was an end tag, so there wasn't enough data
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
            // left in the valuetype's encoding on the wire
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
            // to read what we wanted
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            if (nextLong < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
                throw omgWrapper.rmiiiopOptionalDataIncompatible3() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    protected void alignAndCheck(int align, int n) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        checkBlockLength(align, n);
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        // WARNING: Must compute real alignment after calling
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        // checkBlockLength since it may move the position
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        int alignResult = computeAlignment(bbwi.position(), align);
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        bbwi.position(bbwi.position() + alignResult);
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
        if (bbwi.position() + n > bbwi.buflen)
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
            grow(align, n);
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    // This can be overridden....
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
    protected void grow(int align, int n) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        bbwi.needed = n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        bbwi = bufferManagerRead.underflow(bbwi);
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
    // Marshal primitives.
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
    public final void consumeEndian() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        littleEndian = read_boolean();
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    // No such type in java
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
    public final double read_longdouble() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        throw wrapper.longDoubleNotImplemented( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
    public final boolean read_boolean() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        return (read_octet() != 0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
    public final char read_char() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        alignAndCheck(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        return getConvertedChars(1, getCharConverter())[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    public char read_wchar() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
        // Don't allow transmission of wchar/wstring data with
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
        // foreign ORBs since it's against the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
        if (ORBUtility.isForeignORB((ORB)orb)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
            throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
        // If we're talking to one of our legacy ORBs, do what
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        // they did:
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
        int b1, b2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
        alignAndCheck(2, 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
            b2 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
            b1 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
            b1 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
            b2 = bbwi.byteBuffer.get(bbwi.position()) & 0x00FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        return (char)((b1 << 8) + (b2 << 0));
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    public final byte read_octet() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        alignAndCheck(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        byte b = bbwi.byteBuffer.get(bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
        bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
        return b;
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    public final short read_short() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        int b1, b2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
        alignAndCheck(2, 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
            b2 = (bbwi.byteBuffer.get(bbwi.position()) << 0) & 0x000000FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
            b1 = (bbwi.byteBuffer.get(bbwi.position()) << 8) & 0x0000FF00;
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
            b1 = (bbwi.byteBuffer.get(bbwi.position()) << 8) & 0x0000FF00;
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
            b2 = (bbwi.byteBuffer.get(bbwi.position()) << 0) & 0x000000FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
            bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
        return (short)(b1 | b2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    public final short read_ushort() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        return read_short();
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
    public final int read_long() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
        int b1, b2, b3, b4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        alignAndCheck(4, 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        int bufPos = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
            b4 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            b3 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
            b2 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
            b1 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
            b1 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
            b2 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
            b3 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
            b4 = bbwi.byteBuffer.get(bufPos++) & 0xFF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        bbwi.position(bufPos);
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
        return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
    public final int read_ulong() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        return read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
    public final long read_longlong() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
        long i1, i2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        alignAndCheck(8, 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
            i2 = read_long() & 0xFFFFFFFFL;
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
            i1 = (long)read_long() << 32;
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
            i1 = (long)read_long() << 32;
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
            i2 = read_long() & 0xFFFFFFFFL;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
        return (i1 | i2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
    public final long read_ulonglong() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        return read_longlong();
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
    public final float read_float() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
        return Float.intBitsToFloat(read_long());
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
    public final double read_double() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
        return Double.longBitsToDouble(read_longlong());
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    protected final void checkForNegativeLength(int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
        if (length < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
            throw wrapper.negativeStringLength( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
                new Integer(length) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    protected final String readStringOrIndirection(boolean allowIndirection) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        int len = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
        // Check for indirection
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
        if (allowIndirection) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
            if (len == 0xffffffff)
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                stringIndirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
        checkForNegativeLength(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
        if (orb != null && ORBUtility.isLegacyORB((ORB)orb))
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
            return legacyReadString(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
            return internalReadString(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
    private final String internalReadString(int len) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
        // Workaround for ORBs which send string lengths of
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
        // zero to mean empty string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
        // IMPORTANT: Do not replace 'new String("")' with "", it may result
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
        // in a Serialization bug (See serialization.zerolengthstring) and
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
        // bug id: 4728756 for details
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        if (len == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
            return new String("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
        char[] result = getConvertedChars(len - 1, getCharConverter());
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        // Skip over the 1 byte null
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
        read_octet();
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
        return new String(result, 0, getCharConverter().getNumChars());
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
    private final String legacyReadString(int len) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
        // Workaround for ORBs which send string lengths of
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
        // zero to mean empty string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
        // IMPORTANT: Do not replace 'new String("")' with "", it may result
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
        // in a Serialization bug (See serialization.zerolengthstring) and
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
        // bug id: 4728756 for details
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        if (len == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
            return new String("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
        len--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
        char[] c = new char[len];
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
        int n = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
        while (n < len) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
            int avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
            int bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
            int wanted;
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
            avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
            if (avail <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                grow(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
                avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
            wanted = len - n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
            bytes = (wanted < avail) ? wanted : avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            // Microbenchmarks are showing a loop of ByteBuffer.get(int) being
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            // faster than ByteBuffer.get(byte[], int, int).
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            for (int i=0; i<bytes; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
                c[n+i] = (char) (bbwi.byteBuffer.get(bbwi.position()+i) & 0xFF);
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
            bbwi.position(bbwi.position() + bytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
            n += bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        // Skip past terminating null byte
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
        if (bbwi.position() + 1 > bbwi.buflen)
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
            alignAndCheck(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
        bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
        return new String(c);
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    public final String read_string() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
        return readStringOrIndirection(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
    public String read_wstring() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
        // Don't allow transmission of wchar/wstring data with
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
        // foreign ORBs since it's against the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
        if (ORBUtility.isForeignORB((ORB)orb)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
            throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
        int len = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
        // Workaround for ORBs which send string lengths of
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
        // zero to mean empty string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
        // IMPORTANT: Do not replace 'new String("")' with "", it may result
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
        // in a Serialization bug (See serialization.zerolengthstring) and
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
        // bug id: 4728756 for details
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
        if (len == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
            return new String("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        checkForNegativeLength(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
        len--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        char[] c = new char[len];
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        for (int i = 0; i < len; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
            c[i] = read_wchar();
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
        // skip the two null terminator bytes
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        read_wchar();
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
        // bbwi.position(bbwi.position() + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        return new String(c);
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
    public final void read_octet_array(byte[] b, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
        if ( b == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
            throw wrapper.nullParam() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
        // Must call alignAndCheck at least once to ensure
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
        // we aren't at the end of a chunk.  Of course, we
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
        // should only call it if we actually need to read
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
        // something, otherwise we might end up with an
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        // exception at the end of the stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        if (length == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        alignAndCheck(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
        int n = offset;
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
        while (n < length+offset) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
            int avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
            int bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
            int wanted;
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
            avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
            if (avail <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
                grow(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
                avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
            wanted = (length + offset) - n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
            bytes = (wanted < avail) ? wanted : avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
            // Microbenchmarks are showing a loop of ByteBuffer.get(int) being
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
            // faster than ByteBuffer.get(byte[], int, int).
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            for (int i = 0; i < bytes; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
                b[n+i] = bbwi.byteBuffer.get(bbwi.position() + i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
            bbwi.position(bbwi.position() + bytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
            n += bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
    public Principal read_Principal() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
        int len = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
        byte[] pvalue = new byte[len];
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
        read_octet_array(pvalue,0,len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
        Principal p = new PrincipalImpl();
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
        p.name(pvalue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
        return p;
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
    public TypeCode read_TypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
        TypeCodeImpl tc = new TypeCodeImpl(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
        tc.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
        return tc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
    public Any read_any() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
        Any any = orb.create_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
        TypeCodeImpl tc = new TypeCodeImpl(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        // read off the typecode
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
        // REVISIT We could avoid this try-catch if we could peek the typecode
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        // kind off this stream and see if it is a tk_value.  Looking at the
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
        // code we know that for tk_value the Any.read_value() below
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
        // ignores the tc argument anyway (except for the kind field).
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        // But still we would need to make sure that the whole typecode,
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
        // including encapsulations, is read off.
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
            tc.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
        } catch (MARSHAL ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
            if (tc.kind().value() != TCKind._tk_value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
                throw ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
            // We can be sure that the whole typecode encapsulation has been
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
            // read off.
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
            dprintThrowable(ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
        // read off the value of the any
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        any.read_value(parent, tc);
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
        return any;
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
    public org.omg.CORBA.Object read_Object() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        return read_Object(null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
    // ------------ RMI related methods --------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
    // IDL to Java ptc-00-01-08 1.21.4.1
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
    // The clz argument to read_Object can be either a stub
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
    // Class or the "Class object for the RMI/IDL interface type
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
    // that is statically expected."
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
    // This functions as follows:
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
    // 1. If clz==null, just use the repository ID from the stub
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
    // 2. If clz is a stub class, just use it as a static factory.
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
    //    clz is a stub class iff StubAdapter.isStubClass( clz ).
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
    //    In addition, clz is a IDL stub class iff
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
    //    IDLEntity.class.isAssignableFrom( clz ).
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
    // 3. If clz is an interface, use it to create the appropriate
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
    //    stub factory.
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
    public org.omg.CORBA.Object read_Object(Class clz)
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
        // In any case, we must first read the IOR.
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
        IOR ior = IORFactories.makeIOR(parent) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        if (ior.isNil())
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
            return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
        PresentationManager.StubFactoryFactory sff = ORB.getStubFactoryFactory() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        String codeBase = ior.getProfile().getCodebase() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
        PresentationManager.StubFactory stubFactory = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        if (clz == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
            RepositoryId rid = RepositoryId.cache.getId( ior.getTypeId() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
            String className = rid.getClassName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
            boolean isIDLInterface = rid.isIDLType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
            if (className == null || className.equals( "" ))
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
                stubFactory = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
                    stubFactory = sff.createStubFactory( className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
                        isIDLInterface, codeBase, (Class)null,
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
                        (ClassLoader)null );
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
                } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
                    // Could not create stubFactory, so use null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
                    // XXX stubFactory handling is still too complex:
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
                    // Can we resolve the stubFactory question once in
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
                    // a single place?
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
                    stubFactory = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        } else if (StubAdapter.isStubClass( clz )) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
            stubFactory = PresentationDefaults.makeStaticStubFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
                clz ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
            // clz is an interface class
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
            boolean isIDL = IDLEntity.class.isAssignableFrom( clz ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
            stubFactory = sff.createStubFactory( clz.getName(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
                isIDL, codeBase, clz, clz.getClassLoader() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        return internalIORToObject( ior, stubFactory, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
     * This is used as a general utility (e.g., the PortableInterceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
     * implementation uses it.   If stubFactory is null, the ior's
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
     * IIOPProfile must support getServant.
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
    public static org.omg.CORBA.Object internalIORToObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
        IOR ior, PresentationManager.StubFactory stubFactory, ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        ORBUtilSystemException wrapper = ORBUtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
            (ORB)orb, CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
        java.lang.Object servant = ior.getProfile().getServant() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
        if (servant != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
            if (servant instanceof Tie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
                String codebase = ior.getProfile().getCodebase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
                org.omg.CORBA.Object objref = (org.omg.CORBA.Object)
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
                    Utility.loadStub( (Tie)servant, stubFactory, codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
                        false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
                // If we managed to load a stub, return it, otherwise we
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
                // must fail...
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
                if (objref != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                    return objref;
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
                    throw wrapper.readObjectException() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
            } else if (servant instanceof org.omg.CORBA.Object) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                if (!(servant instanceof
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
                        org.omg.CORBA.portable.InvokeHandler)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
                    return (org.omg.CORBA.Object) servant;
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
            } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
                throw wrapper.badServantReadObject() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        CorbaClientDelegate del = ORBUtility.makeClientDelegate( ior ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
        org.omg.CORBA.Object objref = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
            objref = stubFactory.makeStub() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
        } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
            wrapper.stubCreateError( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
            if (e instanceof ThreadDeath) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
                throw (ThreadDeath) e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
            // Return the "default" stub...
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
            objref = new CORBAObjectImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
        StubAdapter.setDelegate( objref, del ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
        return objref;
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
    public java.lang.Object read_abstract_interface()
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
        return read_abstract_interface(null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
    public java.lang.Object read_abstract_interface(java.lang.Class clz)
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
        boolean object = read_boolean();
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
        if (object) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
            return read_Object(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
            return read_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
    public Serializable read_value()
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
        return read_value((Class)null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
    private Serializable handleIndirection() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
        int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
        if (valueCache != null && valueCache.containsVal(indirection)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
            java.io.Serializable cachedValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
                = (java.io.Serializable)valueCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
            return cachedValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
            // In RMI-IIOP the ValueHandler will recognize this
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
            // exception and use the provided indirection value
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
            // to lookup a possible indirection to an object
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
            // currently on the deserialization stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
            throw new IndirectionException(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
    private String readRepositoryIds(int valueTag,
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
                                     Class expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
                                     String expectedTypeRepId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
        return readRepositoryIds(valueTag, expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
                                 expectedTypeRepId, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
     * Examines the valuetag to see how many (if any) repository IDs
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
     * are present on the wire.  If no repository ID information
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
     * is on the wire but the expectedType or expectedTypeRepId
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
     * is known, it will return one of those (favoring the
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
     * expectedType's repId). Failing that, it uses the supplied
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
     * BoxedValueHelper to obtain the repository ID, as a last resort.
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
    private String readRepositoryIds(int valueTag,
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                                     Class expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
                                     String expectedTypeRepId,
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
                                     BoxedValueHelper factory) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
        switch(repIdUtil.getTypeInfo(valueTag)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
            case RepositoryIdUtility.NO_TYPE_INFO :
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
                // Throw an exception if we have no repository ID info and
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
                // no expectedType to work with.  Otherwise, how would we
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
                // know what to unmarshal?
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
                if (expectedType == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
                    if (expectedTypeRepId != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                        return expectedTypeRepId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
                    } else if (factory != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
                        return factory.get_id();
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                        throw wrapper.expectedTypeNullAndNoRepId(
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                            CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
                return repIdStrs.createForAnyType(expectedType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
            case RepositoryIdUtility.SINGLE_REP_TYPE_INFO :
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
                return read_repositoryId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
            case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO :
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
                return read_repositoryIds();
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
            default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
                throw wrapper.badValueTag( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
                    Integer.toHexString(valueTag) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    public Serializable read_value(Class expectedType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
        // Read value tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
        int vType = readValueTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
        // Is value null?
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
        if (vType == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
        // Is this an indirection to a previously
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
        // read valuetype?
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
        if (vType == 0xffffffff)
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
            return handleIndirection();
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
        // Save where this valuetype started so we
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
        // can put it in the indirection valueCache
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        // later
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
        int indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
        // Need to save this special marker variable
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        // to restore its value during recursion
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
        boolean saveIsChunked = isChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        isChunked = repIdUtil.isChunkedEncoding(vType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
        java.lang.Object value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
        String codebase_URL = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        if (repIdUtil.isCodeBasePresent(vType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
            codebase_URL = read_codebase_URL();
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
        // Read repository id(s)
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
        String repositoryIDString
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
            = readRepositoryIds(vType, expectedType, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        // If isChunked was determined to be true based
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
        // on the valuetag, this will read a chunk length
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        // Remember that end_flag keeps track of all nested
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
        // valuetypes and is used for older ORBs
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
        end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        if (isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
        if (repositoryIDString.equals(repIdStrs.getWStringValueRepId())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
            value = read_wstring();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
        if (repositoryIDString.equals(repIdStrs.getClassDescValueRepId())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
            // read in the class whether with the old ClassDesc or the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
            // new one
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
            value = readClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
            Class valueClass = expectedType;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
            // By this point, either the expectedType or repositoryIDString
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
            // is guaranteed to be non-null.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
            if (expectedType == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
                !repositoryIDString.equals(repIdStrs.createForAnyType(expectedType))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
                valueClass = getClassFromString(repositoryIDString,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
                                                codebase_URL,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
                                                expectedType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
            if (valueClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
                // No point attempting to use value handler below, since the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
                // class information is not available.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
                throw wrapper.couldNotFindClass(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
                    CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
                    new ClassNotFoundException());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
            if (valueClass != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
                org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(valueClass)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
                value =  readIDLValue(indirection,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
                                      repositoryIDString,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
                                      valueClass,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
                                      codebase_URL);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
                // Must be some form of RMI-IIOP valuetype
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
                    if (valueHandler == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
                        valueHandler = ORBUtility.createValueHandler(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
                    value = valueHandler.readValue(parent,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
                                                   indirection,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
                                                   valueClass,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
                                                   repositoryIDString,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
                                                   getCodeBase());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
                } catch(SystemException sysEx) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
                    // Just rethrow any CORBA system exceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
                    // that come out of the ValueHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
                    throw sysEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
                } catch(Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
                    throw wrapper.valuehandlerReadException(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
                        CompletionStatus.COMPLETED_MAYBE, ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
                } catch(Error e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
                    throw wrapper.valuehandlerReadError(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
                        CompletionStatus.COMPLETED_MAYBE, e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
        // Skip any remaining chunks until we get to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
        // an end tag or a valuetag.  If we see a valuetag,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
        // that means there was another valuetype in the sender's
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
        // version of this class that we need to skip over.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
        handleEndOfValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
        // Read and process the end tag if we're chunking.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
        // Assumes that we're at the position of the end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
        // (handleEndOfValue should assure this)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
        readEndTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
        // Cache the valuetype that we read
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
        if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
            valueCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
        valueCache.put(value, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
        // Allow for possible continuation chunk.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
        // If we're a nested valuetype inside of a chunked
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
        // valuetype, and that enclosing valuetype has
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
        // more data to write, it will need to have this
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
        // new chunk begin after we wrote our end tag.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
        isChunked = saveIsChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
        return (java.io.Serializable)value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
    public Serializable read_value(BoxedValueHelper factory) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
        // Read value tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
        int vType = readValueTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
        if (vType == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
            return null; // value is null
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
        else if (vType == 0xffffffff) { // Indirection tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
            int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
            if (valueCache != null && valueCache.containsVal(indirection))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
                    java.io.Serializable cachedValue =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
                           (java.io.Serializable)valueCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
                    return cachedValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
                throw new IndirectionException(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
            int indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
            // end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
            boolean saveIsChunked = isChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
            isChunked = repIdUtil.isChunkedEncoding(vType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
            java.lang.Object value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
            String codebase_URL = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
            if (repIdUtil.isCodeBasePresent(vType)){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
                codebase_URL = read_codebase_URL();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
            // Read repository id
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
            String repositoryIDString
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
                = readRepositoryIds(vType, null, null, factory);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
            // Compare rep. ids to see if we should use passed helper
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
            if (!repositoryIDString.equals(factory.get_id()))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
                factory = Utility.getHelper(null, codebase_URL, repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
            if (isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
                chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
            if (factory instanceof ValueHelper) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
                value = readIDLValueWithHelper((ValueHelper)factory, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
                valueIndirection = indirection;  // for callback
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
                value = factory.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
            handleEndOfValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
            readEndTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
            // Put into valueCache
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
            if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
                valueCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
            valueCache.put(value, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
            // allow for possible continuation chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
            isChunked = saveIsChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
            return (java.io.Serializable)value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
    private boolean isCustomType(ValueHelper helper) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
        try{
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
            TypeCode tc = helper.get_type();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
            int kind = tc.kind().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
            if (kind == TCKind._tk_value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
                return (tc.type_modifier() == org.omg.CORBA.VM_CUSTOM.value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
        } catch(BadKind ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
            throw wrapper.badKind(ex) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
    // This method is actually called indirectly by
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
    // read_value(String repositoryId).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
    // Therefore, it is not a truly independent read call that handles
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
    // header information itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
    public java.io.Serializable read_value(java.io.Serializable value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
        // Put into valueCache using valueIndirection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
        if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
            valueCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
        valueCache.put(value, valueIndirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
        if (value instanceof StreamableValue)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
            ((StreamableValue)value)._read(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
        else if (value instanceof CustomValue)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
            ((CustomValue)value).unmarshal(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
        return value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
    public java.io.Serializable read_value(java.lang.String repositoryId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
        // if (inBlock)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
        //    end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
        // Read value tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
        int vType = readValueTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
        if (vType == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
            return null; // value is null
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
        else if (vType == 0xffffffff) { // Indirection tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
            int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
            if (valueCache != null && valueCache.containsVal(indirection))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
                    java.io.Serializable cachedValue =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
                          (java.io.Serializable)valueCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
                    return cachedValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
                throw new IndirectionException(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
            int indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
            // end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
            boolean saveIsChunked = isChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
            isChunked = repIdUtil.isChunkedEncoding(vType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
            java.lang.Object value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
            String codebase_URL = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
            if (repIdUtil.isCodeBasePresent(vType)){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
                codebase_URL = read_codebase_URL();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
            // Read repository id
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
            String repositoryIDString
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
                = readRepositoryIds(vType, null, repositoryId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
            ValueFactory factory =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
               Utility.getFactory(null, codebase_URL, orb, repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
            if (isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
                chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
            valueIndirection = indirection;  // for callback
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
            value = factory.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
            handleEndOfValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
            readEndTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
            // Put into valueCache
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
            if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
                valueCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
            valueCache.put(value, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
            // allow for possible continuation chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
            isChunked = saveIsChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
            return (java.io.Serializable)value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
    private Class readClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
        String codebases = null, classRepId = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
        if (orb == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
            ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
            ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
            codebases = (String)read_value(java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
            classRepId = (String)read_value(java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
            // Pre-Merlin/J2EE 1.3 ORBs wrote the repository ID
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
            // and codebase strings in the wrong order.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
            classRepId = (String)read_value(java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
            codebases = (String)read_value(java.lang.String.class);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
            dprint("readClass codebases: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
                   + codebases
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
                   + " rep Id: "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
                   + classRepId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
        Class cl = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
        RepositoryIdInterface repositoryID
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
            = repIdStrs.getFromString(classRepId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
            cl = repositoryID.getClassFromType(codebases);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
        } catch(ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
            throw wrapper.cnfeReadClass( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
                cnfe, repositoryID.getClassName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
        } catch(MalformedURLException me) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
            throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
                me, repositoryID.getClassName(), codebases ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
        return cl;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
    private java.lang.Object readIDLValueWithHelper(ValueHelper helper, int indirection)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
        // look for two-argument static read method
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
        Method readMethod;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
            Class argTypes[] = {org.omg.CORBA.portable.InputStream.class, helper.get_class()};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
            readMethod = helper.getClass().getDeclaredMethod(kReadMethod, argTypes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
        catch(NoSuchMethodException nsme) { // must be boxed value helper
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
            java.lang.Object result = helper.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
        // found two-argument read method, so must be non-boxed value...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
        // ...create a blank instance
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
        java.lang.Object val = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
            val = helper.get_class().newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
        } catch(java.lang.InstantiationException ie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
            throw wrapper.couldNotInstantiateHelper( ie,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
                helper.get_class() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
        } catch(IllegalAccessException iae){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
            // Value's constructor is protected or private
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
            //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
            // So, use the helper to read the value.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
            //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
            // NOTE : This means that in this particular case a recursive ref.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
            // would fail.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
            return helper.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
        // add blank instance to cache table
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
        if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
            valueCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
        valueCache.put(val, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
        // if custom type, call unmarshal method
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
        if (val instanceof CustomMarshal && isCustomType(helper)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
            ((CustomMarshal)val).unmarshal(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
        // call two-argument read method using reflection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
            java.lang.Object args[] = {parent, val};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
            readMethod.invoke(helper, args);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
        } catch(IllegalAccessException iae2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
            throw wrapper.couldNotInvokeHelperReadMethod( iae2, helper.get_class() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
        } catch(InvocationTargetException ite){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
            throw wrapper.couldNotInvokeHelperReadMethod( ite, helper.get_class() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
    private java.lang.Object readBoxedIDLEntity(Class clazz, String codebase)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
        Class cls = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
            ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
            cls = Utility.loadClassForClass(clazz.getName()+"Helper", codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
                                                   clazzLoader, clazz, clazzLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
            final Class helperClass = cls ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
            final Class argTypes[] = {org.omg.CORBA.portable.InputStream.class};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
            // getDeclaredMethod requires RuntimePermission accessDeclaredMembers
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
            // if a different class loader is used (even though the javadoc says otherwise)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
            Method readMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
                readMethod = (Method)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
                    new PrivilegedExceptionAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
                        public java.lang.Object run() throws NoSuchMethodException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
                            return helperClass.getDeclaredMethod(kReadMethod, argTypes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
                );
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
            } catch (PrivilegedActionException pae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
                // this gets caught below
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
                throw (NoSuchMethodException)pae.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
            java.lang.Object args[] = {parent};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
            return readMethod.invoke(null, args);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
            throw wrapper.couldNotInvokeHelperReadMethod( cnfe, cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
        } catch(NoSuchMethodException nsme) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
            throw wrapper.couldNotInvokeHelperReadMethod( nsme, cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
        } catch(IllegalAccessException iae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
            throw wrapper.couldNotInvokeHelperReadMethod( iae, cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
        } catch(InvocationTargetException ite) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
            throw wrapper.couldNotInvokeHelperReadMethod( ite, cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
    private java.lang.Object readIDLValue(int indirection, String repId,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
                                          Class clazz, String codebase)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
        ValueFactory factory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
        // Always try to find a ValueFactory first, as required by the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
        // There are some complications here in the IDL 3.0 mapping (see 1.13.8),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
        // but basically we must always be able to override the DefaultFactory
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
        // or Helper mappings that are also used.  This appears to be the case
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
        // even in the boxed value cases.  The original code only did the lookup
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
        // in the case of class implementing either StreamableValue or CustomValue,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
        // but abstract valuetypes only implement ValueBase, and really require
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
        // the use of the repId to find a factory (including the DefaultFactory).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
            // use new-style OBV support (factory object)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
            factory = Utility.getFactory(clazz, codebase, orb, repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
        } catch (MARSHAL marshal) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
            // XXX log marshal at one of the INFO levels
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
            // Could not get a factory, so try alternatives
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
            if (!StreamableValue.class.isAssignableFrom(clazz) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
                !CustomValue.class.isAssignableFrom(clazz) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
                ValueBase.class.isAssignableFrom(clazz)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
                // use old-style OBV support (helper object)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
                BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
                if (helper instanceof ValueHelper)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
                    return readIDLValueWithHelper((ValueHelper)helper, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
                    return helper.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
                // must be a boxed IDLEntity, so make a reflective call to the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
                // helper's static read method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
                return readBoxedIDLEntity(clazz, codebase);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
        // If there was no error in getting the factory, use it.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
        valueIndirection = indirection;  // for callback
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
        return factory.read_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
     * End tags are only written for chunked valuetypes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
     * Before Merlin, our ORBs wrote end tags which took into account
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
     * all enclosing valuetypes.  This was changed by an interop resolution
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
     * (see details around chunkedValueNestingLevel) to only include
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
     * enclosing chunked types.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
     * ORB versioning and end tag compaction are handled here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
    private void readEndTag() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
        if (isChunked) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
            // Read the end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
            int anEndTag = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
            // End tags should always be negative, and the outermost
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
            // enclosing chunked valuetype should have a -1 end tag.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
            //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
            // handleEndOfValue should have assured that we were
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
            // at the end tag position!
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
            if (anEndTag >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
                throw wrapper.positiveEndTag( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
                    new Integer(anEndTag), new Integer( get_offset() - 4 ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
            // If the ORB is null, or if we're sure we're talking to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
            // a foreign ORB, Merlin, or something more recent, we
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
            // use the updated end tag computation, and are more strenuous
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
            // about the values.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
            if (orb == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
                ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
                ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
                // If the end tag we read was less than what we were expecting,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
                // then the sender must think it's sent more enclosing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
                // chunked valuetypes than we have.  Throw an exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
                if (anEndTag < chunkedValueNestingLevel)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
                    throw wrapper.unexpectedEnclosingValuetype(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
                        CompletionStatus.COMPLETED_MAYBE, new Integer( anEndTag ),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
                        new Integer( chunkedValueNestingLevel ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
                // If the end tag is bigger than what we expected, but
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
                // still negative, then the sender has done some end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
                // compaction.  We back up the stream 4 bytes so that the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
                // next time readEndTag is called, it will get down here
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
                // again.  Even with fragmentation, we'll always be able
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
                // to do this.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
                if (anEndTag != chunkedValueNestingLevel) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
                    bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
                 }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
                // When talking to Kestrel or Ladybird, we use our old
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
                // end tag rules and are less strict.  If the end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
                // isn't what we expected, we back up, assuming
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
                // compaction.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
                if (anEndTag != end_flag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
                    bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
            // This only keeps track of the enclosing chunked
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
            // valuetypes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
            chunkedValueNestingLevel++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
        // This keeps track of all enclosing valuetypes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
        end_flag++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
    protected int get_offset() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
    private void start_block() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
        // if (outerValueDone)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
        if (!isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
        // if called from alignAndCheck, need to reset blockLength
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
        // to avoid an infinite recursion loop on read_long() call
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
        blockLength = maxBlockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
        blockLength = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
        // Must remember where we began the chunk to calculate how far
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
        // along we are.  See notes above about chunkBeginPos.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
        if (blockLength > 0 && blockLength < maxBlockLength) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
            blockLength += get_offset();  // _REVISIT_ unsafe, should use a Java long
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
            // inBlock = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
            // System.out.println("start_block snooped a " + Integer.toHexString(blockLength));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
            // not a chunk length field
02bb8761fcce Initial load
duke
parents:
diff changeset
  1548
            blockLength = maxBlockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1549
02bb8761fcce Initial load
duke
parents:
diff changeset
  1550
            bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1551
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
    // Makes sure that if we were reading a chunked value, we end up
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
    // at the right place in the stream, no matter how little the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
    // unmarshalling code read.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
    // After calling this method, if we are chunking, we should be
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
    // in position to read the end tag.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
    private void handleEndOfValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
        // If we're not chunking, we don't have to worry about
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
        // skipping remaining chunks or finding end tags
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
        if (!isChunked)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
        // Skip any remaining chunks
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
        while (blockLength != maxBlockLength) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
        // Now look for the end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
        // This is a little wasteful since we're reading
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
        // this long up to 3 times in the worst cases (once
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
        // in start_block, once here, and once in readEndTag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
        // Peek next long
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
        int nextLong = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
        bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
        // We did find an end tag, so we're done.  readEndTag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
        // should take care of making sure it's the correct
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
        // end tag, etc.  Remember that since end tags,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
        // chunk lengths, and valuetags have non overlapping
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
        // ranges, we can tell by the value what the longs are.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
        if (nextLong < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
        if (nextLong == 0 || nextLong >= maxBlockLength) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
            // A custom marshaled valuetype left extra data
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
            // on the wire, and that data had another
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
            // nested value inside of it.  We've just
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
            // read the value tag or null of that nested value.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
            //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
            // In an attempt to get by it, we'll try to call
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
            // read_value() to get the nested value off of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
            // the wire.  Afterwards, we must call handleEndOfValue
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
            // recursively to read any further chunks that the containing
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
            // valuetype might still have after the nested
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
            // value.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
            read_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
            handleEndOfValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
            // This probably means that the code to skip chunks has
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
            // an error, and ended up setting blockLength to something
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
            // other than maxBlockLength even though we weren't
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
            // starting a new chunk.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
            throw wrapper.couldNotSkipBytes( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
                new Integer( nextLong ), new Integer( get_offset() ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
    private void end_block() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
        // if in a chunk, check for underflow or overflow
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
        if (blockLength != maxBlockLength) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
            if (blockLength == get_offset()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
                // Chunk ended correctly
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
                blockLength = maxBlockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
                // Skip over anything left by bad unmarshaling code (ex:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
                // a buggy custom unmarshaler).  See handleEndOfValue.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
                if (blockLength > get_offset()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
                    skipToOffset(blockLength);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
                    throw wrapper.badChunkLength( new Integer( blockLength ),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
                        new Integer( get_offset() ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
    private int readValueTag(){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
        // outerValueDone = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
        return read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
    public org.omg.CORBA.ORB orb() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
        return orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
    // ------------ End RMI related methods --------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
    public final void read_boolean_array(boolean[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
            value[i+offset] = read_boolean();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
    public final void read_char_array(char[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
            value[i+offset] = read_char();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
    public final void read_wchar_array(char[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
            value[i+offset] = read_wchar();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
    public final void read_short_array(short[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
            value[i+offset] = read_short();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1669
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1670
02bb8761fcce Initial load
duke
parents:
diff changeset
  1671
    public final void read_ushort_array(short[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
        read_short_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
    public final void read_long_array(int[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
            value[i+offset] = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
    public final void read_ulong_array(int[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
        read_long_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
    public final void read_longlong_array(long[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
            value[i+offset] = read_longlong();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
    public final void read_ulonglong_array(long[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
        read_longlong_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1693
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1694
02bb8761fcce Initial load
duke
parents:
diff changeset
  1695
    public final void read_float_array(float[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1696
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1697
            value[i+offset] = read_float();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1698
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1699
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1700
02bb8761fcce Initial load
duke
parents:
diff changeset
  1701
    public final void read_double_array(double[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1702
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1703
            value[i+offset] = read_double();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1704
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1705
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1706
02bb8761fcce Initial load
duke
parents:
diff changeset
  1707
    public final void read_any_array(org.omg.CORBA.Any[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1708
        for(int i=0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1709
            value[i+offset] = read_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1710
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1711
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1712
02bb8761fcce Initial load
duke
parents:
diff changeset
  1713
    //--------------------------------------------------------------------//
02bb8761fcce Initial load
duke
parents:
diff changeset
  1714
    // CDRInputStream state management.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1715
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1716
02bb8761fcce Initial load
duke
parents:
diff changeset
  1717
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1718
     * Are we at the end of the input stream?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1719
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1720
//     public final boolean isAtEnd() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1721
//      return bbwi.position() == bbwi.buflen;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1722
//     }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1723
02bb8761fcce Initial load
duke
parents:
diff changeset
  1724
//     public int available() throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1725
//         return bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1726
//     }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1727
02bb8761fcce Initial load
duke
parents:
diff changeset
  1728
    private String read_repositoryIds() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1729
02bb8761fcce Initial load
duke
parents:
diff changeset
  1730
        // Read # of repository ids
02bb8761fcce Initial load
duke
parents:
diff changeset
  1731
        int numRepIds = read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1732
        if (numRepIds == 0xffffffff) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1733
            int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1734
            if (repositoryIdCache != null && repositoryIdCache.containsOrderedVal(indirection))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1735
                return (String)repositoryIdCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1736
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1737
                throw wrapper.unableToLocateRepIdArray( new Integer( indirection ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1738
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1739
02bb8761fcce Initial load
duke
parents:
diff changeset
  1740
            // read first array element and store it as an indirection to the whole array
02bb8761fcce Initial load
duke
parents:
diff changeset
  1741
            int indirection = get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1742
            String repID = read_repositoryId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1743
            if (repositoryIdCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1744
                repositoryIdCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1745
            repositoryIdCache.put(repID, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1746
02bb8761fcce Initial load
duke
parents:
diff changeset
  1747
            // read and ignore the subsequent array elements, but put them in the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1748
            // indirection table in case there are later indirections back to them
02bb8761fcce Initial load
duke
parents:
diff changeset
  1749
            for (int i = 1; i < numRepIds; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1750
                read_repositoryId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1751
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1752
02bb8761fcce Initial load
duke
parents:
diff changeset
  1753
            return repID;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1754
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1755
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1756
02bb8761fcce Initial load
duke
parents:
diff changeset
  1757
    private final String read_repositoryId()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1758
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1759
        String result = readStringOrIndirection(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1760
02bb8761fcce Initial load
duke
parents:
diff changeset
  1761
        if (result == null) { // Indirection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1762
            int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1763
02bb8761fcce Initial load
duke
parents:
diff changeset
  1764
            if (repositoryIdCache != null && repositoryIdCache.containsOrderedVal(indirection))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1765
                return (String)repositoryIdCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1766
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1767
                throw wrapper.badRepIdIndirection( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1768
                    new Integer(bbwi.position()) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1769
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1770
            if (repositoryIdCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1771
                repositoryIdCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1772
            repositoryIdCache.put(result, stringIndirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1773
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1774
02bb8761fcce Initial load
duke
parents:
diff changeset
  1775
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1776
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1777
02bb8761fcce Initial load
duke
parents:
diff changeset
  1778
    private final String read_codebase_URL()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1779
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1780
        String result = readStringOrIndirection(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1781
02bb8761fcce Initial load
duke
parents:
diff changeset
  1782
        if (result == null) { // Indirection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1783
            int indirection = read_long() + get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1784
02bb8761fcce Initial load
duke
parents:
diff changeset
  1785
            if (codebaseCache != null && codebaseCache.containsVal(indirection))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1786
                return (String)codebaseCache.getKey(indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1787
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1788
                throw wrapper.badCodebaseIndirection(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1789
                    CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1790
                    new Integer(bbwi.position()) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1791
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1792
            if (codebaseCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1793
                codebaseCache = new CacheTable(orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1794
            codebaseCache.put(result, stringIndirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1795
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1796
02bb8761fcce Initial load
duke
parents:
diff changeset
  1797
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1798
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1799
02bb8761fcce Initial load
duke
parents:
diff changeset
  1800
    /* DataInputStream methods */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1801
02bb8761fcce Initial load
duke
parents:
diff changeset
  1802
    public java.lang.Object read_Abstract () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1803
        return read_abstract_interface();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1804
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1805
02bb8761fcce Initial load
duke
parents:
diff changeset
  1806
    public java.io.Serializable read_Value () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1807
        return read_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1808
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1809
02bb8761fcce Initial load
duke
parents:
diff changeset
  1810
    public void read_any_array (org.omg.CORBA.AnySeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1811
        read_any_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1812
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1813
02bb8761fcce Initial load
duke
parents:
diff changeset
  1814
    public void read_boolean_array (org.omg.CORBA.BooleanSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1815
        read_boolean_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1816
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1817
02bb8761fcce Initial load
duke
parents:
diff changeset
  1818
    public void read_char_array (org.omg.CORBA.CharSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1819
        read_char_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1820
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1821
02bb8761fcce Initial load
duke
parents:
diff changeset
  1822
    public void read_wchar_array (org.omg.CORBA.WCharSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1823
        read_wchar_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1824
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1825
02bb8761fcce Initial load
duke
parents:
diff changeset
  1826
    public void read_octet_array (org.omg.CORBA.OctetSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1827
        read_octet_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1828
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1829
02bb8761fcce Initial load
duke
parents:
diff changeset
  1830
    public void read_short_array (org.omg.CORBA.ShortSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1831
        read_short_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1832
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1833
02bb8761fcce Initial load
duke
parents:
diff changeset
  1834
    public void read_ushort_array (org.omg.CORBA.UShortSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1835
        read_ushort_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1836
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1837
02bb8761fcce Initial load
duke
parents:
diff changeset
  1838
    public void read_long_array (org.omg.CORBA.LongSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1839
        read_long_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1840
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1841
02bb8761fcce Initial load
duke
parents:
diff changeset
  1842
    public void read_ulong_array (org.omg.CORBA.ULongSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1843
        read_ulong_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1844
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1845
02bb8761fcce Initial load
duke
parents:
diff changeset
  1846
    public void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1847
        read_ulonglong_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1848
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1849
02bb8761fcce Initial load
duke
parents:
diff changeset
  1850
    public void read_longlong_array (org.omg.CORBA.LongLongSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1851
        read_longlong_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1852
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1853
02bb8761fcce Initial load
duke
parents:
diff changeset
  1854
    public void read_float_array (org.omg.CORBA.FloatSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1855
        read_float_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1856
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1857
02bb8761fcce Initial load
duke
parents:
diff changeset
  1858
    public void read_double_array (org.omg.CORBA.DoubleSeqHolder seq, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1859
        read_double_array(seq.value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1860
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1861
02bb8761fcce Initial load
duke
parents:
diff changeset
  1862
    public java.math.BigDecimal read_fixed(short digits, short scale) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1863
        // digits isn't really needed here
02bb8761fcce Initial load
duke
parents:
diff changeset
  1864
        StringBuffer buffer = read_fixed_buffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1865
        if (digits != buffer.length())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1866
            throw wrapper.badFixed( new Integer(digits),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1867
                new Integer(buffer.length()) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1868
        buffer.insert(digits - scale, '.');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1869
        return new BigDecimal(buffer.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1870
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1871
02bb8761fcce Initial load
duke
parents:
diff changeset
  1872
    // This method is unable to yield the correct scale.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1873
    public java.math.BigDecimal read_fixed() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1874
        return new BigDecimal(read_fixed_buffer().toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1875
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1876
02bb8761fcce Initial load
duke
parents:
diff changeset
  1877
    // Each octet contains (up to) two decimal digits.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1878
    // If the fixed type has an odd number of decimal digits, then the representation
02bb8761fcce Initial load
duke
parents:
diff changeset
  1879
    // begins with the first (most significant) digit.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1880
    // Otherwise, this first half-octet is all zero, and the first digit
02bb8761fcce Initial load
duke
parents:
diff changeset
  1881
    // is in the second half-octet.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1882
    // The sign configuration, in the last half-octet of the representation,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1883
    // is 0xD for negative numbers and 0xC for positive and zero values.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1884
    private StringBuffer read_fixed_buffer() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1885
        StringBuffer buffer = new StringBuffer(64);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1886
        byte doubleDigit;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1887
        int firstDigit;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1888
        int secondDigit;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1889
        boolean wroteFirstDigit = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1890
        boolean more = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1891
        while (more) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1892
            doubleDigit = this.read_octet();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1893
            firstDigit = (int)((doubleDigit & 0xf0) >> 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1894
            secondDigit = (int)(doubleDigit & 0x0f);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1895
            if (wroteFirstDigit || firstDigit != 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1896
                buffer.append(Character.forDigit(firstDigit, 10));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1897
                wroteFirstDigit = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1898
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1899
            if (secondDigit == 12) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1900
                // positive number or zero
02bb8761fcce Initial load
duke
parents:
diff changeset
  1901
                if ( ! wroteFirstDigit) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1902
                    // zero
02bb8761fcce Initial load
duke
parents:
diff changeset
  1903
                    return new StringBuffer("0.0");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1904
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1905
                    // positive number
02bb8761fcce Initial load
duke
parents:
diff changeset
  1906
                    // done
02bb8761fcce Initial load
duke
parents:
diff changeset
  1907
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1908
                more = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1909
            } else if (secondDigit == 13) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1910
                // negative number
02bb8761fcce Initial load
duke
parents:
diff changeset
  1911
                buffer.insert(0, '-');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1912
                more = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1913
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1914
                buffer.append(Character.forDigit(secondDigit, 10));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1915
                wroteFirstDigit = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1916
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1917
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1918
        return buffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1919
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1920
02bb8761fcce Initial load
duke
parents:
diff changeset
  1921
    private final static String _id = "IDL:omg.org/CORBA/DataInputStream:1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1922
    private final static String[] _ids = { _id };
02bb8761fcce Initial load
duke
parents:
diff changeset
  1923
02bb8761fcce Initial load
duke
parents:
diff changeset
  1924
    public String[] _truncatable_ids() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1925
        if (_ids == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1926
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1927
02bb8761fcce Initial load
duke
parents:
diff changeset
  1928
        return (String[])_ids.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1929
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1930
02bb8761fcce Initial load
duke
parents:
diff changeset
  1931
    /* for debugging */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1932
02bb8761fcce Initial load
duke
parents:
diff changeset
  1933
    public void printBuffer() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1934
        CDRInputStream_1_0.printBuffer(this.bbwi);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1935
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1936
02bb8761fcce Initial load
duke
parents:
diff changeset
  1937
    public static void printBuffer(ByteBufferWithInfo bbwi) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1938
02bb8761fcce Initial load
duke
parents:
diff changeset
  1939
        System.out.println("----- Input Buffer -----");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1940
        System.out.println();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1941
        System.out.println("Current position: " + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1942
        System.out.println("Total length : " + bbwi.buflen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1943
        System.out.println();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1944
02bb8761fcce Initial load
duke
parents:
diff changeset
  1945
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1946
02bb8761fcce Initial load
duke
parents:
diff changeset
  1947
            char[] charBuf = new char[16];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1948
02bb8761fcce Initial load
duke
parents:
diff changeset
  1949
            for (int i = 0; i < bbwi.buflen; i += 16) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1950
02bb8761fcce Initial load
duke
parents:
diff changeset
  1951
                int j = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1952
02bb8761fcce Initial load
duke
parents:
diff changeset
  1953
                // For every 16 bytes, there is one line
02bb8761fcce Initial load
duke
parents:
diff changeset
  1954
                // of output.  First, the hex output of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1955
                // the 16 bytes with each byte separated
02bb8761fcce Initial load
duke
parents:
diff changeset
  1956
                // by a space.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1957
                while (j < 16 && j + i < bbwi.buflen) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1958
                    int k = bbwi.byteBuffer.get(i + j);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1959
                    if (k < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1960
                        k = 256 + k;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1961
                    String hex = Integer.toHexString(k);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1962
                    if (hex.length() == 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1963
                        hex = "0" + hex;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1964
                    System.out.print(hex + " ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1965
                    j++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1966
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1967
02bb8761fcce Initial load
duke
parents:
diff changeset
  1968
                // Add any extra spaces to align the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1969
                // text column in case we didn't end
02bb8761fcce Initial load
duke
parents:
diff changeset
  1970
                // at 16
02bb8761fcce Initial load
duke
parents:
diff changeset
  1971
                while (j < 16) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1972
                    System.out.print("   ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1973
                    j++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1974
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1975
02bb8761fcce Initial load
duke
parents:
diff changeset
  1976
                // Now output the ASCII equivalents.  Non-ASCII
02bb8761fcce Initial load
duke
parents:
diff changeset
  1977
                // characters are shown as periods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1978
                int x = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1979
                while (x < 16 && x + i < bbwi.buflen) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1980
                    if (ORBUtility.isPrintable((char)bbwi.byteBuffer.get(i + x)))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1981
                        charBuf[x] = (char)bbwi.byteBuffer.get(i + x);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1982
                    else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1983
                        charBuf[x] = '.';
02bb8761fcce Initial load
duke
parents:
diff changeset
  1984
                    x++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1985
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1986
                System.out.println(new String(charBuf, 0, x));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1987
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1988
02bb8761fcce Initial load
duke
parents:
diff changeset
  1989
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1990
            t.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1991
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1992
02bb8761fcce Initial load
duke
parents:
diff changeset
  1993
        System.out.println("------------------------");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1994
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1995
02bb8761fcce Initial load
duke
parents:
diff changeset
  1996
    public ByteBuffer getByteBuffer() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1997
        ByteBuffer result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1998
        if (bbwi != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1999
            result = bbwi.byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2000
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2001
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2002
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2003
02bb8761fcce Initial load
duke
parents:
diff changeset
  2004
    public int getBufferLength() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2005
        return bbwi.buflen;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2006
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2007
02bb8761fcce Initial load
duke
parents:
diff changeset
  2008
    public void setBufferLength(int value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2009
        bbwi.buflen = value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2010
        bbwi.byteBuffer.limit(bbwi.buflen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2011
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2012
02bb8761fcce Initial load
duke
parents:
diff changeset
  2013
    public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2014
        this.bbwi = bbwi;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2015
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2016
02bb8761fcce Initial load
duke
parents:
diff changeset
  2017
    public void setByteBuffer(ByteBuffer byteBuffer) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2018
        bbwi.byteBuffer = byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2019
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2020
02bb8761fcce Initial load
duke
parents:
diff changeset
  2021
    public int getIndex() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2022
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2023
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2024
02bb8761fcce Initial load
duke
parents:
diff changeset
  2025
    public void setIndex(int value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2026
        bbwi.position(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2027
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2028
02bb8761fcce Initial load
duke
parents:
diff changeset
  2029
    public boolean isLittleEndian() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2030
        return littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2031
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2032
02bb8761fcce Initial load
duke
parents:
diff changeset
  2033
    public void orb(org.omg.CORBA.ORB orb) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2034
        this.orb = (ORB)orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2035
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2036
02bb8761fcce Initial load
duke
parents:
diff changeset
  2037
    public BufferManagerRead getBufferManager() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2038
        return bufferManagerRead;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2039
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2040
02bb8761fcce Initial load
duke
parents:
diff changeset
  2041
    private void skipToOffset(int offset) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2042
02bb8761fcce Initial load
duke
parents:
diff changeset
  2043
        // Number of bytes to skip
02bb8761fcce Initial load
duke
parents:
diff changeset
  2044
        int len = offset - get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2045
02bb8761fcce Initial load
duke
parents:
diff changeset
  2046
        int n = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2047
02bb8761fcce Initial load
duke
parents:
diff changeset
  2048
        while (n < len) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2049
            int avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2050
            int bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2051
            int wanted;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2052
02bb8761fcce Initial load
duke
parents:
diff changeset
  2053
            avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2054
            if (avail <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2055
                grow(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2056
                avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2057
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2058
02bb8761fcce Initial load
duke
parents:
diff changeset
  2059
            wanted = len - n;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2060
            bytes = (wanted < avail) ? wanted : avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2061
            bbwi.position(bbwi.position() + bytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2062
            n += bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2063
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2064
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2065
02bb8761fcce Initial load
duke
parents:
diff changeset
  2066
02bb8761fcce Initial load
duke
parents:
diff changeset
  2067
    // Mark and reset -------------------------------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
  2068
02bb8761fcce Initial load
duke
parents:
diff changeset
  2069
    protected MarkAndResetHandler markAndResetHandler = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2070
02bb8761fcce Initial load
duke
parents:
diff changeset
  2071
    protected class StreamMemento
02bb8761fcce Initial load
duke
parents:
diff changeset
  2072
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2073
        // These are the fields that may change after marking
02bb8761fcce Initial load
duke
parents:
diff changeset
  2074
        // the stream position, so we need to save them.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2075
        private int blockLength_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2076
        private int end_flag_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2077
        private int chunkedValueNestingLevel_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2078
        private int valueIndirection_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2079
        private int stringIndirection_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2080
        private boolean isChunked_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2081
        private javax.rmi.CORBA.ValueHandler valueHandler_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2082
        private ByteBufferWithInfo bbwi_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2083
        private boolean specialNoOptionalDataState_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2084
02bb8761fcce Initial load
duke
parents:
diff changeset
  2085
        public StreamMemento()
02bb8761fcce Initial load
duke
parents:
diff changeset
  2086
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2087
            blockLength_ = blockLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2088
            end_flag_ = end_flag;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2089
            chunkedValueNestingLevel_ = chunkedValueNestingLevel;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2090
            valueIndirection_ = valueIndirection;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2091
            stringIndirection_ = stringIndirection;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2092
            isChunked_ = isChunked;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2093
            valueHandler_ = valueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2094
            specialNoOptionalDataState_ = specialNoOptionalDataState;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2095
            bbwi_ = new ByteBufferWithInfo(bbwi);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2096
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2097
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2098
02bb8761fcce Initial load
duke
parents:
diff changeset
  2099
    public java.lang.Object createStreamMemento() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2100
        return new StreamMemento();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2101
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2102
02bb8761fcce Initial load
duke
parents:
diff changeset
  2103
    public void restoreInternalState(java.lang.Object streamMemento) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2104
02bb8761fcce Initial load
duke
parents:
diff changeset
  2105
        StreamMemento mem = (StreamMemento)streamMemento;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2106
02bb8761fcce Initial load
duke
parents:
diff changeset
  2107
        blockLength = mem.blockLength_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2108
        end_flag = mem.end_flag_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2109
        chunkedValueNestingLevel = mem.chunkedValueNestingLevel_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2110
        valueIndirection = mem.valueIndirection_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2111
        stringIndirection = mem.stringIndirection_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2112
        isChunked = mem.isChunked_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2113
        valueHandler = mem.valueHandler_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2114
        specialNoOptionalDataState = mem.specialNoOptionalDataState_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2115
        bbwi = mem.bbwi_;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2116
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2117
02bb8761fcce Initial load
duke
parents:
diff changeset
  2118
    public int getPosition() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2119
        return get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2120
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2121
02bb8761fcce Initial load
duke
parents:
diff changeset
  2122
    public void mark(int readlimit) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2123
        markAndResetHandler.mark(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2124
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2125
02bb8761fcce Initial load
duke
parents:
diff changeset
  2126
    public void reset() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2127
        markAndResetHandler.reset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2128
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2129
02bb8761fcce Initial load
duke
parents:
diff changeset
  2130
    // ---------------------------------- end Mark and Reset
02bb8761fcce Initial load
duke
parents:
diff changeset
  2131
02bb8761fcce Initial load
duke
parents:
diff changeset
  2132
    // Provides a hook so subclasses of CDRInputStream can provide
02bb8761fcce Initial load
duke
parents:
diff changeset
  2133
    // a CodeBase.  This ultimately allows us to grab a Connection
02bb8761fcce Initial load
duke
parents:
diff changeset
  2134
    // instance in IIOPInputStream, the only subclass where this
02bb8761fcce Initial load
duke
parents:
diff changeset
  2135
    // is actually used.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2136
    CodeBase getCodeBase() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2137
        return parent.getCodeBase();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2138
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2139
02bb8761fcce Initial load
duke
parents:
diff changeset
  2140
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2141
     * Attempts to find the class described by the given
02bb8761fcce Initial load
duke
parents:
diff changeset
  2142
     * repository ID string and expected type.  The first
02bb8761fcce Initial load
duke
parents:
diff changeset
  2143
     * attempt is to find the class locally, falling back
02bb8761fcce Initial load
duke
parents:
diff changeset
  2144
     * on the URL that came with the value.  The second
02bb8761fcce Initial load
duke
parents:
diff changeset
  2145
     * attempt is to use a URL from the remote CodeBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2146
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2147
    private Class getClassFromString(String repositoryIDString,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2148
                                     String codebaseURL,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2149
                                     Class expectedType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2150
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2151
        RepositoryIdInterface repositoryID
02bb8761fcce Initial load
duke
parents:
diff changeset
  2152
            = repIdStrs.getFromString(repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2153
02bb8761fcce Initial load
duke
parents:
diff changeset
  2154
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2155
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2156
                // First try to load the class locally, then use
02bb8761fcce Initial load
duke
parents:
diff changeset
  2157
                // the provided URL (if it isn't null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2158
                return repositoryID.getClassFromType(expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2159
                                                     codebaseURL);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2160
            } catch (ClassNotFoundException cnfeOuter) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2161
02bb8761fcce Initial load
duke
parents:
diff changeset
  2162
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2163
02bb8761fcce Initial load
duke
parents:
diff changeset
  2164
                    if (getCodeBase() == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2165
                        return null; // class cannot be loaded remotely.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2166
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2167
02bb8761fcce Initial load
duke
parents:
diff changeset
  2168
                    // Get a URL from the remote CodeBase and retry
02bb8761fcce Initial load
duke
parents:
diff changeset
  2169
                    codebaseURL = getCodeBase().implementation(repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2170
02bb8761fcce Initial load
duke
parents:
diff changeset
  2171
                    // Don't bother trying to find it locally again if
02bb8761fcce Initial load
duke
parents:
diff changeset
  2172
                    // we got a null URL
02bb8761fcce Initial load
duke
parents:
diff changeset
  2173
                    if (codebaseURL == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2174
                        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2175
02bb8761fcce Initial load
duke
parents:
diff changeset
  2176
                    return repositoryID.getClassFromType(expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2177
                                                         codebaseURL);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2178
                } catch (ClassNotFoundException cnfeInner) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2179
                    dprintThrowable(cnfeInner);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2180
                    // Failed to load the class
02bb8761fcce Initial load
duke
parents:
diff changeset
  2181
                    return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2182
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2183
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2184
        } catch (MalformedURLException mue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2185
            // Always report a bad URL
02bb8761fcce Initial load
duke
parents:
diff changeset
  2186
            throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2187
                mue, repositoryIDString, codebaseURL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2188
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2189
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2190
02bb8761fcce Initial load
duke
parents:
diff changeset
  2191
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2192
     * Attempts to find the class described by the given
02bb8761fcce Initial load
duke
parents:
diff changeset
  2193
     * repository ID string.  At most, three attempts are made:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2194
     * Try to find it locally, through the provided URL, and
02bb8761fcce Initial load
duke
parents:
diff changeset
  2195
     * finally, via a URL from the remote CodeBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2196
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2197
    private Class getClassFromString(String repositoryIDString,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2198
                                     String codebaseURL)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2199
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2200
        RepositoryIdInterface repositoryID
02bb8761fcce Initial load
duke
parents:
diff changeset
  2201
            = repIdStrs.getFromString(repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2202
02bb8761fcce Initial load
duke
parents:
diff changeset
  2203
        for (int i = 0; i < 3; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2204
02bb8761fcce Initial load
duke
parents:
diff changeset
  2205
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2206
02bb8761fcce Initial load
duke
parents:
diff changeset
  2207
                switch (i)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2208
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2209
                    case 0:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2210
                        // First try to load the class locally
02bb8761fcce Initial load
duke
parents:
diff changeset
  2211
                        return repositoryID.getClassFromType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2212
                    case 1:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2213
                        // Try to load the class using the provided
02bb8761fcce Initial load
duke
parents:
diff changeset
  2214
                        // codebase URL (falls out below)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2215
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2216
                    case 2:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2217
                        // Try to load the class using a URL from the
02bb8761fcce Initial load
duke
parents:
diff changeset
  2218
                        // remote CodeBase
02bb8761fcce Initial load
duke
parents:
diff changeset
  2219
                        codebaseURL = getCodeBase().implementation(repositoryIDString);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2220
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2221
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2222
02bb8761fcce Initial load
duke
parents:
diff changeset
  2223
                // Don't bother if the codebaseURL is null
02bb8761fcce Initial load
duke
parents:
diff changeset
  2224
                if (codebaseURL == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2225
                    continue;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2226
02bb8761fcce Initial load
duke
parents:
diff changeset
  2227
                return repositoryID.getClassFromType(codebaseURL);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2228
02bb8761fcce Initial load
duke
parents:
diff changeset
  2229
            } catch(ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2230
                // Will ultimately return null if all three
02bb8761fcce Initial load
duke
parents:
diff changeset
  2231
                // attempts fail, but don't do anything here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2232
            } catch (MalformedURLException mue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2233
                throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2234
                    mue, repositoryIDString, codebaseURL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2235
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2236
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2237
02bb8761fcce Initial load
duke
parents:
diff changeset
  2238
        // If we get here, we have failed to load the class
02bb8761fcce Initial load
duke
parents:
diff changeset
  2239
        dprint("getClassFromString failed with rep id "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2240
               + repositoryIDString
02bb8761fcce Initial load
duke
parents:
diff changeset
  2241
               + " and codebase "
02bb8761fcce Initial load
duke
parents:
diff changeset
  2242
               + codebaseURL);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2243
02bb8761fcce Initial load
duke
parents:
diff changeset
  2244
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2245
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2246
02bb8761fcce Initial load
duke
parents:
diff changeset
  2247
    // Utility method used to get chars from bytes
02bb8761fcce Initial load
duke
parents:
diff changeset
  2248
    char[] getConvertedChars(int numBytes,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2249
                             CodeSetConversion.BTCConverter converter) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2250
02bb8761fcce Initial load
duke
parents:
diff changeset
  2251
        // REVISIT - Look at CodeSetConversion.BTCConverter to see
02bb8761fcce Initial load
duke
parents:
diff changeset
  2252
        //           if it can work with an NIO ByteBuffer. We should
02bb8761fcce Initial load
duke
parents:
diff changeset
  2253
        //           avoid getting the bytes into an array if possible.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2254
02bb8761fcce Initial load
duke
parents:
diff changeset
  2255
        // To be honest, I doubt this saves much real time
02bb8761fcce Initial load
duke
parents:
diff changeset
  2256
        if (bbwi.buflen - bbwi.position() >= numBytes) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2257
            // If the entire string is in this buffer,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2258
            // just convert directly from the bbwi rather than
02bb8761fcce Initial load
duke
parents:
diff changeset
  2259
            // allocating and copying.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2260
            byte[] tmpBuf;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2261
            if (bbwi.byteBuffer.hasArray())
02bb8761fcce Initial load
duke
parents:
diff changeset
  2262
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2263
                tmpBuf = bbwi.byteBuffer.array();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2264
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2265
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  2266
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2267
                 tmpBuf = new byte[bbwi.buflen];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2268
                 // Microbenchmarks are showing a loop of ByteBuffer.get(int)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2269
                 // being faster than ByteBuffer.get(byte[], int, int).
02bb8761fcce Initial load
duke
parents:
diff changeset
  2270
                 for (int i = 0; i < bbwi.buflen; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2271
                     tmpBuf[i] = bbwi.byteBuffer.get(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2272
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2273
            char[] result = converter.getChars(tmpBuf,bbwi.position(),numBytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2274
02bb8761fcce Initial load
duke
parents:
diff changeset
  2275
            bbwi.position(bbwi.position() + numBytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2276
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2277
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2278
            // Stretches across buffers.  Unless we provide an
02bb8761fcce Initial load
duke
parents:
diff changeset
  2279
            // incremental conversion interface, allocate and
02bb8761fcce Initial load
duke
parents:
diff changeset
  2280
            // copy the bytes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2281
            byte[] bytes = new byte[numBytes];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2282
            read_octet_array(bytes, 0, bytes.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2283
02bb8761fcce Initial load
duke
parents:
diff changeset
  2284
            return converter.getChars(bytes, 0, numBytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2285
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2286
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2287
02bb8761fcce Initial load
duke
parents:
diff changeset
  2288
    protected CodeSetConversion.BTCConverter getCharConverter() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2289
        if (charConverter == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2290
            charConverter = parent.createCharBTCConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2291
02bb8761fcce Initial load
duke
parents:
diff changeset
  2292
        return charConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2293
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2294
02bb8761fcce Initial load
duke
parents:
diff changeset
  2295
    protected CodeSetConversion.BTCConverter getWCharConverter() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2296
        if (wcharConverter == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2297
            wcharConverter = parent.createWCharBTCConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2298
02bb8761fcce Initial load
duke
parents:
diff changeset
  2299
        return wcharConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2300
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2301
02bb8761fcce Initial load
duke
parents:
diff changeset
  2302
    protected void dprintThrowable(Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2303
        if (debug && t != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2304
            t.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2305
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2306
02bb8761fcce Initial load
duke
parents:
diff changeset
  2307
    protected void dprint(String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2308
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2309
            ORBUtility.dprint(this, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2310
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2311
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2312
02bb8761fcce Initial load
duke
parents:
diff changeset
  2313
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2314
     * Aligns the current position on the given octet boundary
02bb8761fcce Initial load
duke
parents:
diff changeset
  2315
     * if there are enough bytes available to do so.  Otherwise,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2316
     * it just returns.  This is used for some (but not all)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2317
     * GIOP 1.2 message headers.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2318
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2319
02bb8761fcce Initial load
duke
parents:
diff changeset
  2320
    void alignOnBoundary(int octetBoundary) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2321
        int needed = computeAlignment(bbwi.position(), octetBoundary);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2322
02bb8761fcce Initial load
duke
parents:
diff changeset
  2323
        if (bbwi.position() + needed <= bbwi.buflen)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2324
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2325
            bbwi.position(bbwi.position() + needed);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2326
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2327
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2328
02bb8761fcce Initial load
duke
parents:
diff changeset
  2329
    public void resetCodeSetConverters() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2330
        charConverter = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2331
        wcharConverter = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2333
02bb8761fcce Initial load
duke
parents:
diff changeset
  2334
    public void start_value() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2335
        // Read value tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  2336
        int vType = readValueTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2337
02bb8761fcce Initial load
duke
parents:
diff changeset
  2338
        if (vType == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2339
            // Stream needs to go into a state where it
02bb8761fcce Initial load
duke
parents:
diff changeset
  2340
            // throws standard exception until end_value
02bb8761fcce Initial load
duke
parents:
diff changeset
  2341
            // is called.  This means the sender didn't
02bb8761fcce Initial load
duke
parents:
diff changeset
  2342
            // send any custom data.  If the reader here
02bb8761fcce Initial load
duke
parents:
diff changeset
  2343
            // tries to read more, we need to throw an
02bb8761fcce Initial load
duke
parents:
diff changeset
  2344
            // exception before reading beyond where
02bb8761fcce Initial load
duke
parents:
diff changeset
  2345
            // we're supposed to
02bb8761fcce Initial load
duke
parents:
diff changeset
  2346
            specialNoOptionalDataState = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2347
02bb8761fcce Initial load
duke
parents:
diff changeset
  2348
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2349
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2350
02bb8761fcce Initial load
duke
parents:
diff changeset
  2351
        if (vType == 0xffffffff) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2352
            // One should never indirect to a custom wrapper
02bb8761fcce Initial load
duke
parents:
diff changeset
  2353
            throw wrapper.customWrapperIndirection(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2354
                CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2355
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2356
02bb8761fcce Initial load
duke
parents:
diff changeset
  2357
        if (repIdUtil.isCodeBasePresent(vType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2358
            throw wrapper.customWrapperWithCodebase(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2359
                CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2360
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2361
02bb8761fcce Initial load
duke
parents:
diff changeset
  2362
        if (repIdUtil.getTypeInfo(vType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2363
            != RepositoryIdUtility.SINGLE_REP_TYPE_INFO) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2364
            throw wrapper.customWrapperNotSingleRepid(
02bb8761fcce Initial load
duke
parents:
diff changeset
  2365
                CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2366
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2367
02bb8761fcce Initial load
duke
parents:
diff changeset
  2368
02bb8761fcce Initial load
duke
parents:
diff changeset
  2369
        // REVISIT - Could verify repository ID even though
02bb8761fcce Initial load
duke
parents:
diff changeset
  2370
        // it isn't used elsewhere
02bb8761fcce Initial load
duke
parents:
diff changeset
  2371
        read_repositoryId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2372
02bb8761fcce Initial load
duke
parents:
diff changeset
  2373
        // Note: isChunked should be true here.  Should have
02bb8761fcce Initial load
duke
parents:
diff changeset
  2374
        // been set to true in the containing value's read_value
02bb8761fcce Initial load
duke
parents:
diff changeset
  2375
        // method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2376
02bb8761fcce Initial load
duke
parents:
diff changeset
  2377
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2378
        end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2379
        chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2380
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2381
02bb8761fcce Initial load
duke
parents:
diff changeset
  2382
    public void end_value() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2383
02bb8761fcce Initial load
duke
parents:
diff changeset
  2384
        if (specialNoOptionalDataState) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2385
            specialNoOptionalDataState = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2386
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2387
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2388
02bb8761fcce Initial load
duke
parents:
diff changeset
  2389
        handleEndOfValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2390
        readEndTag();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2391
02bb8761fcce Initial load
duke
parents:
diff changeset
  2392
        // Note that isChunked should still be true here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2393
        // If the containing valuetype is the highest
02bb8761fcce Initial load
duke
parents:
diff changeset
  2394
        // chunked value, it will get set to false
02bb8761fcce Initial load
duke
parents:
diff changeset
  2395
        // at the end of read_value.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2396
02bb8761fcce Initial load
duke
parents:
diff changeset
  2397
        // allow for possible continuation chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  2398
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2399
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2400
02bb8761fcce Initial load
duke
parents:
diff changeset
  2401
    public void close() throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  2402
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2403
02bb8761fcce Initial load
duke
parents:
diff changeset
  2404
        // tell BufferManagerRead to release any ByteBuffers
02bb8761fcce Initial load
duke
parents:
diff changeset
  2405
        getBufferManager().close(bbwi);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2406
02bb8761fcce Initial load
duke
parents:
diff changeset
  2407
        // It's possible bbwi.byteBuffer is shared between
02bb8761fcce Initial load
duke
parents:
diff changeset
  2408
        // this InputStream and an OutputStream. Thus, we check
02bb8761fcce Initial load
duke
parents:
diff changeset
  2409
        // if the Input/Output streams are using the same ByteBuffer.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2410
        // If they sharing the same ByteBuffer we need to ensure only
02bb8761fcce Initial load
duke
parents:
diff changeset
  2411
        // one of those ByteBuffers are released to the ByteBufferPool.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2412
02bb8761fcce Initial load
duke
parents:
diff changeset
  2413
        if (bbwi != null && getByteBuffer() != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2414
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2415
            int bbHash = System.identityHashCode(bbwi.byteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2416
            MessageMediator messageMediator = parent.getMessageMediator();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2417
            if (messageMediator != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2418
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2419
                CDROutputObject outputObj =
02bb8761fcce Initial load
duke
parents:
diff changeset
  2420
                             (CDROutputObject)messageMediator.getOutputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2421
                if (outputObj != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2422
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2423
                    ByteBuffer outputBb = outputObj.getByteBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2424
02bb8761fcce Initial load
duke
parents:
diff changeset
  2425
                    int oBbHash = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2426
                    if (outputBb != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2427
                    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2428
                        oBbHash = System.identityHashCode(outputBb);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2429
                        if (bbHash == oBbHash)  // shared?
02bb8761fcce Initial load
duke
parents:
diff changeset
  2430
                        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2431
                            // Set OutputStream's ByteBuffer and bbwi to null
02bb8761fcce Initial load
duke
parents:
diff changeset
  2432
                            // so its ByteBuffer cannot be released to the pool
02bb8761fcce Initial load
duke
parents:
diff changeset
  2433
                            outputObj.setByteBuffer(null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2434
                            outputObj.setByteBufferWithInfo(null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2435
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2436
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2437
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2438
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2439
02bb8761fcce Initial load
duke
parents:
diff changeset
  2440
            // release this stream's ByteBuffer to the pool
02bb8761fcce Initial load
duke
parents:
diff changeset
  2441
            ByteBufferPool byteBufferPool = orb.getByteBufferPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2442
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2443
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2444
                // print address of ByteBuffer being released
02bb8761fcce Initial load
duke
parents:
diff changeset
  2445
                int bbAddress = System.identityHashCode(bbwi.byteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2446
                StringBuffer sb = new StringBuffer(80);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2447
                sb.append(".close - releasing ByteBuffer id (");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2448
                sb.append(bbAddress).append(") to ByteBufferPool.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2449
                String msg = sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2450
                dprint(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2451
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2452
            byteBufferPool.releaseByteBuffer(bbwi.byteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2453
            bbwi.byteBuffer = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2454
            bbwi = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2455
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2456
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2457
}