KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)IDLJavaSerializationInputStream.java 1.4 04/06/07
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.Serializable JavaDoc;
10 import java.io.ObjectInputStream JavaDoc;
11 import java.io.ByteArrayInputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.nio.ByteBuffer JavaDoc;
14 import java.math.BigDecimal JavaDoc;
15 import java.util.LinkedList JavaDoc;
16
17 import com.sun.corba.se.spi.orb.ORB;
18 import com.sun.corba.se.spi.ior.IOR;
19 import com.sun.corba.se.spi.ior.IORFactories;
20 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
21 import com.sun.corba.se.spi.logging.CORBALogDomains;
22 import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
23 import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
24 import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults;
25
26 import com.sun.corba.se.impl.util.Utility;
27 import com.sun.corba.se.impl.orbutil.ORBUtility;
28 import com.sun.corba.se.impl.corba.TypeCodeImpl;
29 import com.sun.corba.se.impl.util.RepositoryId;
30 import com.sun.corba.se.impl.orbutil.ORBConstants;
31 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
32 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
33
34 import org.omg.CORBA.Any JavaDoc;
35 import org.omg.CORBA.TypeCode JavaDoc;
36 import org.omg.CORBA.Principal JavaDoc;
37 import org.omg.CORBA.portable.IDLEntity JavaDoc;
38
39 /**
40  * Implementation class that uses Java serialization for input streams.
41  * This assumes a GIOP version 1.2 message format.
42  *
43  * This class uses a ByteArrayInputStream as the underlying buffer. The
44  * first 16 bytes are directly read out of the underlying buffer. This allows
45  * [GIOPHeader (12 bytes) + requestID (4 bytes)] to be read as bytes.
46  * Subsequent write operations on this output stream object uses
47  * ObjectInputStream class to read into the buffer. This allows unmarshaling
48  * complex types and graphs using the ObjectInputStream implementation.
49  *
50  * Note, this class assumes a GIOP 1.2 style header. Further, the first
51  * 12 bytes, that is, the GIOPHeader is read directly from the received
52  * message, before this stream object is called. So, this class effectively
53  * reads only the requestID (4 bytes) directly, and uses the
54  * ObjectInputStream for further unmarshaling.
55  *
56  * @author Ram Jeyaraman
57  */

