KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > CDRInputStream


1 /*
2  * @(#)CDRInputStream.java 1.34 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.encoding;
8
9 import java.io.IOException JavaDoc;
10 import java.io.Serializable JavaDoc;
11 import java.math.BigDecimal JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
13
14 import org.omg.CORBA.TypeCode JavaDoc;
15 import org.omg.CORBA.Principal JavaDoc;
16 import org.omg.CORBA.Any JavaDoc;
17
18 import com.sun.org.omg.SendingContext.CodeBase;
19
20 import com.sun.corba.se.pept.protocol.MessageMediator;
21
22 import com.sun.corba.se.spi.logging.CORBALogDomains;
23 import com.sun.corba.se.spi.orb.ORB;
24 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
25 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
26
27 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
28 import com.sun.corba.se.impl.encoding.CodeSetConversion;
29 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
30 import com.sun.corba.se.impl.orbutil.ORBUtility;
31 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
32
33 /**
34  * This is delegates to the real implementation.
35  *
36  * NOTE:
37  *
38  * Before using the stream for valuetype unmarshaling, one must call
39  * performORBVersionSpecificInit().
40  */

41 public abstract class CDRInputStream
42     extends org.omg.CORBA_2_3.portable.InputStream JavaDoc
43     implements com.sun.corba.se.impl.encoding.MarshalInputStream,
44                org.omg.CORBA.DataInputStream JavaDoc, org.omg.CORBA.portable.ValueInputStream JavaDoc
45 {
46     protected CorbaMessageMediator messageMediator;
47     private CDRInputStreamBase impl;
48
49     // We can move this out somewhere later. For now, it serves its purpose
50
// to create a concrete CDR delegate based on the GIOP version.
51
private static class InputStreamFactory {
52         
53         public static CDRInputStreamBase newInputStream(
54             ORB orb, GIOPVersion version, byte encodingVersion) {
55             switch(version.intValue()) {
56                 case GIOPVersion.VERSION_1_0:
57                     return new CDRInputStream_1_0();
58                 case GIOPVersion.VERSION_1_1:
59                     return new CDRInputStream_1_1();
60                 case GIOPVersion.VERSION_1_2:
61             if (encodingVersion != Message.CDR_ENC_VERSION) {
62             return
63               new IDLJavaSerializationInputStream(encodingVersion);
64             }
65                     return new CDRInputStream_1_2();
66             // else fall through and report exception.
67
default:
68             ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
69             CORBALogDomains.RPC_ENCODING ) ;
70             throw wrapper.unsupportedGiopVersion( version ) ;
71             }
72         }
73     }
74
75     // Required for the case when a ClientResponseImpl is
76
// created with a SystemException due to a dead server/closed
77
// connection with no warning. Note that the stream will
78
// not be initialized in this case.
79
//
80
// Probably also required by ServerRequestImpl.
81
//
82
// REVISIT.
83
public CDRInputStream() {
84     }
85
86     public CDRInputStream(CDRInputStream is) {
87         impl = is.impl.dup();
88         impl.setParent(this);
89     }
90
91     public CDRInputStream(org.omg.CORBA.ORB JavaDoc orb,
92                           ByteBuffer JavaDoc byteBuffer,
93                           int size,
94                           boolean littleEndian,
95                           GIOPVersion version,
96               byte encodingVersion,
97                           BufferManagerRead bufMgr)
98     {
99         impl = InputStreamFactory.newInputStream((ORB)orb, version,
100                          encodingVersion);
101
102         impl.init(orb, byteBuffer, size, littleEndian, bufMgr);
103
104         impl.setParent(this);
105     }
106
107     // org.omg.CORBA.portable.InputStream
108
public final boolean read_boolean() {
109         return impl.read_boolean();
110     }
111
112     public final char read_char() {
113         return impl.read_char();
114     }
115
116     public final char read_wchar() {
117         return impl.read_wchar();
118     }
119
120     public final byte read_octet() {
121         return impl.read_octet();
122     }
123
124     public final short read_short() {
125         return impl.read_short();
126     }
127
128     public final short read_ushort() {
129         return impl.read_ushort();
130     }
131
132     public final int read_long() {
133         return impl.read_long();
134     }
135
136     public final int read_ulong() {
137         return impl.read_ulong();
138     }
139
140     public final long read_longlong() {
141         return impl.read_longlong();
142     }
143
144     public final long read_ulonglong() {
145         return impl.read_ulonglong();
146     }
147
148     public final float read_float() {
149         return impl.read_float();
150     }
151
152     public final double read_double() {
153         return impl.read_double();
154     }
155
156     public final String JavaDoc read_string() {
157         return impl.read_string();
158     }
159
160     public final String JavaDoc read_wstring() {
161         return impl.read_wstring();
162     }
163
164     public final void read_boolean_array(boolean[] value, int offset, int length) {
165         impl.read_boolean_array(value, offset, length);
166     }
167
168     public final void read_char_array(char[] value, int offset, int length) {
169         impl.read_char_array(value, offset, length);
170     }
171
172     public final void read_wchar_array(char[] value, int offset, int length) {
173         impl.read_wchar_array(value, offset, length);
174     }
175
176     public final void read_octet_array(byte[] value, int offset, int length) {
177         impl.read_octet_array(value, offset, length);
178     }
179
180     public final void read_short_array(short[] value, int offset, int length) {
181         impl.read_short_array(value, offset, length);
182     }
183
184     public final void read_ushort_array(short[] value, int offset, int length) {
185         impl.read_ushort_array(value, offset, length);
186     }
187
188     public final void read_long_array(int[] value, int offset, int length) {
189         impl.read_long_array(value, offset, length);
190     }
191
192     public final void read_ulong_array(int[] value, int offset, int length) {
193         impl.read_ulong_array(value, offset, length);
194     }
195
196     public final void read_longlong_array(long[] value, int offset, int length) {
197         impl.read_longlong_array(value, offset, length);
198     }
199
200     public final void read_ulonglong_array(long[] value, int offset, int length) {
201         impl.read_ulonglong_array(value, offset, length);
202     }
203
204     public final void read_float_array(float[] value, int offset, int length) {
205         impl.read_float_array(value, offset, length);
206     }
207
208     public final void read_double_array(double[] value, int offset, int length) {
209         impl.read_double_array(value, offset, length);
210     }
211
212     public final org.omg.CORBA.Object JavaDoc read_Object() {
213         return impl.read_Object();
214     }
215
216     public final TypeCode JavaDoc read_TypeCode() {
217         return impl.read_TypeCode();
218     }
219     public final Any JavaDoc read_any() {
220         return impl.read_any();
221     }
222
223     public final Principal JavaDoc read_Principal() {
224         return impl.read_Principal();
225     }
226
227     public final int read() throws java.io.IOException JavaDoc {
228         return impl.read();
229     }
230
231     public final java.math.BigDecimal JavaDoc read_fixed() {
232         return impl.read_fixed();
233     }
234
235     public final org.omg.CORBA.Context JavaDoc read_Context() {
236         return impl.read_Context();
237     }
238
239     public final org.omg.CORBA.Object JavaDoc read_Object(java.lang.Class JavaDoc clz) {
240         return impl.read_Object(clz);
241     }
242
243     public final org.omg.CORBA.ORB JavaDoc orb() {
244         return impl.orb();
245     }
246
247     // org.omg.CORBA_2_3.portable.InputStream
248
public final java.io.Serializable JavaDoc read_value() {
249         return impl.read_value();
250     }
251
252     public final java.io.Serializable JavaDoc read_value(java.lang.Class JavaDoc clz) {
253         return impl.read_value(clz);
254     }
255
256     public final java.io.Serializable JavaDoc read_value(org.omg.CORBA.portable.BoxedValueHelper JavaDoc factory) {
257         return impl.read_value(factory);
258     }
259
260     public final java.io.Serializable JavaDoc read_value(java.lang.String JavaDoc rep_id) {
261         return impl.read_value(rep_id);
262     }
263
264     public final java.io.Serializable JavaDoc read_value(java.io.Serializable JavaDoc value) {
265         return impl.read_value(value);
266     }
267
268     public final java.lang.Object JavaDoc read_abstract_interface() {
269         return impl.read_abstract_interface();
270     }
271
272     public final java.lang.Object JavaDoc read_abstract_interface(java.lang.Class JavaDoc clz) {
273         return impl.read_abstract_interface(clz);
274     }
275     // com.sun.corba.se.impl.encoding.MarshalInputStream
276

