corba/src/share/classes/com/sun/corba/se/impl/copyobject/JavaInputStream.sjava
changeset 19231 6f0ebdd538a0
parent 18978 edb01c460d4c
child 19232 ddfc1727d3ef
equal deleted inserted replaced
18978:edb01c460d4c 19231:6f0ebdd538a0
     1 /*
       
     2  * Copyright (c) 2004, 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 package com.sun.corba.se.impl.encoding;
       
    26 
       
    27 import java.io.IOException;
       
    28 import java.io.Serializable;
       
    29 import java.math.BigDecimal;
       
    30 import java.nio.ByteBuffer;
       
    31 
       
    32 import org.omg.CORBA.TypeCode;
       
    33 import org.omg.CORBA.Principal;
       
    34 import org.omg.CORBA.Any;
       
    35 
       
    36 import com.sun.org.omg.SendingContext.CodeBase;
       
    37 
       
    38 import com.sun.corba.se.pept.protocol.MessageMediator;
       
    39 
       
    40 import com.sun.corba.se.spi.logging.CORBALogDomains;
       
    41 import com.sun.corba.se.spi.orb.ORB;
       
    42 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
       
    43 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
       
    44 
       
    45 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
       
    46 import com.sun.corba.se.impl.encoding.CodeSetConversion;
       
    47 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
       
    48 
       
    49 /**
       
    50  * This is delegates to the real implementation.
       
    51  *
       
    52  * NOTE:
       
    53  *
       
    54  * Before using the stream for valuetype unmarshaling, one must call
       
    55  * performORBVersionSpecificInit().
       
    56  */
       
    57 public abstract class CDRInputStream
       
    58     extends org.omg.CORBA_2_3.portable.InputStream
       
    59     implements com.sun.corba.se.impl.encoding.MarshalInputStream,
       
    60                org.omg.CORBA.DataInputStream, org.omg.CORBA.portable.ValueInputStream
       
    61 {
       
    62     protected CorbaMessageMediator messageMediator;
       
    63     private CDRInputStreamBase impl;
       
    64 
       
    65     // We can move this out somewhere later.  For now, it serves its purpose
       
    66     // to create a concrete CDR delegate based on the GIOP version.
       
    67     private static class InputStreamFactory {
       
    68         
       
    69         public static CDRInputStreamBase newInputStream(ORB orb, GIOPVersion version)
       
    70         {
       
    71             switch(version.intValue()) {
       
    72                 case GIOPVersion.VERSION_1_0:
       
    73                     return new CDRInputStream_1_0();
       
    74                 case GIOPVersion.VERSION_1_1:
       
    75                     return new CDRInputStream_1_1();
       
    76                 case GIOPVersion.VERSION_1_2:
       
    77                     return new CDRInputStream_1_2();
       
    78                 default:
       
    79 		    ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
       
    80 			CORBALogDomains.RPC_ENCODING ) ;
       
    81 		    throw wrapper.unsupportedGiopVersion( version ) ;
       
    82             }
       
    83         }
       
    84     }
       
    85 
       
    86     // Required for the case when a ClientResponseImpl is
       
    87     // created with a SystemException due to a dead server/closed
       
    88     // connection with no warning.  Note that the stream will
       
    89     // not be initialized in this case.
       
    90     // 
       
    91     // Probably also required by ServerRequestImpl.
       
    92     // 
       
    93     // REVISIT.
       
    94     public CDRInputStream() {
       
    95     }
       
    96 
       
    97     public CDRInputStream(CDRInputStream is) {
       
    98         impl = is.impl.dup();
       
    99         impl.setParent(this);
       
   100     }
       
   101 
       
   102     public CDRInputStream(org.omg.CORBA.ORB orb,
       
   103                           ByteBuffer byteBuffer,
       
   104                           int size,
       
   105                           boolean littleEndian,
       
   106                           GIOPVersion version,
       
   107                           BufferManagerRead bufMgr)
       
   108     {
       
   109         impl = InputStreamFactory.newInputStream( (ORB)orb, version);
       
   110 
       
   111         impl.init(orb, byteBuffer, size, littleEndian, bufMgr);
       
   112 
       
   113         impl.setParent(this);
       
   114     }
       
   115 
       
   116     // org.omg.CORBA.portable.InputStream
       
   117     public final boolean read_boolean() {
       
   118         return impl.read_boolean();
       
   119     }
       
   120 
       
   121     public final char read_char() {
       
   122         return impl.read_char();
       
   123     }
       
   124 
       
   125     public final char read_wchar() {
       
   126         return impl.read_wchar();
       
   127     }
       
   128 
       
   129     public final byte read_octet() {
       
   130         return impl.read_octet();
       
   131     }
       
   132 
       
   133     public final short read_short() {
       
   134         return impl.read_short();
       
   135     }
       
   136 
       
   137     public final short read_ushort() {
       
   138         return impl.read_ushort();
       
   139     }
       
   140 
       
   141     public final int read_long() {
       
   142         return impl.read_long();
       
   143     }
       
   144 
       
   145     public final int read_ulong() {
       
   146         return impl.read_ulong();
       
   147     }
       
   148 
       
   149     public final long read_longlong() {
       
   150         return impl.read_longlong();
       
   151     }
       
   152 
       
   153     public final long read_ulonglong() {
       
   154         return impl.read_ulonglong();
       
   155     }
       
   156 
       
   157     public final float read_float() {
       
   158         return impl.read_float();
       
   159     }
       
   160 
       
   161     public final double read_double() {
       
   162         return impl.read_double();
       
   163     }
       
   164 
       
   165     public final String read_string() {
       
   166         return impl.read_string();
       
   167     }
       
   168 
       
   169     public final String read_wstring() {
       
   170         return impl.read_wstring();
       
   171     }
       
   172 
       
   173     public final void read_boolean_array(boolean[] value, int offset, int length) {
       
   174         impl.read_boolean_array(value, offset, length);
       
   175     }
       
   176 
       
   177     public final void read_char_array(char[] value, int offset, int length) {
       
   178         impl.read_char_array(value, offset, length);
       
   179     }
       
   180 
       
   181     public final void read_wchar_array(char[] value, int offset, int length) {
       
   182         impl.read_wchar_array(value, offset, length);
       
   183     }
       
   184 
       
   185     public final void read_octet_array(byte[] value, int offset, int length) {
       
   186         impl.read_octet_array(value, offset, length);
       
   187     }
       
   188 
       
   189     public final void read_short_array(short[] value, int offset, int length) {
       
   190         impl.read_short_array(value, offset, length);
       
   191     }
       
   192 
       
   193     public final void read_ushort_array(short[] value, int offset, int length) {
       
   194         impl.read_ushort_array(value, offset, length);
       
   195     }
       
   196 
       
   197     public final void read_long_array(int[] value, int offset, int length) {
       
   198         impl.read_long_array(value, offset, length);
       
   199     }
       
   200 
       
   201     public final void read_ulong_array(int[] value, int offset, int length) {
       
   202         impl.read_ulong_array(value, offset, length);
       
   203     }
       
   204 
       
   205     public final void read_longlong_array(long[] value, int offset, int length) {
       
   206         impl.read_longlong_array(value, offset, length);
       
   207     }
       
   208 
       
   209     public final void read_ulonglong_array(long[] value, int offset, int length) {
       
   210         impl.read_ulonglong_array(value, offset, length);
       
   211     }
       
   212 
       
   213     public final void read_float_array(float[] value, int offset, int length) {
       
   214         impl.read_float_array(value, offset, length);
       
   215     }
       
   216 
       
   217     public final void read_double_array(double[] value, int offset, int length) {
       
   218         impl.read_double_array(value, offset, length);
       
   219     }
       
   220 
       
   221     public final org.omg.CORBA.Object read_Object() {
       
   222         return impl.read_Object();
       
   223     }
       
   224 
       
   225     public final TypeCode read_TypeCode() {
       
   226         return impl.read_TypeCode();
       
   227     }
       
   228     public final Any read_any() {
       
   229         return impl.read_any();
       
   230     }
       
   231 
       
   232     public final Principal read_Principal() {
       
   233         return impl.read_Principal();
       
   234     }
       
   235 
       
   236     public final int read() throws java.io.IOException {
       
   237         return impl.read();
       
   238     }
       
   239 
       
   240     public final java.math.BigDecimal read_fixed() {
       
   241         return impl.read_fixed();
       
   242     }
       
   243 
       
   244     public final org.omg.CORBA.Context read_Context() {
       
   245         return impl.read_Context();
       
   246     }
       
   247 
       
   248     public final org.omg.CORBA.Object read_Object(java.lang.Class clz) {
       
   249         return impl.read_Object(clz);
       
   250     }
       
   251 
       
   252     public final org.omg.CORBA.ORB orb() {
       
   253         return impl.orb();
       
   254     }
       
   255 
       
   256     // org.omg.CORBA_2_3.portable.InputStream
       
   257     public final java.io.Serializable read_value() {
       
   258         return impl.read_value();
       
   259     }
       
   260 
       
   261     public final java.io.Serializable read_value(java.lang.Class clz) {
       
   262         return impl.read_value(clz);
       
   263     }
       
   264 
       
   265     public final java.io.Serializable read_value(org.omg.CORBA.portable.BoxedValueHelper factory) {
       
   266         return impl.read_value(factory);
       
   267     }
       
   268 
       
   269     public final java.io.Serializable read_value(java.lang.String rep_id) {
       
   270         return impl.read_value(rep_id);
       
   271     }
       
   272 
       
   273     public final java.io.Serializable read_value(java.io.Serializable value) {
       
   274         return impl.read_value(value);
       
   275     }
       
   276 
       
   277     public final java.lang.Object read_abstract_interface() {
       
   278         return impl.read_abstract_interface();
       
   279     }
       
   280 
       
   281     public final java.lang.Object read_abstract_interface(java.lang.Class clz) {
       
   282         return impl.read_abstract_interface(clz);
       
   283     }
       
   284     // com.sun.corba.se.impl.encoding.MarshalInputStream
       
   285 
       
   286     public final void consumeEndian() {
       
   287         impl.consumeEndian();
       
   288     }
       
   289 
       
   290     public final int getPosition() {
       
   291         return impl.getPosition();
       
   292     }
       
   293 
       
   294     // org.omg.CORBA.DataInputStream
       
   295 
       
   296     public final java.lang.Object read_Abstract () {
       
   297         return impl.read_Abstract();
       
   298     }
       
   299 
       
   300     public final java.io.Serializable read_Value () {
       
   301         return impl.read_Value();
       
   302     }
       
   303 
       
   304     public final void read_any_array (org.omg.CORBA.AnySeqHolder seq, int offset, int length) {
       
   305         impl.read_any_array(seq, offset, length);
       
   306     }
       
   307 
       
   308     public final void read_boolean_array (org.omg.CORBA.BooleanSeqHolder seq, int offset, int length) {
       
   309         impl.read_boolean_array(seq, offset, length);
       
   310     }
       
   311 
       
   312     public final void read_char_array (org.omg.CORBA.CharSeqHolder seq, int offset, int length) {
       
   313         impl.read_char_array(seq, offset, length);
       
   314     }
       
   315 
       
   316     public final void read_wchar_array (org.omg.CORBA.WCharSeqHolder seq, int offset, int length) {
       
   317         impl.read_wchar_array(seq, offset, length);
       
   318     }
       
   319 
       
   320     public final void read_octet_array (org.omg.CORBA.OctetSeqHolder seq, int offset, int length) {
       
   321         impl.read_octet_array(seq, offset, length);
       
   322     }
       
   323 
       
   324     public final void read_short_array (org.omg.CORBA.ShortSeqHolder seq, int offset, int length) {
       
   325         impl.read_short_array(seq, offset, length);
       
   326     }
       
   327 
       
   328     public final void read_ushort_array (org.omg.CORBA.UShortSeqHolder seq, int offset, int length) {
       
   329         impl.read_ushort_array(seq, offset, length);
       
   330     }
       
   331 
       
   332     public final void read_long_array (org.omg.CORBA.LongSeqHolder seq, int offset, int length) {
       
   333         impl.read_long_array(seq, offset, length);
       
   334     }
       
   335 
       
   336     public final void read_ulong_array (org.omg.CORBA.ULongSeqHolder seq, int offset, int length) {
       
   337         impl.read_ulong_array(seq, offset, length);
       
   338     }
       
   339 
       
   340     public final void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder seq, int offset, int length) {
       
   341         impl.read_ulonglong_array(seq, offset, length);
       
   342     }
       
   343 
       
   344     public final void read_longlong_array (org.omg.CORBA.LongLongSeqHolder seq, int offset, int length) {
       
   345         impl.read_longlong_array(seq, offset, length);
       
   346     }
       
   347 
       
   348     public final void read_float_array (org.omg.CORBA.FloatSeqHolder seq, int offset, int length) {
       
   349         impl.read_float_array(seq, offset, length);
       
   350     }
       
   351 
       
   352     public final void read_double_array (org.omg.CORBA.DoubleSeqHolder seq, int offset, int length) {
       
   353         impl.read_double_array(seq, offset, length);
       
   354     }
       
   355 
       
   356     // org.omg.CORBA.portable.ValueBase
       
   357     public final String[] _truncatable_ids() {
       
   358         return impl._truncatable_ids();
       
   359     }
       
   360 
       
   361     // java.io.InputStream
       
   362     public final int read(byte b[]) throws IOException {
       
   363         return impl.read(b);
       
   364     }
       
   365 
       
   366     public final int read(byte b[], int off, int len) throws IOException {
       
   367         return impl.read(b, off, len);
       
   368     }
       
   369 
       
   370     public final long skip(long n) throws IOException {
       
   371         return impl.skip(n);
       
   372     }
       
   373 
       
   374     public final int available() throws IOException {
       
   375         return impl.available();
       
   376     }
       
   377 
       
   378     public final void close() throws IOException {
       
   379         impl.close();
       
   380     }
       
   381 
       
   382     public final void mark(int readlimit) {
       
   383         impl.mark(readlimit);
       
   384     }
       
   385 
       
   386     public final void reset() {
       
   387         impl.reset();
       
   388     }
       
   389 
       
   390     public final boolean markSupported() {
       
   391         return impl.markSupported();
       
   392     }
       
   393 
       
   394     public abstract CDRInputStream dup();
       
   395 
       
   396     // Needed by TCUtility
       
   397     public final java.math.BigDecimal read_fixed(short digits, short scale) {
       
   398         return impl.read_fixed(digits, scale);
       
   399     }
       
   400 
       
   401     public final boolean isLittleEndian() {
       
   402         return impl.isLittleEndian();
       
   403     }
       
   404 
       
   405     protected final ByteBuffer getByteBuffer() {
       
   406         return impl.getByteBuffer();
       
   407     }
       
   408 
       
   409     protected final void setByteBuffer(ByteBuffer byteBuffer) {
       
   410         impl.setByteBuffer(byteBuffer);
       
   411     }
       
   412 
       
   413     protected final void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
       
   414         impl.setByteBufferWithInfo(bbwi);
       
   415     }
       
   416 
       
   417     public final int getBufferLength() {
       
   418         return impl.getBufferLength();
       
   419     }
       
   420 
       
   421     protected final void setBufferLength(int value) {
       
   422         impl.setBufferLength(value);
       
   423     }
       
   424 
       
   425     protected final int getIndex() {
       
   426         return impl.getIndex();
       
   427     }
       
   428 
       
   429     protected final void setIndex(int value) {
       
   430         impl.setIndex(value);
       
   431     }
       
   432 
       
   433     public final void orb(org.omg.CORBA.ORB orb) {
       
   434         impl.orb(orb);
       
   435     }
       
   436 
       
   437     public final GIOPVersion getGIOPVersion() {
       
   438         return impl.getGIOPVersion();
       
   439     }
       
   440 
       
   441     public final BufferManagerRead getBufferManager() {
       
   442         return impl.getBufferManager();
       
   443     }
       
   444 
       
   445     // This should be overridden by any stream (ex: IIOPInputStream)
       
   446     // which wants to read values.  Thus, TypeCodeInputStream doesn't
       
   447     // have to do this.
       
   448     public CodeBase getCodeBase() {
       
   449         return null;
       
   450     }
       
   451 
       
   452     // Use Latin-1 for GIOP 1.0 or when code set negotiation was not
       
   453     // performed.
       
   454     protected CodeSetConversion.BTCConverter createCharBTCConverter() {
       
   455         return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1,
       
   456                                                         impl.isLittleEndian());
       
   457     }
       
   458 
       
   459     // Subclasses must decide what to do here.  It's inconvenient to
       
   460     // make the class and this method abstract because of dup().
       
   461     protected abstract CodeSetConversion.BTCConverter createWCharBTCConverter();
       
   462 
       
   463     // Prints the current buffer in a human readable form
       
   464     void printBuffer() {
       
   465         impl.printBuffer();
       
   466     }
       
   467 
       
   468     /**
       
   469      * Aligns the current position on the given octet boundary
       
   470      * if there are enough bytes available to do so.  Otherwise,
       
   471      * it just returns.  This is used for some (but not all)
       
   472      * GIOP 1.2 message headers.
       
   473      */
       
   474     public void alignOnBoundary(int octetBoundary) {
       
   475         impl.alignOnBoundary(octetBoundary);
       
   476     }
       
   477 
       
   478     // Needed by request and reply messages for GIOP versions >= 1.2 only.
       
   479     public void setHeaderPadding(boolean headerPadding) {
       
   480         impl.setHeaderPadding(headerPadding);
       
   481     }
       
   482     
       
   483     /**
       
   484      * This must be called after determining the proper ORB version,
       
   485      * and setting it on the stream's ORB instance.  It can be called
       
   486      * after reading the service contexts, since that is the only place
       
   487      * we can get the ORB version info.
       
   488      *
       
   489      * Trying to unmarshal things requiring repository IDs before calling
       
   490      * this will result in NullPtrExceptions.
       
   491      */
       
   492     public void performORBVersionSpecificInit() {
       
   493         // In the case of SystemExceptions, a stream is created
       
   494         // with its default constructor (and thus no impl is set).
       
   495         if (impl != null)
       
   496             impl.performORBVersionSpecificInit();
       
   497     }
       
   498 
       
   499     /**
       
   500      * Resets any internal references to code set converters.
       
   501      * This is useful for forcing the CDR stream to reacquire
       
   502      * converters (probably from its subclasses) when state
       
   503      * has changed.
       
   504      */
       
   505     public void resetCodeSetConverters() {
       
   506         impl.resetCodeSetConverters();
       
   507     }
       
   508 
       
   509     public void setMessageMediator(MessageMediator messageMediator)
       
   510     {
       
   511         this.messageMediator = (CorbaMessageMediator) messageMediator;
       
   512     }
       
   513 
       
   514     public MessageMediator getMessageMediator()
       
   515     {
       
   516         return messageMediator;
       
   517     }
       
   518 
       
   519     // ValueInputStream -----------------------------
       
   520 
       
   521     public void start_value() {
       
   522         impl.start_value();
       
   523     }
       
   524 
       
   525     public void end_value() {
       
   526         impl.end_value();
       
   527     }
       
   528 }