58 public class IDLJavaSerializationInputStream extends CDRInputStreamBase {
59
60     private ORB orb;
61     private int bufSize;
62     private ByteBuffer JavaDoc buffer;
63     private byte encodingVersion;
64     private ObjectInputStream JavaDoc is;
65     private _ByteArrayInputStream bis;
66     private BufferManagerRead bufferManager;
67
68     // [GIOPHeader(12) + requestID(4)] bytes
69
private final int directReadLength = Message.GIOPMessageHeaderLength + 4;
70
71     // Used for mark / reset operations.
72
private boolean markOn;
73     private int peekIndex, peekCount;
74     private LinkedList JavaDoc markedItemQ = new LinkedList JavaDoc();
75
76     protected ORBUtilSystemException wrapper;
77
78     class _ByteArrayInputStream extends ByteArrayInputStream JavaDoc {
79
80     _ByteArrayInputStream(byte[] buf) {
81         super(buf);
82     }
83     
84     int getPosition() {
85         return this.pos;
86     }
87
88     void setPosition(int value) {
89         if (value < 0 || value > count) {
90         throw new IndexOutOfBoundsException JavaDoc();
91         }
92         this.pos = value;
93     }
94     }
95
96     class MarshalObjectInputStream extends ObjectInputStream JavaDoc {
97
98     ORB orb;
99     
100     MarshalObjectInputStream(java.io.InputStream JavaDoc out, ORB orb)
101             throws IOException JavaDoc {
102
103         super(out);
104         this.orb = orb;
105
106         java.security.AccessController.doPrivileged(
107             new java.security.PrivilegedAction JavaDoc() {
108             public Object JavaDoc run() {
109             // needs SerializablePermission("enableSubstitution")
110
enableResolveObject(true);
111             return null;
112             }
113             }
114         );
115     }
116
117     /**
118      * Connect the Stub to the ORB.
119      */

120     protected final Object JavaDoc resolveObject(Object JavaDoc obj) throws IOException JavaDoc {
121         try {
122         if (StubAdapter.isStub(obj)) {
123             StubAdapter.connect(obj, orb);
124         }
125         } catch (java.rmi.RemoteException JavaDoc re) {
126         IOException JavaDoc ie = new IOException JavaDoc("resolveObject failed");
127         ie.initCause(re);
128         throw ie;
129         }
130         return obj;
131     }
132     }
133
134     public IDLJavaSerializationInputStream(byte encodingVersion) {
135     super();
136     this.encodingVersion = encodingVersion;
137     }
138
139     public void init(org.omg.CORBA.ORB JavaDoc orb,
140                      ByteBuffer JavaDoc byteBuffer,
141                      int bufSize,
142                      boolean littleEndian,
143                      BufferManagerRead bufferManager) {
144     this.orb = (ORB) orb;
145     this.bufSize = bufSize;
146     this.bufferManager = bufferManager;
147     buffer = byteBuffer;
148     wrapper =
149         ORBUtilSystemException.get((ORB)orb, CORBALogDomains.RPC_ENCODING);
150
151     byte[] buf;
152     if (buffer.hasArray()) {
153         buf = buffer.array();
154     } else {
155         buf = new byte[bufSize];
156         buffer.get(buf);
157     }
158     // Note: at this point, the buffer position is zero. The setIndex()
159
// method call can be used to set a desired read index.
160
bis = new _ByteArrayInputStream(buf);
161     }
162
163     // Called from read_octet or read_long or read_ulong method.
164
private void initObjectInputStream() {
165     //System.out.print(" is ");
166
if (is != null) {
167         throw wrapper.javaStreamInitFailed();
168     }
169     try {
170         is = new MarshalObjectInputStream(bis, orb);
171     } catch (Exception JavaDoc e) {
172         throw wrapper.javaStreamInitFailed(e);
173     }
174     }
175
176     // org.omg.CORBA.portable.InputStream
177

178     // Primitive types.
179

180     public boolean read_boolean() {
181     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
182
return ((Boolean JavaDoc)markedItemQ.removeFirst()).booleanValue();
183     }
184     if (markOn && !(markedItemQ.isEmpty()) &&
185             (peekIndex < peekCount)) { // peek
186
return ((Boolean JavaDoc)markedItemQ.get(peekIndex++)).booleanValue();
187     }
188     try {
189         boolean value = is.readBoolean();
190         if (markOn) { // enqueue
191
markedItemQ.addLast(Boolean.valueOf(value));
192         }
193         return value;
194     } catch (Exception JavaDoc e) {
195         throw wrapper.javaSerializationException(e, "read_boolean");
196     }
197     }
198
199     public char read_char() {
200     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
201
return ((Character JavaDoc)markedItemQ.removeFirst()).charValue();
202     }
203     if (markOn && !(markedItemQ.isEmpty()) &&
204             (peekIndex < peekCount)) { // peek
205
return ((Character JavaDoc)markedItemQ.get(peekIndex++)).charValue();
206     }
207     try {
208         char value = is.readChar();
209         if (markOn) { // enqueue
210
markedItemQ.addLast(new Character JavaDoc(value));
211         }
212         return value;
213     } catch (Exception JavaDoc e) {
214         throw wrapper.javaSerializationException(e, "read_char");
215     }
216     }
217
218     public char read_wchar() {
219     return this.read_char();
220     }
221
222     public byte read_octet() {
223
224     // check if size < [ GIOPHeader(12) + requestID(4)] bytes
225
if (bis.getPosition() < directReadLength) {
226             byte b = (byte) bis.read();
227         if (bis.getPosition() == directReadLength) {
228         initObjectInputStream();
229         }
230         return b;
231     }
232
233     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
234
return ((Byte JavaDoc)markedItemQ.removeFirst()).byteValue();
235     }
236
237     if (markOn && !(markedItemQ.isEmpty()) &&
238             (peekIndex < peekCount)) { // peek
239
return ((Byte JavaDoc)markedItemQ.get(peekIndex++)).byteValue();
240     }
241
242     try {
243         byte value = is.readByte();
244         if (markOn) { // enqueue
245
//markedItemQ.addLast(Byte.valueOf(value)); // only in JDK 1.5
246
markedItemQ.addLast(new Byte JavaDoc(value));
247         }
248         return value;
249     } catch (Exception JavaDoc e) {
250         throw wrapper.javaSerializationException(e, "read_octet");
251     }
252     }
253
254     public short read_short() {
255     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
256
return ((Short JavaDoc)markedItemQ.removeFirst()).shortValue();
257     }
258     if (markOn && !(markedItemQ.isEmpty()) &&
259             (peekIndex < peekCount)) { // peek
260
return ((Short JavaDoc)markedItemQ.get(peekIndex++)).shortValue();
261     }
262
263     try {
264         short value = is.readShort();
265         if (markOn) { // enqueue
266
markedItemQ.addLast(new Short JavaDoc(value));
267         }
268         return value;
269     } catch (Exception JavaDoc e) {
270         throw wrapper.javaSerializationException(e, "read_short");
271     }
272     }
273
274     public short read_ushort() {
275     return this.read_short();
276     }
277
278     public int read_long() {
279
280     // check if size < [ GIOPHeader(12) + requestID(4)] bytes
281
if (bis.getPosition() < directReadLength) {
282
283         // Use big endian (network byte order). This is fixed.
284
// Both the writer and reader use the same byte order.
285
int b1 = (bis.read() << 24) & 0xFF000000;
286             int b2 = (bis.read() << 16) & 0x00FF0000;
287             int b3 = (bis.read() << 8) & 0x0000FF00;
288             int b4 = (bis.read() << 0) & 0x000000FF;
289
290         if (bis.getPosition() == directReadLength) {
291         initObjectInputStream();
292         } else if (bis.getPosition() > directReadLength) {
293         // Cannot happen. All direct reads are contained
294
// within the first 16 bytes.
295
wrapper.javaSerializationException("read_long");
296         }
297
298         return (b1 | b2 | b3 | b4);
299     }
300
301     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
302
return ((Integer JavaDoc)markedItemQ.removeFirst()).intValue();
303     }
304
305     if (markOn && !(markedItemQ.isEmpty()) &&
306             (peekIndex < peekCount)) { // peek
307
return ((Integer JavaDoc)markedItemQ.get(peekIndex++)).intValue();
308     }
309
310     try {
311         int value = is.readInt();
312         if (markOn) { // enqueue
313
markedItemQ.addLast(new Integer JavaDoc(value));
314         }
315         return value;
316     } catch (Exception JavaDoc e) {
317         throw wrapper.javaSerializationException(e, "read_long");
318     }
319     }
320
321     public int read_ulong() {
322     return this.read_long();
323     }
324
325     public long read_longlong() {
326     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
327
return ((Long JavaDoc)markedItemQ.removeFirst()).longValue();
328     }
329     if (markOn && !(markedItemQ.isEmpty()) &&
330             (peekIndex < peekCount)) { // peek
331
return ((Long JavaDoc)markedItemQ.get(peekIndex++)).longValue();
332     }
333
334     try {
335         long value = is.readLong();
336         if (markOn) { // enqueue
337
markedItemQ.addLast(new Long JavaDoc(value));
338         }
339         return value;
340     } catch (Exception JavaDoc e) {
341         throw wrapper.javaSerializationException(e, "read_longlong");
342     }
343     }
344
345     public long read_ulonglong() {
346     return read_longlong();
347     }
348
349     public float read_float() {
350     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
351
return ((Float JavaDoc)markedItemQ.removeFirst()).floatValue();
352     }
353     if (markOn && !(markedItemQ.isEmpty()) &&
354             (peekIndex < peekCount)) { // peek
355
return ((Float JavaDoc)markedItemQ.get(peekIndex++)).floatValue();
356     }
357
358     try {
359         float value = is.readFloat();
360         if (markOn) { // enqueue
361
markedItemQ.addLast(new Float JavaDoc(value));
362         }
363         return value;
364     } catch (Exception JavaDoc e) {
365         throw wrapper.javaSerializationException(e, "read_float");
366     }
367     }
368
369     public double read_double() {
370     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
371
return ((Double JavaDoc)markedItemQ.removeFirst()).doubleValue();
372     }
373     if (markOn && !(markedItemQ.isEmpty()) &&
374             (peekIndex < peekCount)) { // peek
375
return ((Double JavaDoc)markedItemQ.get(peekIndex++)).doubleValue();
376     }
377
378     try {
379         double value = is.readDouble();
380         if (markOn) { // enqueue
381
markedItemQ.addLast(new Double JavaDoc(value));
382         }
383         return value;
384     } catch (Exception JavaDoc e) {
385         throw wrapper.javaSerializationException(e, "read_double");
386     }
387     }
388
389     // String types.
390

