corba/src/share/classes/com/sun/corba/se/impl/encoding/CDROutputStream_1_0.java
author coffeys
Fri, 11 Nov 2011 10:16:17 +0000
changeset 11044 758078ec0816
parent 5555 b2b5ed3f0d0d
child 16136 f5a39cbcd82f
permissions -rw-r--r--
7091388: Regular unexplained npe's from corba libs after system has been running for days Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
11044
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package com.sun.corba.se.impl.encoding;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.io.ByteArrayOutputStream;
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.ByteArrayOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Method;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.lang.reflect.InvocationTargetException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.math.BigDecimal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.nio.ByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.security.PrivilegedExceptionAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.security.PrivilegedActionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.Stack;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import javax.rmi.CORBA.ValueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import javax.rmi.CORBA.ValueHandlerMultiFormat;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import org.omg.CORBA.CustomMarshal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import org.omg.CORBA.DataOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import org.omg.CORBA.TypeCodePackage.BadKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import org.omg.CORBA.Object;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import org.omg.CORBA.Principal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import org.omg.CORBA.VM_CUSTOM;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import org.omg.CORBA.VM_TRUNCATABLE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import org.omg.CORBA.VM_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import org.omg.CORBA.portable.IDLEntity;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import org.omg.CORBA.portable.CustomValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.CORBA.portable.StreamableValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import org.omg.CORBA.portable.BoxedValueHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import org.omg.CORBA.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import org.omg.CORBA.portable.ValueBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import com.sun.org.omg.CORBA.portable.ValueHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.pept.protocol.MessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.pept.transport.ByteBufferPool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import com.sun.corba.se.spi.ior.IORFactories;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.spi.orb.ORBVersionFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.spi.orb.ORBVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
import com.sun.corba.se.impl.encoding.MarshalOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
import com.sun.corba.se.impl.encoding.CodeSetConversion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
import com.sun.corba.se.impl.corba.TypeCodeImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
import com.sun.corba.se.impl.orbutil.CacheTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
import com.sun.corba.se.impl.orbutil.RepositoryIdStrings;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
import com.sun.corba.se.impl.orbutil.RepositoryIdUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
import com.sun.corba.se.impl.orbutil.RepositoryIdFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
public class CDROutputStream_1_0 extends CDROutputStreamBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    private static final int INDIRECTION_TAG = 0xffffffff;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    protected boolean littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    protected BufferManagerWrite bufferManagerWrite;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    ByteBufferWithInfo bbwi;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    protected ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    protected ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    protected boolean debug = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    protected int blockSizeIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    protected int blockSizePosition = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    protected byte streamFormatVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    private static final int DEFAULT_BUFFER_SIZE = 1024;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    private static final String kWriteMethod = "write";
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // Codebase cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    private CacheTable codebaseCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    // Value cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    private CacheTable valueCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    // Repository ID cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    private CacheTable repositoryIdCache = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    // Write end flag
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    private int end_flag = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    // Beginning with the resolution to interop issue 3526,
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    // only enclosing chunked valuetypes are taken into account
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    // when computing the nesting level.  However, we still need
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    // the old computation around for interoperability with our
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    // older ORBs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    private int chunkedValueNestingLevel = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    private boolean mustChunk = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    // In block marker
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    protected boolean inBlock = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    // Last end tag position
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    private int end_flag_position = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    private int end_flag_index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    // ValueHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    private ValueHandler valueHandler = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    // Repository ID handlers
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    private RepositoryIdUtility repIdUtil;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    private RepositoryIdStrings repIdStrs;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    // Code set converters (created when first needed)
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    private CodeSetConversion.CTBConverter charConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    private CodeSetConversion.CTBConverter wcharConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    // REVISIT - This should be re-factored so that including whether
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    // to use pool byte buffers or not doesn't need to be known.
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    public void init(org.omg.CORBA.ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
                        boolean littleEndian,
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
                        BufferManagerWrite bufferManager,
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
                        byte streamFormatVersion,
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                        boolean usePooledByteBuffers)
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        // ORB must not be null.  See CDROutputStream constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        this.orb = (ORB)orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
        this.wrapper = ORBUtilSystemException.get( this.orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
            CORBALogDomains.RPC_ENCODING ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        debug = this.orb.transportDebugFlag;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        this.littleEndian = littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        this.bufferManagerWrite = bufferManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        this.bbwi = new ByteBufferWithInfo(orb, bufferManager, usePooledByteBuffers);
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        this.streamFormatVersion = streamFormatVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        createRepositoryIdHandlers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    public void init(org.omg.CORBA.ORB orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                        boolean littleEndian,
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
                        BufferManagerWrite bufferManager,
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                        byte streamFormatVersion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
   {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
       init(orb, littleEndian, bufferManager, streamFormatVersion, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
   }
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    private final void createRepositoryIdHandlers()
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        if (orb != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
            // Get the appropriate versions based on the ORB version.  The
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            // ORB versioning info is only in the core ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            repIdUtil
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                = RepositoryIdFactory.getRepIdUtility(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            repIdStrs
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                = RepositoryIdFactory.getRepIdStringsFactory(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            // Get the latest versions
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            repIdUtil = RepositoryIdFactory.getRepIdUtility();
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
            repIdStrs = RepositoryIdFactory.getRepIdStringsFactory();
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    public BufferManagerWrite getBufferManager()
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        return bufferManagerWrite;
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    public byte[] toByteArray() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        byte[] it;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        it = new byte[bbwi.position()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
        // Micro-benchmarks show ByteBuffer.get(int) out perform the bulk
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        // ByteBuffer.get(byte[], offset, length).
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
        for (int i = 0; i < bbwi.position(); i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
            it[i] = bbwi.byteBuffer.get(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        return it;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    public GIOPVersion getGIOPVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        return GIOPVersion.V1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    // Called by Request and Reply message. Valid for GIOP versions >= 1.2 only.
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    // Illegal for GIOP versions < 1.2.
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
    void setHeaderPadding(boolean headerPadding) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        throw wrapper.giopVersionError();
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
    protected void handleSpecialChunkBegin(int requiredSize)
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        // No-op for GIOP 1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    protected void handleSpecialChunkEnd()
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
        // No-op for GIOP 1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    protected final int computeAlignment(int align) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        if (align > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            int incr = bbwi.position() & (align - 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            if (incr != 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                return align - incr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    protected void alignAndReserve(int align, int n) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        bbwi.position(bbwi.position() + computeAlignment(align));
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        if (bbwi.position() + n  > bbwi.buflen)
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            grow(align, n);
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    // Default implementation of grow.  Subclassers may override this.
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    // Always grow the single buffer. This needs to delegate
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    // fragmentation policy for IIOP 1.1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
    protected void grow(int align, int n)
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
        bbwi.needed = n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        bufferManagerWrite.overflow(bbwi);
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    public final void putEndian() throws SystemException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        write_boolean(littleEndian);
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    public final boolean littleEndian() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        return littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    void freeInternalCaches() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        if (codebaseCache != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
            codebaseCache.done();
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        if (valueCache != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
            valueCache.done();
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        if (repositoryIdCache != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
            repositoryIdCache.done();
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    // No such type in java
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    public final void write_longdouble(double x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        throw wrapper.longDoubleNotImplemented(
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            CompletionStatus.COMPLETED_MAYBE ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    public void write_octet(byte x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        // The 'if' stmt is commented out since we need the alignAndReserve to
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        // be called, particularly when the first body byte is written,
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        // to induce header padding to align the body on a 8-octet boundary,
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        // for GIOP versions 1.2 and above. Refer to internalWriteOctetArray()
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        // method that also has a similar change.
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        //if (bbwi.position() + 1 > bbwi.buflen)
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
            alignAndReserve(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
//      REVISIT - Should just use ByteBuffer.put(byte) and let it
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
//                increment the ByteBuffer position. This is true
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
//                for all write operations in this file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        bbwi.byteBuffer.put(bbwi.position(), x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        bbwi.position(bbwi.position() + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    public final void write_boolean(boolean x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        write_octet(x? (byte)1:(byte)0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    public void write_char(char x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        CodeSetConversion.CTBConverter converter = getCharConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
        converter.convert(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        // CORBA formal 99-10-07 15.3.1.6: "In the case of multi-byte encodings
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        // of characters, a single instance of the char type may only
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        // hold one octet of any multi-byte character encoding."
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
        if (converter.getNumBytes() > 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            throw wrapper.invalidSingleCharCtb(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        write_octet(converter.getBytes()[0]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
    // These wchar methods are only used when talking to
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    // legacy ORBs, now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    private final void writeLittleEndianWchar(char x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        bbwi.byteBuffer.put(bbwi.position(), (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        bbwi.position(bbwi.position() + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    private final void writeBigEndianWchar(char x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        bbwi.byteBuffer.put(bbwi.position(), (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        bbwi.position(bbwi.position() + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
    private final void writeLittleEndianShort(short x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        bbwi.byteBuffer.put(bbwi.position(), (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        bbwi.position(bbwi.position() + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    private final void writeBigEndianShort(short x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        bbwi.byteBuffer.put(bbwi.position(), (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        bbwi.position(bbwi.position() + 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    private final void writeLittleEndianLong(int x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        bbwi.byteBuffer.put(bbwi.position(), (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
        bbwi.byteBuffer.put(bbwi.position() + 2, (byte)((x >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
        bbwi.byteBuffer.put(bbwi.position() + 3, (byte)((x >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
        bbwi.position(bbwi.position() + 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    private final void writeBigEndianLong(int x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
        bbwi.byteBuffer.put(bbwi.position(), (byte)((x >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        bbwi.byteBuffer.put(bbwi.position() + 2, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        bbwi.byteBuffer.put(bbwi.position() + 3, (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        bbwi.position(bbwi.position() + 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    private final void writeLittleEndianLongLong(long x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        bbwi.byteBuffer.put(bbwi.position(), (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        bbwi.byteBuffer.put(bbwi.position() + 2, (byte)((x >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        bbwi.byteBuffer.put(bbwi.position() + 3, (byte)((x >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        bbwi.byteBuffer.put(bbwi.position() + 4, (byte)((x >>> 32) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        bbwi.byteBuffer.put(bbwi.position() + 5, (byte)((x >>> 40) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        bbwi.byteBuffer.put(bbwi.position() + 6, (byte)((x >>> 48) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        bbwi.byteBuffer.put(bbwi.position() + 7, (byte)((x >>> 56) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
        bbwi.position(bbwi.position() + 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
    private final void writeBigEndianLongLong(long x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
        bbwi.byteBuffer.put(bbwi.position(), (byte)((x >>> 56) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
        bbwi.byteBuffer.put(bbwi.position() + 1, (byte)((x >>> 48) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
        bbwi.byteBuffer.put(bbwi.position() + 2, (byte)((x >>> 40) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
        bbwi.byteBuffer.put(bbwi.position() + 3, (byte)((x >>> 32) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        bbwi.byteBuffer.put(bbwi.position() + 4, (byte)((x >>> 24) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        bbwi.byteBuffer.put(bbwi.position() + 5, (byte)((x >>> 16) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        bbwi.byteBuffer.put(bbwi.position() + 6, (byte)((x >>> 8) & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        bbwi.byteBuffer.put(bbwi.position() + 7, (byte)(x & 0xFF));
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        bbwi.position(bbwi.position() + 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    public void write_wchar(char x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
        // Don't allow transmission of wchar/wstring data with
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        // foreign ORBs since it's against the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        if (ORBUtility.isForeignORB(orb)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
            throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
        // If it's one of our legacy ORBs, do what they did:
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        alignAndReserve(2, 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
            writeLittleEndianWchar(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
            writeBigEndianWchar(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    public void write_short(short x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        alignAndReserve(2, 2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
            writeLittleEndianShort(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
            writeBigEndianShort(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    public final void write_ushort(short x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
        write_short(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
    public void write_long(int x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        alignAndReserve(4, 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            writeLittleEndianLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
            writeBigEndianLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
    public final void write_ulong(int x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
        write_long(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    public void write_longlong(long x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
        alignAndReserve(8, 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
            writeLittleEndianLongLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
            writeBigEndianLongLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    public final void write_ulonglong(long x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        write_longlong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
    public final void write_float(float x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        write_long(Float.floatToIntBits(x));
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
    public final void write_double(double x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
        write_longlong(Double.doubleToLongBits(x));
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    public void write_string(String value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
      writeString(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
    protected int writeString(String value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        if (value == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
        CodeSetConversion.CTBConverter converter = getCharConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        converter.convert(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        // A string is encoded as an unsigned CORBA long for the
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
        // number of bytes to follow (including a terminating null).
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        // There is only one octet per character in the string.
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
        int len = converter.getNumBytes() + 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
        handleSpecialChunkBegin(computeAlignment(4) + 4 + len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        write_long(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        int indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        internalWriteOctetArray(converter.getBytes(), 0, converter.getNumBytes());
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        // Write the null ending
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        write_octet((byte)0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
        return indirection;
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
    public void write_wstring(String value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        if (value == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        // Don't allow transmission of wchar/wstring data with
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
        // foreign ORBs since it's against the spec.
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        if (ORBUtility.isForeignORB(orb)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
            throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        // When talking to our legacy ORBs, do what they did:
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
        int len = value.length() + 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
        handleSpecialChunkBegin(4 + (len * 2) + computeAlignment(4));
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        write_long(len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        for (int i = 0; i < len - 1; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            write_wchar(value.charAt(i));
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        // Write the null ending
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
        write_short((short)0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    // Performs no checks and doesn't tamper with chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    void internalWriteOctetArray(byte[] value, int offset, int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        int n = offset;
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
        // This flag forces the alignAndReserve method to be called the
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
        // first time an octet is written. This is necessary to ensure
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
        // that the body is aligned on an 8-octet boundary. Note the 'if'
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
        // condition inside the 'while' loop below. Also, refer to the
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        // write_octet() method that has a similar change.
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
        boolean align = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
        while (n < length+offset) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
            int avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
            int bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
            int wanted;
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
            if ((bbwi.position() + 1 > bbwi.buflen) || align) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                align = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
                alignAndReserve(1, 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
            avail = bbwi.buflen - bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
            wanted = (length + offset) - n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
            bytes = (wanted < avail) ? wanted : avail;
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
            for (int i = 0; i < bytes; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                bbwi.byteBuffer.put(bbwi.position() + i, value[n+i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
            bbwi.position(bbwi.position() + bytes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
            n += bytes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
    public final void write_octet_array(byte b[], int offset, int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
        if ( b == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
        handleSpecialChunkBegin(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
        internalWriteOctetArray(b, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    public void write_Principal(Principal p)
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
        write_long(p.name().length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
        write_octet_array(p.name(), 0, p.name().length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
    public void write_any(Any any)
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
        if ( any == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
        write_TypeCode(any.type());
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        any.write_value(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    public void write_TypeCode(TypeCode tc)
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
        if ( tc == null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
        TypeCodeImpl tci;
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
        if (tc instanceof TypeCodeImpl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
            tci = (TypeCodeImpl)tc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
            tci = new TypeCodeImpl(orb, tc);
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
        tci.write_value((org.omg.CORBA_2_3.portable.OutputStream)parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
    public void write_Object(org.omg.CORBA.Object ref)
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        if (ref == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
            IOR nullIOR = IORFactories.makeIOR( orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            nullIOR.write(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
        // IDL to Java formal 01-06-06 1.21.4.2
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        if (ref instanceof org.omg.CORBA.LocalObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
            throw wrapper.writeLocalObject(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
        IOR ior = ORBUtility.connectAndGetIOR( orb, ref ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
        ior.write(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
        return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    // ------------ RMI related methods --------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    public void write_abstract_interface(java.lang.Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
        boolean corbaObject = false; // Assume value type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
        org.omg.CORBA.Object theObject = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
        // Is it a CORBA.Object?
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
        if (obj != null && obj instanceof org.omg.CORBA.Object) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
            // Yes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
            theObject = (org.omg.CORBA.Object)obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
            corbaObject = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
        // Write our flag...
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
        write_boolean(corbaObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
        // Now write out the object...
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
        if (corbaObject) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
            write_Object(theObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
                write_value((java.io.Serializable)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
            } catch(ClassCastException cce) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                if (obj instanceof java.io.Serializable)
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
                    throw cce;
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
                    ORBUtility.throwNotSerializableForCorba(obj.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    public void write_value(Serializable object, Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        write_value(object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
    private void writeWStringValue(String string) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
        int indirection = writeValueTag(mustChunk, true, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
        // Write WStringValue's repository ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
        write_repositoryId(repIdStrs.getWStringValueRepId());
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
        // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        updateIndirectionTable(indirection, string, string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
        // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
        write_wstring(string);
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
        writeEndTag(mustChunk);
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
    private void writeArray(Serializable array, Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
        if (valueHandler == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
            valueHandler = ORBUtility.createValueHandler(orb); //d11638
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
        int indirection = writeValueTag(mustChunk, true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
                                        Util.getCodebase(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
        // Write repository ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
        write_repositoryId(repIdStrs.createSequenceRepID(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
        // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
        updateIndirectionTable(indirection, array, array);
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
        // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
        if (valueHandler instanceof ValueHandlerMultiFormat) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
            ValueHandlerMultiFormat vh = (ValueHandlerMultiFormat)valueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
            vh.writeValue(parent, array, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
            valueHandler.writeValue(parent, array);
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
        writeEndTag(mustChunk);
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
    private void writeValueBase(org.omg.CORBA.portable.ValueBase object,
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
                                Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        // _REVISIT_ could check to see whether chunking really needed
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
        mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
        int indirection = writeValueTag(true, true, Util.getCodebase(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
        // Get rep id
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
        String repId = ((ValueBase)object)._truncatable_ids()[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
        // Write rep id
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
        write_repositoryId(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        updateIndirectionTable(indirection, object, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
        // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
        end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
        writeIDLValue(object, repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
        end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
        writeEndTag(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
    private void writeRMIIIOPValueType(Serializable object, Class clazz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
        if (valueHandler == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
            valueHandler = ORBUtility.createValueHandler(orb); //d11638
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
        Serializable key = object;
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
        // Allow the ValueHandler to call writeReplace on
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
        // the Serializable (if the method is present)
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
        object = valueHandler.writeReplace(key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
        if (object == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
            // Write null tag and return
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
            write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
        if (object != key) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
            if (valueCache != null && valueCache.containsKey(object)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
                writeIndirection(INDIRECTION_TAG, valueCache.getVal(object));
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
                return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
            clazz = object.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
        if (mustChunk || valueHandler.isCustomMarshaled(clazz)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
            mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
        int indirection = writeValueTag(mustChunk, true, Util.getCodebase(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
        // Write rep. id
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
        write_repositoryId(repIdStrs.createForJavaType(clazz));
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
        // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        updateIndirectionTable(indirection, object, key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
            // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
        if (valueHandler instanceof ValueHandlerMultiFormat) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
            ValueHandlerMultiFormat vh = (ValueHandlerMultiFormat)valueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
            vh.writeValue(parent, object, streamFormatVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
            valueHandler.writeValue(parent, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        writeEndTag(mustChunk);
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
    public void write_value(Serializable object, String repository_id) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
        // Handle null references
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        if (object == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
            // Write null tag and return
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
            write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
        // Handle shared references
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
        if (valueCache != null && valueCache.containsKey(object)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
            writeIndirection(INDIRECTION_TAG, valueCache.getVal(object));
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        Class clazz = object.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
        boolean oldMustChunk = mustChunk;
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
            mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
        if (inBlock)
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
        if (clazz.isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
            // Handle arrays
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
            writeArray(object, clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
        } else if (object instanceof org.omg.CORBA.portable.ValueBase) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
            // Handle IDL Value types
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
            writeValueBase((org.omg.CORBA.portable.ValueBase)object, clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        } else if (shouldWriteAsIDLEntity(object)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
            writeIDLEntity((IDLEntity)object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        } else if (object instanceof java.lang.String) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
            writeWStringValue((String)object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
        } else if (object instanceof java.lang.Class) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
            writeClass(repository_id, (Class)object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
            // RMI-IIOP value type
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
            writeRMIIIOPValueType(object, clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
        mustChunk = oldMustChunk;
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
        // Check to see if we need to start another block for a
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
        // possible outer value
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
    public void write_value(Serializable object)
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
        write_value(object, (String)null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
    public void write_value(Serializable object, org.omg.CORBA.portable.BoxedValueHelper factory)
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
        // Handle null references
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
        if (object == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
            // Write null tag and return
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
            write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
        // Handle shared references
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
        if ((valueCache != null) && valueCache.containsKey(object)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
            writeIndirection(INDIRECTION_TAG, valueCache.getVal(object));
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
        boolean oldMustChunk = mustChunk;
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
        boolean isCustom = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
        if (factory instanceof ValueHelper) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
            short modifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
                modifier = ((ValueHelper)factory).get_type().type_modifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
            } catch(BadKind ex) {  // tk_value_box
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
                modifier = VM_NONE.value;
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
            if (object instanceof CustomMarshal &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
                modifier == VM_CUSTOM.value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
                isCustom = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
                mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
            if (modifier == VM_TRUNCATABLE.value)
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
                mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
            if (inBlock)
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
            // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
            int indirection = writeValueTag(true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
                                            orb.getORBData().useRepId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
                                            Util.getCodebase(object.getClass())
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
                                           );
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
            if (orb.getORBData().useRepId()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
                write_repositoryId(factory.get_id());
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
            // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
            updateIndirectionTable(indirection, object, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
            // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
            if (isCustom)
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                ((CustomMarshal)object).marshal(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
                factory.write_value(parent, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
            // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
            writeEndTag(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
            // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
            int indirection = writeValueTag(false,
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
                                            orb.getORBData().useRepId(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
                                            Util.getCodebase(object.getClass())
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
                                           );
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
            if (orb.getORBData().useRepId()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
                write_repositoryId(factory.get_id());
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
            // Add indirection for object to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
            updateIndirectionTable(indirection, object, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
            // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
            // no need to test for custom on the non-chunked path
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
            factory.write_value(parent, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
            // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
            writeEndTag(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
        mustChunk = oldMustChunk;
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
        // Check to see if we need to start another block for a
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
        // possible outer value
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
    public int get_offset() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
    public void start_block() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
            dprint("CDROutputStream_1_0 start_block, position" + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
        //Move inBlock=true to after write_long since write_long might
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
        //trigger grow which will lead to erroneous behavior with a
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
        //missing blockSizeIndex.
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
        //inBlock = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
        // Save space in the buffer for block size
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
        //Has to happen after write_long since write_long could
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
        //trigger grow which is overridden by supper classes to
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        //depend on inBlock.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
        inBlock = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        blockSizePosition = get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
        // Remember where to put the size of the endblock less 4
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
        blockSizeIndex = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
            dprint("CDROutputStream_1_0 start_block, blockSizeIndex "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
                   + blockSizeIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
    // Utility method which will hopefully decrease chunking complexity
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
    // by allowing us to end_block and update chunk lengths without
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
    // calling alignAndReserve.  Otherwise, it's possible to get into
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
    // recursive scenarios which lose the chunking state.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
    protected void writeLongWithoutAlign(int x) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
        if (littleEndian) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
            writeLittleEndianLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
            writeBigEndianLong(x);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
    public void end_block() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
            dprint("CDROutputStream_1_0.java end_block");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
        if (!inBlock)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
            dprint("CDROutputStream_1_0.java end_block, in a block");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
        inBlock = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
        // Test to see if the block was of zero length
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
        // If so, remove the block instead of ending it
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
        // (This can happen if the last field written
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
        //  in a value was another value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
        if (get_offset() == blockSizePosition) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
            // Need to assert that blockSizeIndex == bbwi.position()?  REVISIT
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
            bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
            blockSizeIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
            blockSizePosition = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
        int oldSize = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
        bbwi.position(blockSizeIndex - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
        writeLongWithoutAlign(oldSize - blockSizeIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
        bbwi.position(oldSize);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
        blockSizeIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
        blockSizePosition = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
        // System.out.println("      post end_block: " + get_offset() + " " + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
    public org.omg.CORBA.ORB orb()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
        return orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
    // ------------ End RMI related methods --------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
    public final void write_boolean_array(boolean[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
        handleSpecialChunkBegin(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
            write_boolean(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
    public final void write_char_array(char[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
        handleSpecialChunkBegin(length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
            write_char(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
    public void write_wchar_array(char[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
        handleSpecialChunkBegin(computeAlignment(2) + (length * 2));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
            write_wchar(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
    public final void write_short_array(short[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
        handleSpecialChunkBegin(computeAlignment(2) + (length * 2));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
            write_short(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
    public final void write_ushort_array(short[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
        write_short_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
    public final void write_long_array(int[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
        handleSpecialChunkBegin(computeAlignment(4) + (length * 4));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
            write_long(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
    public final void write_ulong_array(int[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
        write_long_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
    public final void write_longlong_array(long[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
        handleSpecialChunkBegin(computeAlignment(8) + (length * 8));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
            write_longlong(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
    public final void write_ulonglong_array(long[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
        write_longlong_array(value, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
    public final void write_float_array(float[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
        handleSpecialChunkBegin(computeAlignment(4) + (length * 4));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
            write_float(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
    public final void write_double_array(double[]value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
        handleSpecialChunkBegin(computeAlignment(8) + (length * 8));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
        for (int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
            write_double(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
        // This will only have an effect if we're already chunking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
    public void write_string_array(String[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
        for(int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
            write_string(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
    public void write_wstring_array(String[] value, int offset, int length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
        if ( value == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
            throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
        for(int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
            write_wstring(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
    public final void write_any_array(org.omg.CORBA.Any value[], int offset, int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
        for(int i = 0; i < length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
            write_any(value[offset + i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
    //--------------------------------------------------------------------//
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
    // CDROutputStream state management.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
    public void writeTo(java.io.OutputStream s)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
        throws java.io.IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
        byte[] tmpBuf = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
        if (bbwi.byteBuffer.hasArray())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
            tmpBuf = bbwi.byteBuffer.array();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
            int size = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
            tmpBuf = new byte[size];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
            // Micro-benchmarks are showing a loop of ByteBuffer.get(int) is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
            // faster than ByteBuffer.get(byte[], offset, length)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
            for (int i = 0; i < size; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
                tmpBuf[i] = bbwi.byteBuffer.get(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
        s.write(tmpBuf, 0, bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
    public void writeOctetSequenceTo(org.omg.CORBA.portable.OutputStream s) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
        byte[] buf = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
        if (bbwi.byteBuffer.hasArray())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
            buf = bbwi.byteBuffer.array();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
            int size = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
            buf = new byte[size];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
            // Micro-benchmarks are showing a loop of ByteBuffer.get(int) is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
            // faster than ByteBuffer.get(byte[], offset, length)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
            for (int i = 0; i < size; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
                buf[i] = bbwi.byteBuffer.get(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
        s.write_long(bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
        s.write_octet_array(buf, 0, bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
    public final int getSize() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
    public int getIndex() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
        return bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
    public boolean isLittleEndian() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
        return littleEndian;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
    public void setIndex(int value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
        bbwi.position(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
    public ByteBufferWithInfo getByteBufferWithInfo() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
        return bbwi;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
    public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
        this.bbwi = bbwi;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
    public ByteBuffer getByteBuffer() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
        ByteBuffer result = null;;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
        if (bbwi != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
            result = bbwi.byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
    public void setByteBuffer(ByteBuffer byteBuffer) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
        bbwi.byteBuffer = byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
    private final void updateIndirectionTable(int indirection, java.lang.Object object,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
                                              java.lang.Object key) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
        // int indirection = get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
        if (valueCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
            valueCache = new CacheTable(orb,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
        valueCache.put(object, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
        if (key != object)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
            valueCache.put(key, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
    private final void write_repositoryId(String id) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
        // Use an indirection if available
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
        if (repositoryIdCache != null && repositoryIdCache.containsKey(id)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
            writeIndirection(INDIRECTION_TAG, repositoryIdCache.getVal(id));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
        // Write it as a string.  Note that we have already done the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
        // special case conversion of non-Latin-1 characters to escaped
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
        // Latin-1 sequences in RepositoryId.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
        // It's not a good idea to cache them now that we can have
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
        // multiple code sets.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
        int indirection = writeString(id);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
        // Add indirection for id to indirection table
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
        if (repositoryIdCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
        repositoryIdCache = new CacheTable(orb,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
        repositoryIdCache.put(id, indirection);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
    private void write_codebase(String str, int pos) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
        if (codebaseCache != null && codebaseCache.containsKey(str)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
            writeIndirection(INDIRECTION_TAG, codebaseCache.getVal(str));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
        else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
            write_string(str);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
            if (codebaseCache == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
                codebaseCache = new CacheTable(orb,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
            codebaseCache.put(str, pos);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
    private final int writeValueTag(boolean chunkIt, boolean useRepId,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
                                    String codebase) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
        int indirection = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
        if (chunkIt && !useRepId){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
            if (codebase == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
                write_long(repIdUtil.getStandardRMIChunkedNoRepStrId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
                write_long(repIdUtil.getCodeBaseRMIChunkedNoRepStrId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
                write_codebase(codebase, get_offset());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
        } else if (chunkIt && useRepId){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
            if (codebase == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
                write_long(repIdUtil.getStandardRMIChunkedId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
                write_long(repIdUtil.getCodeBaseRMIChunkedId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
                write_codebase(codebase, get_offset());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
        } else if (!chunkIt && !useRepId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
            if (codebase == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
                write_long(repIdUtil.getStandardRMIUnchunkedNoRepStrId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
                write_long(repIdUtil.getCodeBaseRMIUnchunkedNoRepStrId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
                write_codebase(codebase, get_offset());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
        } else if (!chunkIt && useRepId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
            if (codebase == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
                write_long(repIdUtil.getStandardRMIUnchunkedId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
                write_long(repIdUtil.getCodeBaseRMIUnchunkedId());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
                indirection = get_offset() - 4;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
                write_codebase(codebase, get_offset());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
        return indirection;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
    private void writeIDLValue(Serializable object, String repID)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
        if (object instanceof StreamableValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
            ((StreamableValue)object)._write(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
        } else if (object instanceof CustomValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
            ((CustomValue)object).marshal(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
            BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
            boolean isCustom = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
            if (helper instanceof ValueHelper && object instanceof CustomMarshal) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
                    if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
                        isCustom = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
                } catch(BadKind ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
                    throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
                        ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
            if (isCustom)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
                ((CustomMarshal)object).marshal(parent);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
                helper.write_value(parent, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
    // Handles end tag compaction...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
    private void writeEndTag(boolean chunked){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
        if (chunked) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
            if (get_offset() == end_flag_position) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
                if (bbwi.position() == end_flag_index) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
                    // We are exactly at the same position and index as the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
                    // end of the last end tag.  Thus, we can back up over it
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
                    // and compact the tags.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
                    bbwi.position(bbwi.position() - 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
                    // Special case in which we're at the beginning of a new
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
                    // fragment, but the position is the same.  We can't back up,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
                    // so we just write the new end tag without compaction.  This
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
                    // occurs when a value ends and calls start_block to open a
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
                    // continuation chunk, but it's called at the very end of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
                    // a fragment.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
            writeNestingLevel();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
            // Remember the last index and position.  These are only used when chunking.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
            end_flag_index = bbwi.position();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
            end_flag_position = get_offset();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
            chunkedValueNestingLevel++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
        // Increment the nesting level
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
        end_flag++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
     * Handles ORB versioning of the end tag.  Should only
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
     * be called if chunking.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
     * If talking to our older ORBs (Standard Extension,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
     * Kestrel, and Ladybird), write the end flag that takes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
     * into account all enclosing valuetypes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
     * If talking a newer or foreign ORB, or if the orb
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
     * instance is null, write the end flag that only takes
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
     * into account the enclosing chunked valuetypes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
    private void writeNestingLevel() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
        if (orb == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
            ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
            ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
            write_long(chunkedValueNestingLevel);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
            write_long(end_flag);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
    private void writeClass(String repository_id, Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
        if (repository_id == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
            repository_id = repIdStrs.getClassDescValueRepId();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
        int indirection = writeValueTag(mustChunk, true, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
        updateIndirectionTable(indirection, clz, clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
        write_repositoryId(repository_id);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
            // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
            chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
            end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
        writeClassBody(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
        if (mustChunk)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
        writeEndTag(mustChunk);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
    // Pre-Merlin/J2EE 1.3 ORBs wrote the repository ID
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
    // and codebase strings in the wrong order.  This handles
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
    // backwards compatibility.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
    private void writeClassBody(Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
        if (orb == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
            ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
            ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
            write_value(Util.getCodebase(clz));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
            write_value(repIdStrs.createForAnyType(clz));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
            write_value(repIdStrs.createForAnyType(clz));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
            write_value(Util.getCodebase(clz));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
    // Casts and returns an Object as a Serializable
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
    // This is required for JDK 1.1 only to avoid VerifyErrors when
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
    // passing arrays as Serializable
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
    // private java.io.Serializable make_serializable(java.lang.Object object)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
    // {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
    //  return (java.io.Serializable)object;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
    // }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
    private boolean shouldWriteAsIDLEntity(Serializable object)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
        return ((object instanceof IDLEntity) && (!(object instanceof ValueBase)) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
                (!(object instanceof org.omg.CORBA.Object)));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
    private void writeIDLEntity(IDLEntity object) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
        // _REVISIT_ could check to see whether chunking really needed
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
        mustChunk = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
        String repository_id = repIdStrs.createForJavaType(object);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
        Class clazz = object.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
        String codebase = Util.getCodebase(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
        int indirection = writeValueTag(true, true, codebase);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1548
        updateIndirectionTable(indirection, object, object);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1549
02bb8761fcce Initial load
duke
parents:
diff changeset
  1550
        // Write rep. id
02bb8761fcce Initial load
duke
parents:
diff changeset
  1551
        write_repositoryId(repository_id);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
        // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
        end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
        chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
        start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
        // Write the IDLEntity using reflection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
            ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
            final Class helperClass = Utility.loadClassForClass(clazz.getName()+"Helper", codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
                                                   clazzLoader, clazz, clazzLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
            final Class argTypes[] = {org.omg.CORBA.portable.OutputStream.class, clazz};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
            // getDeclaredMethod requires RuntimePermission accessDeclaredMembers
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
            // if a different class loader is used (even though the javadoc says otherwise)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
            Method writeMethod = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
                writeMethod = (Method)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
                    new PrivilegedExceptionAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
                        public java.lang.Object run() throws NoSuchMethodException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
                            return helperClass.getDeclaredMethod(kWriteMethod, argTypes);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
                );
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
            } catch (PrivilegedActionException pae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
                // this gets caught below
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
                throw (NoSuchMethodException)pae.getException();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
            java.lang.Object args[] = {parent, object};
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
            writeMethod.invoke(null, args);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
            throw wrapper.errorInvokingHelperWrite( CompletionStatus.COMPLETED_MAYBE, cnfe ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
        } catch(NoSuchMethodException nsme) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
            throw wrapper.errorInvokingHelperWrite( CompletionStatus.COMPLETED_MAYBE, nsme ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
        } catch(IllegalAccessException iae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
            throw wrapper.errorInvokingHelperWrite( CompletionStatus.COMPLETED_MAYBE, iae ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
        } catch(InvocationTargetException ite) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
            throw wrapper.errorInvokingHelperWrite( CompletionStatus.COMPLETED_MAYBE, ite ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
        end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
        // Write end tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
        writeEndTag(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
    /* DataOutputStream methods */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
    public void write_Abstract (java.lang.Object value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
        write_abstract_interface(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
    public void write_Value (java.io.Serializable value) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
        write_value(value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
    // This will stay a custom add-on until the java-rtf issue is resolved.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
    // Then it should be declared in org.omg.CORBA.portable.OutputStream.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
    // Pads the string representation of bigDecimal with zeros to fit the given
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
    // digits and scale before it gets written to the stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
    public void write_fixed(java.math.BigDecimal bigDecimal, short digits, short scale) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
        String string = bigDecimal.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
        String integerPart;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
        String fractionPart;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
        StringBuffer stringBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
        // Get rid of the sign
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
        if (string.charAt(0) == '-' || string.charAt(0) == '+') {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
            string = string.substring(1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
        // Determine integer and fraction parts
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
        int dotIndex = string.indexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
        if (dotIndex == -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
            integerPart = string;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
            fractionPart = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
        } else if (dotIndex == 0 ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
            integerPart = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
            fractionPart = string;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
            integerPart = string.substring(0, dotIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
            fractionPart = string.substring(dotIndex + 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
        // Pad both parts with zeros as necessary
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
        stringBuffer = new StringBuffer(digits);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
        if (fractionPart != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
            stringBuffer.append(fractionPart);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
        while (stringBuffer.length() < scale) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
            stringBuffer.append('0');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
        if (integerPart != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
            stringBuffer.insert(0, integerPart);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
        while (stringBuffer.length() < digits) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
            stringBuffer.insert(0, '0');
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
        // This string contains no sign or dot
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
        this.write_fixed(stringBuffer.toString(), bigDecimal.signum());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
    // This method should be remove by the java-rtf issue.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
    // Right now the scale and digits information of the type code is lost.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
    public void write_fixed(java.math.BigDecimal bigDecimal) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
        // This string might contain sign and/or dot
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
        this.write_fixed(bigDecimal.toString(), bigDecimal.signum());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
    // The string may contain a sign and dot
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
    public void write_fixed(String string, int signum) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
        int stringLength = string.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
        // Each octet contains (up to) two decimal digits
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
        byte doubleDigit = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
        char ch;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
        byte digit;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
02bb8761fcce Initial load
duke
parents:
diff changeset
  1669
        // First calculate the length of the string without optional sign and dot
02bb8761fcce Initial load
duke
parents:
diff changeset
  1670
        int numDigits = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1671
        for (int i=0; i<stringLength; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
            ch = string.charAt(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
            if (ch == '-' || ch == '+' || ch == '.')
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
                continue;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
            numDigits++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
        for (int i=0; i<stringLength; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
            ch = string.charAt(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
            if (ch == '-' || ch == '+' || ch == '.')
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
                continue;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
            digit = (byte)Character.digit(ch, 10);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
            if (digit == -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
                throw wrapper.badDigitInFixed( CompletionStatus.COMPLETED_MAYBE ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
            // If the fixed type has an odd number of decimal digits,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
            // then the representation begins with the first (most significant) digit.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
            // Otherwise, this first half-octet is all zero, and the first digit
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
            // is in the second half-octet.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
            if (numDigits % 2 == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
                doubleDigit |= digit;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
                this.write_octet(doubleDigit);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
                doubleDigit = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1693
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1694
                doubleDigit |= (digit << 4);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1695
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1696
            numDigits--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1697
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1698
        // The sign configuration, in the last half-octet of the representation,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1699
        // is 0xD for negative numbers and 0xC for positive and zero values
02bb8761fcce Initial load
duke
parents:
diff changeset
  1700
        if (signum == -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1701
            doubleDigit |= 0xd;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1702
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1703
            doubleDigit |= 0xc;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1704
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1705
        this.write_octet(doubleDigit);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1706
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1707
02bb8761fcce Initial load
duke
parents:
diff changeset
  1708
    private final static String _id = "IDL:omg.org/CORBA/DataOutputStream:1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1709
    private final static String[] _ids = { _id };
02bb8761fcce Initial load
duke
parents:
diff changeset
  1710
02bb8761fcce Initial load
duke
parents:
diff changeset
  1711
    public String[] _truncatable_ids() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1712
        if (_ids == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1713
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1714
02bb8761fcce Initial load
duke
parents:
diff changeset
  1715
        return (String[])_ids.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1716
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1717
02bb8761fcce Initial load
duke
parents:
diff changeset
  1718
    /* for debugging */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1719
02bb8761fcce Initial load
duke
parents:
diff changeset
  1720
    public void printBuffer() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1721
        CDROutputStream_1_0.printBuffer(this.bbwi);
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 static void printBuffer(ByteBufferWithInfo bbwi) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1725
02bb8761fcce Initial load
duke
parents:
diff changeset
  1726
        System.out.println("+++++++ Output Buffer ++++++++");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1727
        System.out.println();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1728
        System.out.println("Current position: " + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1729
        System.out.println("Total length : " + bbwi.buflen);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1730
        System.out.println();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1731
02bb8761fcce Initial load
duke
parents:
diff changeset
  1732
        char[] charBuf = new char[16];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1733
02bb8761fcce Initial load
duke
parents:
diff changeset
  1734
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1735
02bb8761fcce Initial load
duke
parents:
diff changeset
  1736
            for (int i = 0; i < bbwi.position(); i += 16) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1737
02bb8761fcce Initial load
duke
parents:
diff changeset
  1738
                int j = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1739
02bb8761fcce Initial load
duke
parents:
diff changeset
  1740
                // For every 16 bytes, there is one line
02bb8761fcce Initial load
duke
parents:
diff changeset
  1741
                // of output.  First, the hex output of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1742
                // the 16 bytes with each byte separated
02bb8761fcce Initial load
duke
parents:
diff changeset
  1743
                // by a space.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1744
                while (j < 16 && j + i < bbwi.position()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1745
                    int k = bbwi.byteBuffer.get(i + j);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1746
                    if (k < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1747
                        k = 256 + k;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1748
                    String hex = Integer.toHexString(k);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1749
                    if (hex.length() == 1)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1750
                        hex = "0" + hex;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1751
                    System.out.print(hex + " ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1752
                    j++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1753
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1754
02bb8761fcce Initial load
duke
parents:
diff changeset
  1755
                // Add any extra spaces to align the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1756
                // text column in case we didn't end
02bb8761fcce Initial load
duke
parents:
diff changeset
  1757
                // at 16
02bb8761fcce Initial load
duke
parents:
diff changeset
  1758
                while (j < 16) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1759
                    System.out.print("   ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1760
                    j++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1761
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1762
02bb8761fcce Initial load
duke
parents:
diff changeset
  1763
                // Now output the ASCII equivalents.  Non-ASCII
02bb8761fcce Initial load
duke
parents:
diff changeset
  1764
                // characters are shown as periods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1765
                int x = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1766
02bb8761fcce Initial load
duke
parents:
diff changeset
  1767
                while (x < 16 && x + i < bbwi.position()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1768
                    if (ORBUtility.isPrintable((char)bbwi.byteBuffer.get(i + x)))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1769
                        charBuf[x] = (char)bbwi.byteBuffer.get(i + x);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1770
                    else
02bb8761fcce Initial load
duke
parents:
diff changeset
  1771
                        charBuf[x] = '.';
02bb8761fcce Initial load
duke
parents:
diff changeset
  1772
                    x++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1773
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1774
                System.out.println(new String(charBuf, 0, x));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1775
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1776
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1777
            t.printStackTrace();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1778
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1779
        System.out.println("++++++++++++++++++++++++++++++");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1780
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1781
02bb8761fcce Initial load
duke
parents:
diff changeset
  1782
    public void writeIndirection(int tag, int posIndirectedTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1783
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1784
        // Must ensure that there are no chunks between the tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1785
        // and the actual indirection value.  This isn't talked about
02bb8761fcce Initial load
duke
parents:
diff changeset
  1786
        // in the spec, but seems to cause headaches in our code.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1787
        // At the very least, this method isolates the indirection code
02bb8761fcce Initial load
duke
parents:
diff changeset
  1788
        // that was duplicated so often.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1789
02bb8761fcce Initial load
duke
parents:
diff changeset
  1790
        handleSpecialChunkBegin(computeAlignment(4) + 8);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1791
02bb8761fcce Initial load
duke
parents:
diff changeset
  1792
        // write indirection tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1793
        write_long(tag);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1794
02bb8761fcce Initial load
duke
parents:
diff changeset
  1795
        // write indirection
02bb8761fcce Initial load
duke
parents:
diff changeset
  1796
        // Use parent.getRealIndex() so that it can be overridden by TypeCodeOutputStreams
02bb8761fcce Initial load
duke
parents:
diff changeset
  1797
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1798
        System.out.println("CDROutputStream_1_0 writing indirection pos " + posIndirectedTo +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1799
                           " - real index " + parent.getRealIndex(get_offset()) + " = " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1800
                           (posIndirectedTo - parent.getRealIndex(get_offset())));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1801
*/
02bb8761fcce Initial load
duke
parents:
diff changeset
  1802
        write_long(posIndirectedTo - parent.getRealIndex(get_offset()));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1803
02bb8761fcce Initial load
duke
parents:
diff changeset
  1804
        handleSpecialChunkEnd();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1805
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1806
02bb8761fcce Initial load
duke
parents:
diff changeset
  1807
    protected CodeSetConversion.CTBConverter getCharConverter() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1808
        if (charConverter == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1809
            charConverter = parent.createCharCTBConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1810
02bb8761fcce Initial load
duke
parents:
diff changeset
  1811
        return charConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1812
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1813
02bb8761fcce Initial load
duke
parents:
diff changeset
  1814
    protected CodeSetConversion.CTBConverter getWCharConverter() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1815
        if (wcharConverter == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1816
            wcharConverter = parent.createWCharCTBConverter();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1817
02bb8761fcce Initial load
duke
parents:
diff changeset
  1818
        return wcharConverter;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1819
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1820
02bb8761fcce Initial load
duke
parents:
diff changeset
  1821
    protected void dprint(String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1822
        if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1823
            ORBUtility.dprint(this, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1824
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1825
02bb8761fcce Initial load
duke
parents:
diff changeset
  1826
    void alignOnBoundary(int octetBoundary) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1827
        alignAndReserve(octetBoundary, 0);
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 start_value(String rep_id) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1831
02bb8761fcce Initial load
duke
parents:
diff changeset
  1832
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1833
            dprint("start_value w/ rep id "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1834
                   + rep_id
02bb8761fcce Initial load
duke
parents:
diff changeset
  1835
                   + " called at pos "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1836
                   + get_offset()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1837
                   + " position "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1838
                   + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1839
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1840
02bb8761fcce Initial load
duke
parents:
diff changeset
  1841
        if (inBlock)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1842
            end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1843
02bb8761fcce Initial load
duke
parents:
diff changeset
  1844
        // Write value_tag
02bb8761fcce Initial load
duke
parents:
diff changeset
  1845
        writeValueTag(true, true, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1846
02bb8761fcce Initial load
duke
parents:
diff changeset
  1847
        // Write rep. id
02bb8761fcce Initial load
duke
parents:
diff changeset
  1848
        write_repositoryId(rep_id);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1849
02bb8761fcce Initial load
duke
parents:
diff changeset
  1850
        // Write Value chunk
02bb8761fcce Initial load
duke
parents:
diff changeset
  1851
        end_flag--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1852
        chunkedValueNestingLevel--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1853
02bb8761fcce Initial load
duke
parents:
diff changeset
  1854
        // Make sure to chunk the custom data
02bb8761fcce Initial load
duke
parents:
diff changeset
  1855
        start_block();
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 end_value() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1859
02bb8761fcce Initial load
duke
parents:
diff changeset
  1860
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1861
            dprint("end_value called at pos "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1862
                   + get_offset()
02bb8761fcce Initial load
duke
parents:
diff changeset
  1863
                   + " position "
02bb8761fcce Initial load
duke
parents:
diff changeset
  1864
                   + bbwi.position());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1865
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1866
02bb8761fcce Initial load
duke
parents:
diff changeset
  1867
        end_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1868
02bb8761fcce Initial load
duke
parents:
diff changeset
  1869
        writeEndTag(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1870
02bb8761fcce Initial load
duke
parents:
diff changeset
  1871
        // Check to see if we need to start another block for a
02bb8761fcce Initial load
duke
parents:
diff changeset
  1872
        // possible outer value.  Since we're in the stream
02bb8761fcce Initial load
duke
parents:
diff changeset
  1873
        // format 2 custom type contained by another custom
02bb8761fcce Initial load
duke
parents:
diff changeset
  1874
        // type, mustChunk should always be true.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1875
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1876
        // Here's why we need to open a continuation chunk:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1877
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
  1878
        // We need to enclose the default data of the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1879
        // next subclass down in chunks.  There won't be
02bb8761fcce Initial load
duke
parents:
diff changeset
  1880
        // an end tag separating the superclass optional
02bb8761fcce Initial load
duke
parents:
diff changeset
  1881
        // data and the subclass's default data.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1882
02bb8761fcce Initial load
duke
parents:
diff changeset
  1883
        if (debug) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1884
            dprint("mustChunk is " + mustChunk);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1885
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1886
02bb8761fcce Initial load
duke
parents:
diff changeset
  1887
        if (mustChunk) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1888
            start_block();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1889
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1890
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1891
02bb8761fcce Initial load
duke
parents:
diff changeset
  1892
    public void close() throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1893
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1894
        // tell BufferManagerWrite to release any ByteBuffers
02bb8761fcce Initial load
duke
parents:
diff changeset
  1895
        getBufferManager().close();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1896
02bb8761fcce Initial load
duke
parents:
diff changeset
  1897
        // It's possible bbwi.byteBuffer is shared between
02bb8761fcce Initial load
duke
parents:
diff changeset
  1898
        // this OutputStream and an InputStream. Thus, we check
02bb8761fcce Initial load
duke
parents:
diff changeset
  1899
        // if the Input/Output streams are using the same ByteBuffer.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1900
        // If they sharing the same ByteBuffer we need to ensure only
02bb8761fcce Initial load
duke
parents:
diff changeset
  1901
        // one of those ByteBuffers are released to the ByteBufferPool.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1902
02bb8761fcce Initial load
duke
parents:
diff changeset
  1903
        if (getByteBufferWithInfo() != null && getByteBuffer() != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1904
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1905
            MessageMediator messageMediator = parent.getMessageMediator();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1906
            if (messageMediator != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1907
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1908
                CDRInputObject inputObj =
02bb8761fcce Initial load
duke
parents:
diff changeset
  1909
                               (CDRInputObject)messageMediator.getInputObject();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1910
                if (inputObj != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1911
                {
11044
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
  1912
                    if (inputObj.isSharing(getByteBuffer()))
4
02bb8761fcce Initial load
duke
parents:
diff changeset
  1913
                    {
11044
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
  1914
                        // Set InputStream's ByteBuffer and bbwi to null
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
  1915
                        // so its ByteBuffer cannot be released to the pool
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
  1916
                        inputObj.setByteBuffer(null);
758078ec0816 7091388: Regular unexplained npe's from corba libs after system has been running for days
coffeys
parents: 5555
diff changeset
  1917
                        inputObj.setByteBufferWithInfo(null);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
  1918
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1919
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1920
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1921
02bb8761fcce Initial load
duke
parents:
diff changeset
  1922
            // release this stream's ByteBuffer to the pool
02bb8761fcce Initial load
duke
parents:
diff changeset
  1923
            ByteBufferPool byteBufferPool = orb.getByteBufferPool();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1924
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1925
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1926
                // print address of ByteBuffer being released
02bb8761fcce Initial load
duke
parents:
diff changeset
  1927
                int bbAddress = System.identityHashCode(bbwi.byteBuffer);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1928
                StringBuffer sb = new StringBuffer(80);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1929
                sb.append(".close - releasing ByteBuffer id (");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1930
                sb.append(bbAddress).append(") to ByteBufferPool.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1931
                String msg = sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1932
                dprint(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1933
             }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1934
             byteBufferPool.releaseByteBuffer(getByteBuffer());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1935
             bbwi.byteBuffer = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1936
             bbwi = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1937
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1938
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1939
}