src/java.corba/share/classes/com/sun/corba/se/impl/io/OutputStreamHook.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /*
  26  * Licensed Materials - Property of IBM
  27  * RMI-IIOP v1.0
  28  * Copyright IBM Corp. 1998 1999  All Rights Reserved
  29  *
  30  */
  31 
  32 package com.sun.corba.se.impl.io;
  33 
  34 import java.io.IOException;

  35 import java.io.OutputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.ObjectOutput;
  38 import java.util.Map;
  39 import java.util.HashMap;
  40 
  41 import org.omg.CORBA.INTERNAL;
  42 
  43 public abstract class OutputStreamHook extends ObjectOutputStream
  44 {
  45     private HookPutFields putFields = null;
  46 
  47     /**
  48      * Since ObjectOutputStream.PutField methods specify no exceptions,
  49      * we are not checking for null parameters on put methods.
  50      */
  51     private class HookPutFields extends ObjectOutputStream.PutField
  52     {
  53         private Map<String,Object> fields = new HashMap<>();
  54 


 137     }
 138 
 139     abstract void writeField(ObjectStreamField field, Object value) throws IOException;
 140 
 141     public OutputStreamHook()
 142         throws java.io.IOException {
 143         super();
 144     }
 145 
 146     public void defaultWriteObject() throws IOException {
 147 
 148         writeObjectState.defaultWriteObject(this);
 149 
 150         defaultWriteObjectDelegate();
 151     }
 152 
 153     public abstract void defaultWriteObjectDelegate();
 154 
 155     public ObjectOutputStream.PutField putFields()
 156         throws IOException {

 157         putFields = new HookPutFields();

 158         return putFields;
 159     }
 160 
 161     // Stream format version, saved/restored during recursive calls
 162     protected byte streamFormatVersion = 1;
 163 
 164     // Return the stream format version currently being used
 165     // to serialize an object
 166     public byte getStreamFormatVersion() {
 167         return streamFormatVersion;
 168     }
 169 
 170     abstract ObjectStreamField[] getFieldsNoCopy();
 171 
 172     // User uses PutFields to simulate default data.
 173     // See java.io.ObjectOutputStream.PutFields
 174     public void writeFields()
 175         throws IOException {
 176 
 177         writeObjectState.defaultWriteObject(this);
 178 
 179         putFields.write(this);


 180     }

 181 
 182     abstract org.omg.CORBA_2_3.portable.OutputStream getOrbStream();
 183 
 184     protected abstract void beginOptionalCustomData();
 185 
 186 
 187     // The following is a State pattern implementation of what
 188     // should be done when a Serializable has a
 189     // writeObject method.  This was especially necessary for
 190     // RMI-IIOP stream format version 2.  Please see the
 191     // state diagrams in the docs directory of the workspace.
 192 
 193     protected WriteObjectState writeObjectState = NOT_IN_WRITE_OBJECT;
 194 
 195     protected void setState(WriteObjectState newState) {
 196         writeObjectState = newState;
 197     }
 198 
 199     // Description of possible actions
 200     protected static class WriteObjectState {


   1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 /*
  26  * Licensed Materials - Property of IBM
  27  * RMI-IIOP v1.0
  28  * Copyright IBM Corp. 1998 1999  All Rights Reserved
  29  *
  30  */
  31 
  32 package com.sun.corba.se.impl.io;
  33 
  34 import java.io.IOException;
  35 import java.io.NotActiveException;
  36 import java.io.OutputStream;
  37 import java.io.ObjectOutputStream;
  38 import java.io.ObjectOutput;
  39 import java.util.Map;
  40 import java.util.HashMap;
  41 
  42 import org.omg.CORBA.INTERNAL;
  43 
  44 public abstract class OutputStreamHook extends ObjectOutputStream
  45 {
  46     private HookPutFields putFields = null;
  47 
  48     /**
  49      * Since ObjectOutputStream.PutField methods specify no exceptions,
  50      * we are not checking for null parameters on put methods.
  51      */
  52     private class HookPutFields extends ObjectOutputStream.PutField
  53     {
  54         private Map<String,Object> fields = new HashMap<>();
  55 


 138     }
 139 
 140     abstract void writeField(ObjectStreamField field, Object value) throws IOException;
 141 
 142     public OutputStreamHook()
 143         throws java.io.IOException {
 144         super();
 145     }
 146 
 147     public void defaultWriteObject() throws IOException {
 148 
 149         writeObjectState.defaultWriteObject(this);
 150 
 151         defaultWriteObjectDelegate();
 152     }
 153 
 154     public abstract void defaultWriteObjectDelegate();
 155 
 156     public ObjectOutputStream.PutField putFields()
 157         throws IOException {
 158         if (putFields == null) {
 159             putFields = new HookPutFields();
 160         }
 161         return putFields;
 162     }
 163 
 164     // Stream format version, saved/restored during recursive calls
 165     protected byte streamFormatVersion = 1;
 166 
 167     // Return the stream format version currently being used
 168     // to serialize an object
 169     public byte getStreamFormatVersion() {
 170         return streamFormatVersion;
 171     }
 172 
 173     abstract ObjectStreamField[] getFieldsNoCopy();
 174 
 175     // User uses PutFields to simulate default data.
 176     // See java.io.ObjectOutputStream.PutFields
 177     public void writeFields()
 178         throws IOException {
 179 
 180         writeObjectState.defaultWriteObject(this);
 181         if (putFields != null) {
 182             putFields.write(this);
 183         } else {
 184             throw new NotActiveException("no current PutField object");
 185         }
 186     }
 187 
 188     abstract org.omg.CORBA_2_3.portable.OutputStream getOrbStream();
 189 
 190     protected abstract void beginOptionalCustomData();
 191 
 192 
 193     // The following is a State pattern implementation of what
 194     // should be done when a Serializable has a
 195     // writeObject method.  This was especially necessary for
 196     // RMI-IIOP stream format version 2.  Please see the
 197     // state diagrams in the docs directory of the workspace.
 198 
 199     protected WriteObjectState writeObjectState = NOT_IN_WRITE_OBJECT;
 200 
 201     protected void setState(WriteObjectState newState) {
 202         writeObjectState = newState;
 203     }
 204 
 205     // Description of possible actions
 206     protected static class WriteObjectState {