391     public String JavaDoc read_string() {
392     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
393
return (String JavaDoc) markedItemQ.removeFirst();
394     }
395     if (markOn && !(markedItemQ.isEmpty()) &&
396         (peekIndex < peekCount)) { // peek
397
return (String JavaDoc) markedItemQ.get(peekIndex++);
398     }
399     try {
400         String JavaDoc value = is.readUTF();
401         if (markOn) { // enqueue
402
markedItemQ.addLast(value);
403         }
404         return value;
405     } catch (Exception JavaDoc e) {
406         throw wrapper.javaSerializationException(e, "read_string");
407     }
408     }
409
410     public String JavaDoc read_wstring() {
411     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
412
return (String JavaDoc) markedItemQ.removeFirst();
413     }
414     if (markOn && !(markedItemQ.isEmpty()) &&
415             (peekIndex < peekCount)) { // peek
416
return (String JavaDoc) markedItemQ.get(peekIndex++);
417     }
418     try {
419         String JavaDoc value = (String JavaDoc) is.readObject();
420         if (markOn) { // enqueue
421
markedItemQ.addLast(value);
422         }
423         return value;
424     } catch (Exception JavaDoc e) {
425         throw wrapper.javaSerializationException(e, "read_wstring");
426     }
427     }
428
429     // Array types.
430

