corba/src/share/classes/com/sun/corba/se/impl/io/OutputStreamHook.java
author coffeys
Tue, 01 Jul 2014 15:17:55 +0100
changeset 25229 1d2051494df4
parent 22131 4d7b21463768
permissions -rw-r--r--
7095856: OutputStreamHook doesn't handle null values Reviewed-by: lancea, msheppar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
25229
1d2051494df4 7095856: OutputStreamHook doesn't handle null values
coffeys
parents: 22131
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package com.sun.corba.se.impl.io;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.io.ObjectOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectOutput;
25229
1d2051494df4 7095856: OutputStreamHook doesn't handle null values
coffeys
parents: 22131
diff changeset
    38
import java.util.Map;
1d2051494df4 7095856: OutputStreamHook doesn't handle null values
coffeys
parents: 22131
diff changeset
    39
import java.util.HashMap;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
public abstract class OutputStreamHook extends ObjectOutputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
    private HookPutFields putFields = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
     * Since ObjectOutputStream.PutField methods specify no exceptions,
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
     * we are not checking for null parameters on put methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    private class HookPutFields extends ObjectOutputStream.PutField
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    {
25229
1d2051494df4 7095856: OutputStreamHook doesn't handle null values
coffeys
parents: 22131
diff changeset
    53
        private Map<String,Object> fields = new HashMap<>();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
         * Put the value of the named boolean field into the persistent field.
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
        public void put(String name, boolean value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
            fields.put(name, new Boolean(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
         * Put the value of the named char field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        public void put(String name, char value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
            fields.put(name, new Character(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
         * Put the value of the named byte field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        public void put(String name, byte value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
            fields.put(name, new Byte(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
         * Put the value of the named short field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        public void put(String name, short value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
            fields.put(name, new Short(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
         * Put the value of the named int field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        public void put(String name, int value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
            fields.put(name, new Integer(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
         * Put the value of the named long field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        public void put(String name, long value){
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
            fields.put(name, new Long(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
         * Put the value of the named float field into the persistent fields.
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        public void put(String name, float value){
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            fields.put(name, new Float(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
         * Put the value of the named double field into the persistent field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        public void put(String name, double value){
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
            fields.put(name, new Double(value));
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
         * Put the value of the named Object field into the persistent field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        public void put(String name, Object value){
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            fields.put(name, value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
         * Write the data and fields to the specified ObjectOutput stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        public void write(ObjectOutput out) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            OutputStreamHook hook = (OutputStreamHook)out;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
            ObjectStreamField[] osfields = hook.getFieldsNoCopy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
            // Write the fields to the stream in the order
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            // provided by the ObjectStreamClass.  (They should
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            // be sorted appropriately already.)
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            for (int i = 0; i < osfields.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
                Object value = fields.get(osfields[i].getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                hook.writeField(osfields[i], value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    abstract void writeField(ObjectStreamField field, Object value) throws IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    public OutputStreamHook()
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        throws java.io.IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        super();
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    public void defaultWriteObject() throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        writeObjectState.defaultWriteObject(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        defaultWriteObjectDelegate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    public abstract void defaultWriteObjectDelegate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    public ObjectOutputStream.PutField putFields()
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        putFields = new HookPutFields();
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        return putFields;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    // Stream format version, saved/restored during recursive calls
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    protected byte streamFormatVersion = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    // Return the stream format version currently being used
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    // to serialize an object
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    public byte getStreamFormatVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        return streamFormatVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    abstract ObjectStreamField[] getFieldsNoCopy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    // User uses PutFields to simulate default data.
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    // See java.io.ObjectOutputStream.PutFields
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    public void writeFields()
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        writeObjectState.defaultWriteObject(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        putFields.write(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
18307
8bf60b58675b 8000642: Better handling of objects for transportation
coffeys
parents: 5555
diff changeset
   182
    abstract org.omg.CORBA_2_3.portable.OutputStream getOrbStream();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    protected abstract void beginOptionalCustomData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    // The following is a State pattern implementation of what
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    // should be done when a Serializable has a
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    // writeObject method.  This was especially necessary for
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    // RMI-IIOP stream format version 2.  Please see the
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    // state diagrams in the docs directory of the workspace.
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    protected WriteObjectState writeObjectState = NOT_IN_WRITE_OBJECT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    protected void setState(WriteObjectState newState) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        writeObjectState = newState;
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    // Description of possible actions
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    protected static class WriteObjectState {
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        public void enterWriteObject(OutputStreamHook stream) throws IOException {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        public void exitWriteObject(OutputStreamHook stream) throws IOException {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        public void defaultWriteObject(OutputStreamHook stream) throws IOException {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
        public void writeData(OutputStreamHook stream) throws IOException {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    protected static class DefaultState extends WriteObjectState {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        public void enterWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
            stream.setState(IN_WRITE_OBJECT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    protected static final WriteObjectState NOT_IN_WRITE_OBJECT = new DefaultState();
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    protected static final WriteObjectState IN_WRITE_OBJECT = new InWriteObjectState();
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    protected static final WriteObjectState WROTE_DEFAULT_DATA = new WroteDefaultDataState();
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    protected static final WriteObjectState WROTE_CUSTOM_DATA = new WroteCustomDataState();
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    protected static class InWriteObjectState extends WriteObjectState {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        public void enterWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
            // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            throw new IOException("Internal state failure: Entered writeObject twice");
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        public void exitWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
            // We didn't write any data, so write the
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
            // called defaultWriteObject indicator as false
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
            stream.getOrbStream().write_boolean(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
            // If we're in stream format verison 2, we must
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            // put the "null" marker to say that there isn't
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
            // any optional data
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
            if (stream.getStreamFormatVersion() == 2)
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
                stream.getOrbStream().write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            stream.setState(NOT_IN_WRITE_OBJECT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        public void defaultWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            // The writeObject method called defaultWriteObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            // or writeFields, so put the called defaultWriteObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            // indicator as true
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            stream.getOrbStream().write_boolean(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            stream.setState(WROTE_DEFAULT_DATA);
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        public void writeData(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            // The writeObject method first called a direct
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
            // write operation.  Write the called defaultWriteObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
            // indicator as false, put the special stream format
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
            // version 2 header (if stream format version 2, of course),
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
            // and write the data
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
            stream.getOrbStream().write_boolean(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
            stream.beginOptionalCustomData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            stream.setState(WROTE_CUSTOM_DATA);
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
    protected static class WroteDefaultDataState extends InWriteObjectState {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        public void exitWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
            // We only wrote default data, so if in stream format
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            // version 2, put the null indicator to say that there
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            // is no optional data
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            if (stream.getStreamFormatVersion() == 2)
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
                stream.getOrbStream().write_long(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            stream.setState(NOT_IN_WRITE_OBJECT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
        public void defaultWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
            // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
            throw new IOException("Called defaultWriteObject/writeFields twice");
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        public void writeData(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            // The writeObject method called a direct write operation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
            // If in stream format version 2, put the fake valuetype
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            // header.
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
            stream.beginOptionalCustomData();
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
            stream.setState(WROTE_CUSTOM_DATA);
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    protected static class WroteCustomDataState extends InWriteObjectState {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        public void exitWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
            // In stream format version 2, we must tell the ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
            // stream to close the fake custom valuetype.
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            if (stream.getStreamFormatVersion() == 2)
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                ((org.omg.CORBA.portable.ValueOutputStream)stream.getOrbStream()).end_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            stream.setState(NOT_IN_WRITE_OBJECT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
        public void defaultWriteObject(OutputStreamHook stream) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
            // XXX I18N, logging needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
            throw new IOException("Cannot call defaultWriteObject/writeFields after writing custom data in RMI-IIOP");
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        // We don't have to do anything special here, just let
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        // the stream write the data.
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        public void writeData(OutputStreamHook stream) throws IOException {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
}