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