431     public void read_boolean_array(boolean[] value, int offset, int length){
432     for(int i = 0; i < length; i++) {
433             value[i+offset] = read_boolean();
434         }
435     }
436
437     public void read_char_array(char[] value, int offset, int length) {
438         for(int i=0; i < length; i++) {
439             value[i+offset] = read_char();
440         }
441     }
442
443     public void read_wchar_array(char[] value, int offset, int length) {
444     read_char_array(value, offset, length);
445     }
446
447     public void read_octet_array(byte[] value, int offset, int length) {
448         for(int i=0; i < length; i++) {
449             value[i+offset] = read_octet();
450         }
451     /* // Cannot use this efficient read due to mark/reset support.
452     try {
453         while (length > 0) {
454         int n = is.read(value, offset, length);
455         offset += n;
456         length -= n;
457         }
458     } catch (Exception e) {
459         throw wrapper.javaSerializationException(e, "read_octet_array");
460     }
461     */

462     }
463
464     public void read_short_array(short[] value, int offset, int length) {
465         for(int i=0; i < length; i++) {
466             value[i+offset] = read_short();
467         }
468     }
469
470     public void read_ushort_array(short[] value, int offset, int length) {
471     read_short_array(value, offset, length);
472     }
473
474     public void read_long_array(int[] value, int offset, int length) {
475         for(int i=0; i < length; i++) {
476             value[i+offset] = read_long();
477         }
478     }
479
480     public void read_ulong_array(int[] value, int offset, int length) {
481     read_long_array(value, offset, length);
482     }
483
484     public void read_longlong_array(long[] value, int offset, int length) {
485         for(int i=0; i < length; i++) {
486             value[i+offset] = read_longlong();
487         }
488     }
489
490     public void read_ulonglong_array(long[] value, int offset, int length) {
491     read_longlong_array(value, offset, length);
492     }
493
494     public void read_float_array(float[] value, int offset, int length) {
495         for(int i=0; i < length; i++) {
496             value[i+offset] = read_float();
497         }
498     }
499
500     public void read_double_array(double[] value, int offset, int length) {
501         for(int i=0; i < length; i++) {
502             value[i+offset] = read_double();
503         }
504     }
505
506     // Complex types.
507