277     public final void consumeEndian() {
278         impl.consumeEndian();
279     }
280
281     public final int getPosition() {
282         return impl.getPosition();
283     }
284
285     // org.omg.CORBA.DataInputStream
286

287     public final java.lang.Object JavaDoc read_Abstract () {
288         return impl.read_Abstract();
289     }
290
291     public final java.io.Serializable JavaDoc read_Value () {
292         return impl.read_Value();
293     }
294
295     public final void read_any_array (org.omg.CORBA.AnySeqHolder JavaDoc seq, int offset, int length) {
296         impl.read_any_array(seq, offset, length);
297     }
298
299     public final void read_boolean_array (org.omg.CORBA.BooleanSeqHolder JavaDoc seq, int offset, int length) {
300         impl.read_boolean_array(seq, offset, length);
301     }
302
303     public final void read_char_array (org.omg.CORBA.CharSeqHolder JavaDoc seq, int offset, int length) {
304         impl.read_char_array(seq, offset, length);
305     }
306
307     public final void read_wchar_array (org.omg.CORBA.WCharSeqHolder JavaDoc seq, int offset, int length) {
308         impl.read_wchar_array(seq, offset, length);
309     }
310
311     public final void read_octet_array (org.omg.CORBA.OctetSeqHolder JavaDoc seq, int offset, int length) {
312         impl.read_octet_array(seq, offset, length);
313     }
314
315     public final void read_short_array (org.omg.CORBA.ShortSeqHolder JavaDoc seq, int offset, int length) {
316         impl.read_short_array(seq, offset, length);
317     }
318
319     public final void read_ushort_array (org.omg.CORBA.UShortSeqHolder JavaDoc seq, int offset, int length) {
320         impl.read_ushort_array(seq, offset, length);
321     }
322
323     public final void read_long_array (org.omg.CORBA.LongSeqHolder JavaDoc seq, int offset, int length) {
324         impl.read_long_array(seq, offset, length);
325     }
326
327     public final void read_ulong_array (org.omg.CORBA.ULongSeqHolder JavaDoc seq, int offset, int length) {
328         impl.read_ulong_array(seq, offset, length);
329     }
330
331     public final void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder JavaDoc seq, int offset, int length) {
332         impl.read_ulonglong_array(seq, offset, length);
333     }
334
335     public final void read_longlong_array (org.omg.CORBA.LongLongSeqHolder JavaDoc seq, int offset, int length) {
336         impl.read_longlong_array(seq, offset, length);
337     }
338
339     public final void read_float_array (org.omg.CORBA.FloatSeqHolder JavaDoc seq, int offset, int length) {
340         impl.read_float_array(seq, offset, length);
341     }
342
343     public final void read_double_array (org.omg.CORBA.DoubleSeqHolder JavaDoc seq, int offset, int length) {
344         impl.read_double_array(seq, offset, length);
345     }
346
347     // org.omg.CORBA.portable.ValueBase
348
public final String JavaDoc[] _truncatable_ids() {
349         return impl._truncatable_ids();
350     }
351
352     // java.io.InputStream
353
public final int read(byte b[]) throws IOException JavaDoc {
354         return impl.read(b);
355     }
356
357     public final int read(byte b[], int off, int len) throws IOException JavaDoc {
358         return impl.read(b, off, len);
359     }
360
361     public final long skip(long n) throws IOException JavaDoc {
362         return impl.skip(n);
363     }
364
365     public final int available() throws IOException JavaDoc {
366         return impl.available();
367     }
368
369     public final void close() throws IOException JavaDoc {
370         impl.close();
371     }
372
373     public final void mark(int readlimit) {
374         impl.mark(readlimit);
375     }
376
377     public final void reset() {
378         impl.reset();
379     }
380
381     public final boolean markSupported() {
382         return impl.markSupported();
383     }
384
385     public abstract CDRInputStream dup();
386
387     // Needed by TCUtility
388
public final java.math.BigDecimal JavaDoc read_fixed(short digits, short scale) {
389         return impl.read_fixed(digits, scale);
390     }
391
392     public final boolean isLittleEndian() {
393         return impl.isLittleEndian();
394     }
395
396     protected final ByteBuffer JavaDoc getByteBuffer() {
397         return impl.getByteBuffer();
398     }
399
400     protected final void setByteBuffer(ByteBuffer JavaDoc byteBuffer) {
401         impl.setByteBuffer(byteBuffer);
402     }
403
404     protected final void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
405         impl.setByteBufferWithInfo(bbwi);
406     }
407
408     public final int getBufferLength() {
409         return impl.getBufferLength();
410     }
411
412     protected final void setBufferLength(int value) {
413         impl.setBufferLength(value);
414     }
415
416     protected final int getIndex() {
417         return impl.getIndex();
418     }
419
420     protected final void setIndex(int value) {
421         impl.setIndex(value);
422     }
423
424     public final void orb(org.omg.CORBA.ORB JavaDoc orb) {
425         impl.orb(orb);
426     }
427
428     public final GIOPVersion getGIOPVersion() {
429         return impl.getGIOPVersion();
430     }
431
432     public final BufferManagerRead getBufferManager() {
433         return impl.getBufferManager();
434     }
435
436     // This should be overridden by any stream (ex: IIOPInputStream)
437
// which wants to read values. Thus, TypeCodeInputStream doesn't
438
// have to do this.
439
public CodeBase getCodeBase() {
440         return null;
441     }
442
443     // Use Latin-1 for GIOP 1.0 or when code set negotiation was not
444
// performed.
445
protected CodeSetConversion.BTCConverter createCharBTCConverter() {
446         return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1,
447                                                         impl.isLittleEndian());
448     }
449
450     // Subclasses must decide what to do here. It's inconvenient to
451
// make the class and this method abstract because of dup().
452
protected abstract CodeSetConversion.BTCConverter createWCharBTCConverter();
453
454     // Prints the current buffer in a human readable form
455
void printBuffer() {
456         impl.printBuffer();
457     }
458
459     /**
460      * Aligns the current position on the given octet boundary
461      * if there are enough bytes available to do so. Otherwise,
462      * it just returns. This is used for some (but not all)
463      * GIOP 1.2 message headers.
464      */

