KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)EncapsInputStream.java 1.14 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
8 package com.sun.corba.se.impl.encoding;
9
10 import java.nio.ByteBuffer JavaDoc;
11 import org.omg.CORBA.CompletionStatus JavaDoc;
12 import com.sun.org.omg.SendingContext.CodeBase;
13 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
14 import com.sun.corba.se.impl.encoding.CDRInputStream;
15 import com.sun.corba.se.impl.encoding.BufferManagerFactory;
16 import com.sun.corba.se.impl.encoding.CodeSetConversion;
17 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
18 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
19
20 import com.sun.corba.se.spi.orb.ORB;
21
22 import com.sun.corba.se.spi.logging.CORBALogDomains;
23
24 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
25
26 /**
27  * Encapsulations are supposed to explicitly define their
28  * code sets and GIOP version. The original resolution to issue 2784
29  * said that the defaults were UTF-8 and UTF-16, but that was not
30  * agreed upon.
31  *
32  * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
33  * UTF16 for wchar/wstring. If no byte order marker is available,
34  * the endianness of the encapsulation is used.
35  *
36  * When more encapsulations arise that have their own special code
37  * sets defined, we can make all constructors take such parameters.
38  */

39 public class EncapsInputStream extends CDRInputStream
40 {
41     private ORBUtilSystemException wrapper ;
42
43     // corba/EncapsOutputStream
44
// corba/ORBSingleton
45
// iiop/ORB
46
public EncapsInputStream(org.omg.CORBA.ORB JavaDoc orb, byte[] buf,
47                  int size, boolean littleEndian,
48                  GIOPVersion version) {
49         super(orb, ByteBuffer.wrap(buf), size, littleEndian,
50           version, Message.CDR_ENC_VERSION,
51           BufferManagerFactory.newBufferManagerRead(
52                       BufferManagerFactory.GROW,
53                       Message.CDR_ENC_VERSION,
54                       (ORB)orb));
55
56     wrapper = ORBUtilSystemException.get( (ORB)orb,
57         CORBALogDomains.RPC_ENCODING ) ;
58
59         performORBVersionSpecificInit();
60     }
61
62     public EncapsInputStream(org.omg.CORBA.ORB JavaDoc orb, ByteBuffer JavaDoc byteBuffer,
63                              int size, boolean littleEndian,
64                              GIOPVersion version) {
65         super(orb, byteBuffer, size, littleEndian,
66               version, Message.CDR_ENC_VERSION,
67               BufferManagerFactory.newBufferManagerRead(
68                       BufferManagerFactory.GROW,
69                       Message.CDR_ENC_VERSION,
70                       (com.sun.corba.se.spi.orb.ORB)orb));
71
72         performORBVersionSpecificInit();
73     }
74
75     // ior/IdentifiableBase
76
// ior/IIOPProfile
77
// corba/ORBSingleton
78
// iiop/ORB
79
public EncapsInputStream(org.omg.CORBA.ORB JavaDoc orb, byte[] data, int size)
80     {
81         this(orb, data, size, GIOPVersion.V1_2);
82     }
83     
84     // corba/AnyImpl
85
public EncapsInputStream(EncapsInputStream eis)
86     {
87         super(eis);
88
89     wrapper = ORBUtilSystemException.get( (ORB)(eis.orb()),
90         CORBALogDomains.RPC_ENCODING ) ;
91
92         performORBVersionSpecificInit();
93     }
94
95     // CDREncapsCodec
96
// ServiceContext
97
//
98
// Assumes big endian (can use consumeEndian to read and set
99
// the endianness if it is an encapsulation with a byte order
100
// mark at the beginning)
101
public EncapsInputStream(org.omg.CORBA.ORB JavaDoc orb, byte[] data, int size, GIOPVersion version)
102     {
103         this(orb, data, size, false, version);
104     }
105
106     /**
107      * Full constructor with a CodeBase parameter useful for
108      * unmarshaling RMI-IIOP valuetypes (technically against the
109      * intention of an encapsulation, but necessary due to OMG
110      * issue 4795. Used by ServiceContexts.
111      */

112     public EncapsInputStream(org.omg.CORBA.ORB JavaDoc orb,
113                              byte[] data,
114                              int size,
115                              GIOPVersion version,
116                              CodeBase codeBase) {
117         super(orb,
118               ByteBuffer.wrap(data),
119               size,
120               false,
121               version, Message.CDR_ENC_VERSION,
122               BufferManagerFactory.newBufferManagerRead(
123                       BufferManagerFactory.GROW,
124                       Message.CDR_ENC_VERSION,
125                       (ORB)orb));
126
127         this.codeBase = codeBase;
128
129         performORBVersionSpecificInit();
130     }
131
132     public CDRInputStream dup() {
133         return new EncapsInputStream(this);
134     }
135
136     protected CodeSetConversion.BTCConverter createCharBTCConverter() {
137         return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1);
138     }
139
140     protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
141         // Wide characters don't exist in GIOP 1.0
142
if (getGIOPVersion().equals(GIOPVersion.V1_0))
143         throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
144
145         // In GIOP 1.1, we shouldn't have byte order markers. Take the order
146
// of the stream if we don't see them.
147
if (getGIOPVersion().equals(GIOPVersion.V1_1))
148             return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
149                                                             isLittleEndian());
150
151         // Assume anything else adheres to GIOP 1.2 requirements.
152
//
153
// Our UTF_16 converter will work with byte order markers, and if
154
// they aren't present, it will use the provided endianness.
155
//
156
// With no byte order marker, it's big endian in GIOP 1.2.
157
// formal 00-11-03 15.3.16.
158
return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
159                                                         false);
160     }
161
162     public CodeBase getCodeBase() {
163         return codeBase;
164     }
165
166     private CodeBase codeBase;
167 }
168
Popular Tags