508     public org.omg.CORBA.Object JavaDoc read_Object() {
509     return read_Object(null);
510     }
511
512     public TypeCode JavaDoc read_TypeCode() {
513         TypeCodeImpl tc = new TypeCodeImpl(orb);
514         tc.read_value(parent);
515     return tc;
516     }
517
518     public Any JavaDoc read_any() {
519
520         Any JavaDoc any = orb.create_any();
521         TypeCodeImpl tc = new TypeCodeImpl(orb);
522
523         // read off the typecode
524

525         // REVISIT We could avoid this try-catch if we could peek the typecode
526
// kind off this stream and see if it is a tk_value.
527
// Looking at the code we know that for tk_value the Any.read_value()
528
// below ignores the tc argument anyway (except for the kind field).
529
// But still we would need to make sure that the whole typecode,
530
// including encapsulations, is read off.
531
try {
532             tc.read_value(parent);
533         } catch (org.omg.CORBA.MARSHAL JavaDoc ex) {
534             if (tc.kind().value() != org.omg.CORBA.TCKind._tk_value) {
535                 throw ex;
536         }
537             // We can be sure that the whole typecode encapsulation has been
538
// read off.
539
ex.printStackTrace();
540         }
541
542         // read off the value of the any.
543
any.read_value(parent, tc);
544
545         return any;
546     }
547
548     public Principal JavaDoc read_Principal() {
549     // We don't need an implementation for this method, since principal
550
// is absent in GIOP version 1.2 or above.
551
int len = read_long();
552         byte[] pvalue = new byte[len];
553         read_octet_array(pvalue,0,len);
554         Principal JavaDoc p = new com.sun.corba.se.impl.corba.PrincipalImpl();
555         p.name(pvalue);
556         return p;
557     }
558
559     public BigDecimal JavaDoc read_fixed() {
560         return new BigDecimal JavaDoc(read_fixed_buffer().toString());
561     }
562
563     // Each octet contains (up to) two decimal digits. If the fixed type has
564
// an odd number of decimal digits, then the representation
565
// begins with the first (most significant) digit.
566
// Otherwise, this first half-octet is all zero, and the first digit
567
// is in the second half-octet.
568
// The sign configuration, in the last half-octet of the representation,
569
// is 0xD for negative numbers and 0xC for positive and zero values.
570
private StringBuffer JavaDoc read_fixed_buffer() {
571         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(64);
572         byte doubleDigit;
573         int firstDigit;
574         int secondDigit;
575         boolean wroteFirstDigit = false;
576         boolean more = true;
577         while (more) {
578             doubleDigit = read_octet();
579             firstDigit = (int)((doubleDigit & 0xf0) >> 4);
580             secondDigit = (int)(doubleDigit & 0x0f);
581             if (wroteFirstDigit || firstDigit != 0) {
582                 buffer.append(Character.forDigit(firstDigit, 10));
583                 wroteFirstDigit = true;
584             }
585             if (secondDigit == 12) {
586                 // positive number or zero
587
if ( ! wroteFirstDigit) {
588                     // zero
589
return new StringBuffer JavaDoc("0.0");
590                 } else {
591                     // positive number
592
// done
593
}
594                 more = false;
595             } else if (secondDigit == 13) {
596                 // negative number
597
buffer.insert(0, '-');
598                 more = false;
599             } else {
600                 buffer.append(Character.forDigit(secondDigit, 10));
601                 wroteFirstDigit = true;
602             }
603         }
604         return buffer;
605     }
606
607     public org.omg.CORBA.Object JavaDoc read_Object(java.lang.Class JavaDoc clz) {
608
609     // In any case, we must first read the IOR.
610
IOR ior = IORFactories.makeIOR(parent) ;
611     if (ior.isNil()) {
612         return null;
613     }
614
615     PresentationManager.StubFactoryFactory sff =
616         ORB.getStubFactoryFactory();
617     String JavaDoc codeBase = ior.getProfile().getCodebase();
618     PresentationManager.StubFactory stubFactory = null;
619
620         if (clz == null) {
621         RepositoryId rid = RepositoryId.cache.getId(ior.getTypeId() );
622         String JavaDoc className = rid.getClassName();
623         boolean isIDLInterface = rid.isIDLType();
624
625         if (className == null || className.equals( "" )) {
626         stubFactory = null;
627         } else {
628         try {
629             stubFactory = sff.createStubFactory(className,
630             isIDLInterface, codeBase, (Class JavaDoc) null,
631             (ClassLoader JavaDoc) null);
632         } catch (Exception JavaDoc exc) {
633             // Could not create stubFactory, so use null.
634
// XXX stubFactory handling is still too complex:
635
// Can we resolve the stubFactory question once in
636
// a single place?
637
stubFactory = null ;
638         }
639         }
640         } else if (StubAdapter.isStubClass(clz)) {
641         stubFactory = PresentationDefaults.makeStaticStubFactory(clz);
642     } else {
643         // clz is an interface class
644
boolean isIDL = IDLEntity JavaDoc.class.isAssignableFrom(clz);
645
646         stubFactory = sff.createStubFactory(
647          clz.getName(), isIDL, codeBase, clz, clz.getClassLoader());
648     }
649
650     return CDRInputStream_1_0.internalIORToObject(ior, stubFactory, orb);
651     }
652
653     public org.omg.CORBA.ORB JavaDoc orb() {
654     return this.orb;
655     }
656
657     // org.omg.CORBA_2_3.portable.InputStream
658