465     public void alignOnBoundary(int octetBoundary) {
466         impl.alignOnBoundary(octetBoundary);
467     }
468
469     // Needed by request and reply messages for GIOP versions >= 1.2 only.
470
public void setHeaderPadding(boolean headerPadding) {
471         impl.setHeaderPadding(headerPadding);
472     }
473     
474     /**
475      * This must be called after determining the proper ORB version,
476      * and setting it on the stream's ORB instance. It can be called
477      * after reading the service contexts, since that is the only place
478      * we can get the ORB version info.
479      *
480      * Trying to unmarshal things requiring repository IDs before calling
481      * this will result in NullPtrExceptions.
482      */

483     public void performORBVersionSpecificInit() {
484         // In the case of SystemExceptions, a stream is created
485
// with its default constructor (and thus no impl is set).
486
if (impl != null)
487             impl.performORBVersionSpecificInit();
488     }
489
490     /**
491      * Resets any internal references to code set converters.
492      * This is useful for forcing the CDR stream to reacquire
493      * converters (probably from its subclasses) when state
494      * has changed.
495      */

496     public void resetCodeSetConverters() {
497         impl.resetCodeSetConverters();
498     }
499
500     public void setMessageMediator(MessageMediator messageMediator)
501     {
502         this.messageMediator = (CorbaMessageMediator) messageMediator;
503     }
504
505     public MessageMediator getMessageMediator()
506     {
507         return messageMediator;
508     }
509
510     // ValueInputStream -----------------------------
511

512     public void start_value() {
513         impl.start_value();
514     }
515
516     public void end_value() {
517         impl.end_value();
518     }
519 }
520
Popular Tags