001: /*
002: * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.corba.se.impl.encoding;
027:
028: import java.nio.ByteBuffer;
029: import org.omg.CORBA.CompletionStatus;
030: import com.sun.org.omg.SendingContext.CodeBase;
031: import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
032: import com.sun.corba.se.impl.encoding.CDRInputStream;
033: import com.sun.corba.se.impl.encoding.BufferManagerFactory;
034: import com.sun.corba.se.impl.encoding.CodeSetConversion;
035: import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
036: import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
037:
038: import com.sun.corba.se.spi.orb.ORB;
039:
040: import com.sun.corba.se.spi.logging.CORBALogDomains;
041:
042: import com.sun.corba.se.impl.logging.ORBUtilSystemException;
043:
044: /**
045: * Encapsulations are supposed to explicitly define their
046: * code sets and GIOP version. The original resolution to issue 2784
047: * said that the defaults were UTF-8 and UTF-16, but that was not
048: * agreed upon.
049: *
050: * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
051: * UTF16 for wchar/wstring. If no byte order marker is available,
052: * the endianness of the encapsulation is used.
053: *
054: * When more encapsulations arise that have their own special code
055: * sets defined, we can make all constructors take such parameters.
056: */
057: public class EncapsInputStream extends CDRInputStream {
058: private ORBUtilSystemException wrapper;
059:
060: // corba/EncapsOutputStream
061: // corba/ORBSingleton
062: // iiop/ORB
063: public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] buf,
064: int size, boolean littleEndian, GIOPVersion version) {
065: super (orb, ByteBuffer.wrap(buf), size, littleEndian, version,
066: Message.CDR_ENC_VERSION, BufferManagerFactory
067: .newBufferManagerRead(
068: BufferManagerFactory.GROW,
069: Message.CDR_ENC_VERSION, (ORB) orb));
070:
071: wrapper = ORBUtilSystemException.get((ORB) orb,
072: CORBALogDomains.RPC_ENCODING);
073:
074: performORBVersionSpecificInit();
075: }
076:
077: public EncapsInputStream(org.omg.CORBA.ORB orb,
078: ByteBuffer byteBuffer, int size, boolean littleEndian,
079: GIOPVersion version) {
080: super (orb, byteBuffer, size, littleEndian, version,
081: Message.CDR_ENC_VERSION, BufferManagerFactory
082: .newBufferManagerRead(
083: BufferManagerFactory.GROW,
084: Message.CDR_ENC_VERSION,
085: (com.sun.corba.se.spi.orb.ORB) orb));
086:
087: performORBVersionSpecificInit();
088: }
089:
090: // ior/IdentifiableBase
091: // ior/IIOPProfile
092: // corba/ORBSingleton
093: // iiop/ORB
094: public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data,
095: int size) {
096: this (orb, data, size, GIOPVersion.V1_2);
097: }
098:
099: // corba/AnyImpl
100: public EncapsInputStream(EncapsInputStream eis) {
101: super (eis);
102:
103: wrapper = ORBUtilSystemException.get((ORB) (eis.orb()),
104: CORBALogDomains.RPC_ENCODING);
105:
106: performORBVersionSpecificInit();
107: }
108:
109: // CDREncapsCodec
110: // ServiceContext
111: //
112: // Assumes big endian (can use consumeEndian to read and set
113: // the endianness if it is an encapsulation with a byte order
114: // mark at the beginning)
115: public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data,
116: int size, GIOPVersion version) {
117: this (orb, data, size, false, version);
118: }
119:
120: /**
121: * Full constructor with a CodeBase parameter useful for
122: * unmarshaling RMI-IIOP valuetypes (technically against the
123: * intention of an encapsulation, but necessary due to OMG
124: * issue 4795. Used by ServiceContexts.
125: */
126: public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data,
127: int size, GIOPVersion version, CodeBase codeBase) {
128: super (orb, ByteBuffer.wrap(data), size, false, version,
129: Message.CDR_ENC_VERSION, BufferManagerFactory
130: .newBufferManagerRead(
131: BufferManagerFactory.GROW,
132: Message.CDR_ENC_VERSION, (ORB) orb));
133:
134: this .codeBase = codeBase;
135:
136: performORBVersionSpecificInit();
137: }
138:
139: public CDRInputStream dup() {
140: return new EncapsInputStream(this );
141: }
142:
143: protected CodeSetConversion.BTCConverter createCharBTCConverter() {
144: return CodeSetConversion.impl().getBTCConverter(
145: OSFCodeSetRegistry.ISO_8859_1);
146: }
147:
148: protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
149: // Wide characters don't exist in GIOP 1.0
150: if (getGIOPVersion().equals(GIOPVersion.V1_0))
151: throw wrapper
152: .wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
153:
154: // In GIOP 1.1, we shouldn't have byte order markers. Take the order
155: // of the stream if we don't see them.
156: if (getGIOPVersion().equals(GIOPVersion.V1_1))
157: return CodeSetConversion.impl().getBTCConverter(
158: OSFCodeSetRegistry.UTF_16, isLittleEndian());
159:
160: // Assume anything else adheres to GIOP 1.2 requirements.
161: //
162: // Our UTF_16 converter will work with byte order markers, and if
163: // they aren't present, it will use the provided endianness.
164: //
165: // With no byte order marker, it's big endian in GIOP 1.2.
166: // formal 00-11-03 15.3.16.
167: return CodeSetConversion.impl().getBTCConverter(
168: OSFCodeSetRegistry.UTF_16, false);
169: }
170:
171: public CodeBase getCodeBase() {
172: return codeBase;
173: }
174:
175: private CodeBase codeBase;
176: }
|