659     public java.io.Serializable JavaDoc read_value() {
660     if (!markOn && !(markedItemQ.isEmpty())) { // dequeue
661
return (Serializable JavaDoc) markedItemQ.removeFirst();
662     }
663     if (markOn && !(markedItemQ.isEmpty()) &&
664             (peekIndex < peekCount)) { // peek
665
return (Serializable JavaDoc) markedItemQ.get(peekIndex++);
666     }
667     try {
668         Serializable JavaDoc value = (java.io.Serializable JavaDoc) is.readObject();
669         if (markOn) { // enqueue
670
markedItemQ.addLast(value);
671         }
672         return value;
673     } catch (Exception JavaDoc e) {
674         throw wrapper.javaSerializationException(e, "read_value");
675     }
676     }
677
678     public java.io.Serializable JavaDoc read_value(java.lang.Class JavaDoc clz) {
679     return read_value();
680     }
681
682     public java.io.Serializable JavaDoc read_value(
683             org.omg.CORBA.portable.BoxedValueHelper JavaDoc factory) {
684     return read_value();
685     }
686
687     public java.io.Serializable JavaDoc read_value(java.lang.String JavaDoc rep_id) {
688     return read_value();
689     }
690
691     public java.io.Serializable JavaDoc read_value(java.io.Serializable JavaDoc value) {
692     return read_value();
693     }
694
695     public java.lang.Object JavaDoc read_abstract_interface() {
696     return read_abstract_interface(null);
697     }
698
699     public java.lang.Object JavaDoc read_abstract_interface(java.lang.Class JavaDoc clz) {
700         boolean isObject = read_boolean();
701         if (isObject) {
702             return read_Object(clz);
703         } else {
704             return read_value();
705     }
706     }
707
708     // com.sun.corba.se.impl.encoding.MarshalInputStream
709
public void consumeEndian() {
710     throw wrapper.giopVersionError();
711     }
712
713     public int getPosition() {
714     try {
715         return bis.getPosition();
716     } catch (Exception JavaDoc e) {
717         throw wrapper.javaSerializationException(e, "getPosition");
718     }
719     }
720
721     // org.omg.CORBA.DataInputStream
722
public java.lang.Object JavaDoc read_Abstract() {
723         return read_abstract_interface();
724     }
725
726     public java.io.Serializable JavaDoc read_Value() {
727         return read_value();
728     }
729
730     public void read_any_array (org.omg.CORBA.AnySeqHolder JavaDoc seq,
731                 int offset, int length) {
732     read_any_array(seq.value, offset, length);
733     }
734
735     private final void read_any_array(org.omg.CORBA.Any JavaDoc[] value,
736                      int offset, int length) {
737         for(int i=0; i < length; i++) {
738             value[i+offset] = read_any();
739         }
740     }
741
742     public void read_boolean_array (org.omg.CORBA.BooleanSeqHolder JavaDoc seq,
743                     int offset, int length){
744     read_boolean_array(seq.value, offset, length);
745     }
746
747     public void read_char_array (org.omg.CORBA.CharSeqHolder JavaDoc seq,
748                  int offset, int length){
749     read_char_array(seq.value, offset, length);
750     }
751
752     public void read_wchar_array (org.omg.CORBA.WCharSeqHolder JavaDoc seq,
753                   int offset, int length){
754     read_wchar_array(seq.value, offset, length);
755     }
756
757     public void read_octet_array (org.omg.CORBA.OctetSeqHolder JavaDoc seq,
758                   int offset, int length){
759     read_octet_array(seq.value, offset, length);
760     }
761
762     public void read_short_array (org.omg.CORBA.ShortSeqHolder JavaDoc seq,
763                   int offset, int length){
764     read_short_array(seq.value, offset, length);
765     }
766
767     public void read_ushort_array (org.omg.CORBA.UShortSeqHolder JavaDoc seq,
768                    int offset, int length){
769     read_ushort_array(seq.value, offset, length);
770     }
771
772     public void read_long_array (org.omg.CORBA.LongSeqHolder JavaDoc seq,
773                  int offset, int length){
774     read_long_array(seq.value, offset, length);
775     }
776
777     public void read_ulong_array (org.omg.CORBA.ULongSeqHolder JavaDoc seq,
778                   int offset, int length){
779     read_ulong_array(seq.value, offset, length);
780     }
781
782     public void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder JavaDoc seq,
783                       int offset, int length){
784     read_ulonglong_array(seq.value, offset, length);
785     }
786
787     public void read_longlong_array (org.omg.CORBA.LongLongSeqHolder JavaDoc seq,
788                      int offset, int length){
789     read_longlong_array(seq.value, offset, length);
790     }
791
792     public void read_float_array (org.omg.CORBA.FloatSeqHolder JavaDoc seq,
793                   int offset, int length){
794     read_float_array(seq.value, offset, length);
795     }
796
797     public void read_double_array (org.omg.CORBA.DoubleSeqHolder JavaDoc seq,
798                    int offset, int length){
799     read_double_array(seq.value, offset, length);
800     }
801
802     // org.omg.CORBA.portable.ValueBase
803

804     public String JavaDoc[] _truncatable_ids() {
805     throw wrapper.giopVersionError();
806     }
807
808     // java.io.InputStream
809
// REVISIT - should we make these throw UnsupportedOperationExceptions?
810
// Right now, they'll go up to the java.io versions!
811

812     // public int read(byte b[]) throws IOException;
813
// public int read(byte b[], int off, int len) throws IOException
814
// public long skip(long n) throws IOException;
815
// public int available() throws IOException;
816
// public void close() throws IOException;
817

818     public void mark(int readLimit) {
819     // Nested mark disallowed.
820
// Further, mark is not supported until first 16 bytes are read.
821
if (markOn || is == null) {
822         throw wrapper.javaSerializationException("mark");
823     }
824     markOn = true;
825     if (!(markedItemQ.isEmpty())) {
826         peekIndex = 0;
827         peekCount = markedItemQ.size();
828     }
829     /*
830     // Note: only ByteArrayInputStream supports mark/reset.
831     if (is == null || is.markSupported() == false) {
832         throw wrapper.javaSerializationException("mark");
833     }
834     is.mark(readLimit);
835     */

836     }
837
838     public void reset() {
839     markOn = false;
840     peekIndex = 0;
841     peekCount = 0;
842     /*
843     // Note: only ByteArrayInputStream supports mark/reset.
844     if (is == null || is.markSupported() == false) {
845         throw wrapper.javaSerializationException("mark");
846     }
847     try {
848         is.reset();
849     } catch (Exception e) {
850         throw wrapper.javaSerializationException(e, "reset");
851     }
852     */

853     }
854
855     // This should return false so that outside users (people using the JDK)
856
// don't have any guarantees that mark/reset will work in their
857
// custom marshaling code. This is necessary since they could do things
858
// like expect obj1a == obj1b in the following code:
859
//
860
// is.mark(10000);
861
// Object obj1a = is.readObject();
862
// is.reset();
863
// Object obj1b = is.readObject();
864
//
865
public boolean markSupported() {
866     return true;
867     }
868
869     // Needed by AnyImpl and ServiceContexts
870
public CDRInputStreamBase dup() {
871
872         CDRInputStreamBase result = null ;
873
874         try {
875             result = (CDRInputStreamBase) this.getClass().newInstance();
876         } catch (Exception JavaDoc e) {
877         throw wrapper.couldNotDuplicateCdrInputStream(e);
878         }
879     
880         result.init(this.orb, this.buffer, this.bufSize, false, null);
881
882     // Set the buffer position.
883
((IDLJavaSerializationInputStream)result).skipBytes(getPosition());
884
885     // Set mark related data.
886
((IDLJavaSerializationInputStream)result).
887         setMarkData(markOn, peekIndex, peekCount,
888             (LinkedList JavaDoc) markedItemQ.clone());
889
890     return result;
891     }
892
893     // Used exclusively by the dup() method.
894
void skipBytes(int len) {
895     try {
896         is.skipBytes(len);
897     } catch (Exception JavaDoc e) {
898         throw wrapper.javaSerializationException(e, "skipBytes");
899     }
900     }
901
902     // Used exclusively by the dup() method.
903
void setMarkData(boolean markOn, int peekIndex, int peekCount,
904              LinkedList JavaDoc markedItemQ) {
905     this.markOn = markOn;
906     this.peekIndex = peekIndex;
907     this.peekCount = peekCount;
908     this.markedItemQ = markedItemQ;
909     }
910
911     // Needed by TCUtility
912
public java.math.BigDecimal JavaDoc read_fixed(short digits, short scale) {
913         // digits isn't really needed here
914
StringBuffer JavaDoc buffer = read_fixed_buffer();
915         if (digits != buffer.length())
916         throw wrapper.badFixed( new Integer JavaDoc(digits),
917         new Integer JavaDoc(buffer.length()) ) ;
918         buffer.insert(digits - scale, '.');
919         return new BigDecimal JavaDoc(buffer.toString());
920     }
921
922     // Needed by TypeCodeImpl
923
public boolean isLittleEndian() {
924     throw wrapper.giopVersionError();
925     }
926
927     // Needed by request and reply messages for GIOP versions >= 1.2 only.
928
void setHeaderPadding(boolean headerPadding) {
929     // no-op. We don't care about body alignment while using
930
// Java serialization. What the GIOP spec states does not apply here.
931
}
932     
933     // Needed by IIOPInputStream and other subclasses
934

935     public ByteBuffer JavaDoc getByteBuffer() {
936     throw wrapper.giopVersionError();
937     }
938
939     public void setByteBuffer(ByteBuffer JavaDoc byteBuffer) {
940     throw wrapper.giopVersionError();
941     }
942
943     public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
944     throw wrapper.giopVersionError();
945     }
946
947     public int getBufferLength() {
948     return bufSize;
949     }
950
951     public void setBufferLength(int value) {
952     // this is redundant, since buffer size was already specified
953
// as part of the init call. So, ignore.
954
}
955
956     public int getIndex() {
957     return bis.getPosition();
958     }
959
960     public void setIndex(int value) {
961     try {
962         bis.setPosition(value);
963     } catch (IndexOutOfBoundsException JavaDoc e) {
964         throw wrapper.javaSerializationException(e, "setIndex");
965     }
966     }
967
968     public void orb(org.omg.CORBA.ORB JavaDoc orb) {
969     this.orb = (ORB) orb;
970     }
971
972     public BufferManagerRead getBufferManager() {
973     return bufferManager;
974     }
975
976     public GIOPVersion getGIOPVersion() {
977     return GIOPVersion.V1_2;
978     }
979
980     com.sun.org.omg.SendingContext.CodeBase getCodeBase() {
981         return parent.getCodeBase();
982     }
983
984     void printBuffer() {
985     byte[] buf = this.buffer.array();
986
987         System.out.println("+++++++ Input Buffer ++++++++");
988         System.out.println();
989         System.out.println("Current position: " + getPosition());
990         System.out.println("Total length : " + this.bufSize);
991         System.out.println();
992
993         char[] charBuf = new char[16];
994
995         try {
996
997             for (int i = 0; i < buf.length; i += 16) {
998                 
999                 int j = 0;
1000                
1001                // For every 16 bytes, there is one line
1002
// of output. First, the hex output of
1003
// the 16 bytes with each byte separated
1004
// by a space.
1005
while (j < 16 && j + i < buf.length) {
1006                    int k = buf[i + j];
1007                    if (k < 0)
1008                        k = 256 + k;
1009                    String JavaDoc hex = Integer.toHexString(k);
1010                    if (hex.length() == 1)
1011                        hex = "0" + hex;
1012                    System.out.print(hex + " ");
1013                    j++;
1014                }
1015                
1016                // Add any extra spaces to align the
1017
// text column in case we didn't end
1018
// at 16
1019
while (j < 16) {
1020                    System.out.print(" ");
1021                    j++;
1022                }
1023                
1024                // Now output the ASCII equivalents. Non-ASCII
1025
// characters are shown as periods.
1026
int x = 0;
1027
1028                while (x < 16 && x + i < buf.length) {
1029                    if (ORBUtility.isPrintable((char)buf[i + x])) {
1030                        charBuf[x] = (char) buf[i + x];
1031                    } else {
1032                        charBuf[x] = '.';
1033            }
1034                    x++;
1035                }
1036                System.out.println(new String JavaDoc(charBuf, 0, x));
1037            }
1038        } catch (Throwable JavaDoc t) {
1039            t.printStackTrace();
1040        }
1041        System.out.println("++++++++++++++++++++++++++++++");
1042    }
1043
1044    void alignOnBoundary(int octetBoundary) {
1045    throw wrapper.giopVersionError();
1046    }
1047
1048    void performORBVersionSpecificInit() {
1049    // No-op.
1050
}
1051
1052    public void resetCodeSetConverters() {
1053    // No-op.
1054
}
1055
1056    // ValueInputStream -------------------------
1057

1058    public void start_value() {
1059    throw wrapper.giopVersionError();
1060    }
1061
1062    public void end_value() {
1063    throw wrapper.giopVersionError();
1064    }
1065}
1066
Popular Tags