Wed, 27 Apr 2016 01:21:28 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/corba/
changeset: 765:f46df0af2ca8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | package com.sun.corba.se.impl.encoding; |
aoqi@0 | 26 | |
aoqi@0 | 27 | import java.io.Serializable; |
aoqi@0 | 28 | import java.io.ObjectInputStream; |
aoqi@0 | 29 | import java.io.ByteArrayInputStream; |
aoqi@0 | 30 | import java.io.IOException; |
aoqi@0 | 31 | import java.nio.ByteBuffer; |
aoqi@0 | 32 | import java.math.BigDecimal; |
aoqi@0 | 33 | import java.util.LinkedList; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import com.sun.corba.se.spi.orb.ORB; |
aoqi@0 | 36 | import com.sun.corba.se.spi.ior.IOR; |
aoqi@0 | 37 | import com.sun.corba.se.spi.ior.IORFactories; |
aoqi@0 | 38 | import com.sun.corba.se.spi.ior.iiop.GIOPVersion; |
aoqi@0 | 39 | import com.sun.corba.se.spi.logging.CORBALogDomains; |
aoqi@0 | 40 | import com.sun.corba.se.spi.presentation.rmi.StubAdapter; |
aoqi@0 | 41 | import com.sun.corba.se.spi.presentation.rmi.PresentationManager; |
aoqi@0 | 42 | import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults; |
aoqi@0 | 43 | |
aoqi@0 | 44 | import com.sun.corba.se.impl.util.Utility; |
aoqi@0 | 45 | import com.sun.corba.se.impl.orbutil.ORBUtility; |
aoqi@0 | 46 | import com.sun.corba.se.impl.corba.TypeCodeImpl; |
aoqi@0 | 47 | import com.sun.corba.se.impl.util.RepositoryId; |
aoqi@0 | 48 | import com.sun.corba.se.impl.orbutil.ORBConstants; |
aoqi@0 | 49 | import com.sun.corba.se.impl.logging.ORBUtilSystemException; |
aoqi@0 | 50 | import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; |
aoqi@0 | 51 | |
aoqi@0 | 52 | import org.omg.CORBA.Any; |
aoqi@0 | 53 | import org.omg.CORBA.TypeCode; |
aoqi@0 | 54 | import org.omg.CORBA.Principal; |
aoqi@0 | 55 | import org.omg.CORBA.portable.IDLEntity; |
aoqi@0 | 56 | |
aoqi@0 | 57 | /** |
aoqi@0 | 58 | * Implementation class that uses Java serialization for input streams. |
aoqi@0 | 59 | * This assumes a GIOP version 1.2 message format. |
aoqi@0 | 60 | * |
aoqi@0 | 61 | * This class uses a ByteArrayInputStream as the underlying buffer. The |
aoqi@0 | 62 | * first 16 bytes are directly read out of the underlying buffer. This allows |
aoqi@0 | 63 | * [GIOPHeader (12 bytes) + requestID (4 bytes)] to be read as bytes. |
aoqi@0 | 64 | * Subsequent write operations on this output stream object uses |
aoqi@0 | 65 | * ObjectInputStream class to read into the buffer. This allows unmarshaling |
aoqi@0 | 66 | * complex types and graphs using the ObjectInputStream implementation. |
aoqi@0 | 67 | * |
aoqi@0 | 68 | * Note, this class assumes a GIOP 1.2 style header. Further, the first |
aoqi@0 | 69 | * 12 bytes, that is, the GIOPHeader is read directly from the received |
aoqi@0 | 70 | * message, before this stream object is called. So, this class effectively |
aoqi@0 | 71 | * reads only the requestID (4 bytes) directly, and uses the |
aoqi@0 | 72 | * ObjectInputStream for further unmarshaling. |
aoqi@0 | 73 | * |
aoqi@0 | 74 | * @author Ram Jeyaraman |
aoqi@0 | 75 | */ |
aoqi@0 | 76 | public class IDLJavaSerializationInputStream extends CDRInputStreamBase { |
aoqi@0 | 77 | |
aoqi@0 | 78 | private ORB orb; |
aoqi@0 | 79 | private int bufSize; |
aoqi@0 | 80 | private ByteBuffer buffer; |
aoqi@0 | 81 | private byte encodingVersion; |
aoqi@0 | 82 | private ObjectInputStream is; |
aoqi@0 | 83 | private _ByteArrayInputStream bis; |
aoqi@0 | 84 | private BufferManagerRead bufferManager; |
aoqi@0 | 85 | |
aoqi@0 | 86 | // [GIOPHeader(12) + requestID(4)] bytes |
aoqi@0 | 87 | private final int directReadLength = Message.GIOPMessageHeaderLength + 4; |
aoqi@0 | 88 | |
aoqi@0 | 89 | // Used for mark / reset operations. |
aoqi@0 | 90 | private boolean markOn; |
aoqi@0 | 91 | private int peekIndex, peekCount; |
aoqi@0 | 92 | private LinkedList markedItemQ = new LinkedList(); |
aoqi@0 | 93 | |
aoqi@0 | 94 | protected ORBUtilSystemException wrapper; |
aoqi@0 | 95 | |
aoqi@0 | 96 | class _ByteArrayInputStream extends ByteArrayInputStream { |
aoqi@0 | 97 | |
aoqi@0 | 98 | _ByteArrayInputStream(byte[] buf) { |
aoqi@0 | 99 | super(buf); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | |
aoqi@0 | 102 | int getPosition() { |
aoqi@0 | 103 | return this.pos; |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | void setPosition(int value) { |
aoqi@0 | 107 | if (value < 0 || value > count) { |
aoqi@0 | 108 | throw new IndexOutOfBoundsException(); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | this.pos = value; |
aoqi@0 | 111 | } |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | class MarshalObjectInputStream extends ObjectInputStream { |
aoqi@0 | 115 | |
aoqi@0 | 116 | ORB orb; |
aoqi@0 | 117 | |
aoqi@0 | 118 | MarshalObjectInputStream(java.io.InputStream out, ORB orb) |
aoqi@0 | 119 | throws IOException { |
aoqi@0 | 120 | |
aoqi@0 | 121 | super(out); |
aoqi@0 | 122 | this.orb = orb; |
aoqi@0 | 123 | |
aoqi@0 | 124 | java.security.AccessController.doPrivileged( |
aoqi@0 | 125 | new java.security.PrivilegedAction() { |
aoqi@0 | 126 | public Object run() { |
aoqi@0 | 127 | // needs SerializablePermission("enableSubstitution") |
aoqi@0 | 128 | enableResolveObject(true); |
aoqi@0 | 129 | return null; |
aoqi@0 | 130 | } |
aoqi@0 | 131 | } |
aoqi@0 | 132 | ); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | /** |
aoqi@0 | 136 | * Connect the Stub to the ORB. |
aoqi@0 | 137 | */ |
aoqi@0 | 138 | protected final Object resolveObject(Object obj) throws IOException { |
aoqi@0 | 139 | try { |
aoqi@0 | 140 | if (StubAdapter.isStub(obj)) { |
aoqi@0 | 141 | StubAdapter.connect(obj, orb); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | } catch (java.rmi.RemoteException re) { |
aoqi@0 | 144 | IOException ie = new IOException("resolveObject failed"); |
aoqi@0 | 145 | ie.initCause(re); |
aoqi@0 | 146 | throw ie; |
aoqi@0 | 147 | } |
aoqi@0 | 148 | return obj; |
aoqi@0 | 149 | } |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | public IDLJavaSerializationInputStream(byte encodingVersion) { |
aoqi@0 | 153 | super(); |
aoqi@0 | 154 | this.encodingVersion = encodingVersion; |
aoqi@0 | 155 | } |
aoqi@0 | 156 | |
aoqi@0 | 157 | public void init(org.omg.CORBA.ORB orb, |
aoqi@0 | 158 | ByteBuffer byteBuffer, |
aoqi@0 | 159 | int bufSize, |
aoqi@0 | 160 | boolean littleEndian, |
aoqi@0 | 161 | BufferManagerRead bufferManager) { |
aoqi@0 | 162 | this.orb = (ORB) orb; |
aoqi@0 | 163 | this.bufSize = bufSize; |
aoqi@0 | 164 | this.bufferManager = bufferManager; |
aoqi@0 | 165 | buffer = byteBuffer; |
aoqi@0 | 166 | wrapper = |
aoqi@0 | 167 | ORBUtilSystemException.get((ORB)orb, CORBALogDomains.RPC_ENCODING); |
aoqi@0 | 168 | |
aoqi@0 | 169 | byte[] buf; |
aoqi@0 | 170 | if (buffer.hasArray()) { |
aoqi@0 | 171 | buf = buffer.array(); |
aoqi@0 | 172 | } else { |
aoqi@0 | 173 | buf = new byte[bufSize]; |
aoqi@0 | 174 | buffer.get(buf); |
aoqi@0 | 175 | } |
aoqi@0 | 176 | // Note: at this point, the buffer position is zero. The setIndex() |
aoqi@0 | 177 | // method call can be used to set a desired read index. |
aoqi@0 | 178 | bis = new _ByteArrayInputStream(buf); |
aoqi@0 | 179 | } |
aoqi@0 | 180 | |
aoqi@0 | 181 | // Called from read_octet or read_long or read_ulong method. |
aoqi@0 | 182 | private void initObjectInputStream() { |
aoqi@0 | 183 | //System.out.print(" is "); |
aoqi@0 | 184 | if (is != null) { |
aoqi@0 | 185 | throw wrapper.javaStreamInitFailed(); |
aoqi@0 | 186 | } |
aoqi@0 | 187 | try { |
aoqi@0 | 188 | is = new MarshalObjectInputStream(bis, orb); |
aoqi@0 | 189 | } catch (Exception e) { |
aoqi@0 | 190 | throw wrapper.javaStreamInitFailed(e); |
aoqi@0 | 191 | } |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | // org.omg.CORBA.portable.InputStream |
aoqi@0 | 195 | |
aoqi@0 | 196 | // Primitive types. |
aoqi@0 | 197 | |
aoqi@0 | 198 | public boolean read_boolean() { |
aoqi@0 | 199 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 200 | return ((Boolean)markedItemQ.removeFirst()).booleanValue(); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 203 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 204 | return ((Boolean)markedItemQ.get(peekIndex++)).booleanValue(); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | try { |
aoqi@0 | 207 | boolean value = is.readBoolean(); |
aoqi@0 | 208 | if (markOn) { // enqueue |
aoqi@0 | 209 | markedItemQ.addLast(Boolean.valueOf(value)); |
aoqi@0 | 210 | } |
aoqi@0 | 211 | return value; |
aoqi@0 | 212 | } catch (Exception e) { |
aoqi@0 | 213 | throw wrapper.javaSerializationException(e, "read_boolean"); |
aoqi@0 | 214 | } |
aoqi@0 | 215 | } |
aoqi@0 | 216 | |
aoqi@0 | 217 | public char read_char() { |
aoqi@0 | 218 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 219 | return ((Character)markedItemQ.removeFirst()).charValue(); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 222 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 223 | return ((Character)markedItemQ.get(peekIndex++)).charValue(); |
aoqi@0 | 224 | } |
aoqi@0 | 225 | try { |
aoqi@0 | 226 | char value = is.readChar(); |
aoqi@0 | 227 | if (markOn) { // enqueue |
aoqi@0 | 228 | markedItemQ.addLast(new Character(value)); |
aoqi@0 | 229 | } |
aoqi@0 | 230 | return value; |
aoqi@0 | 231 | } catch (Exception e) { |
aoqi@0 | 232 | throw wrapper.javaSerializationException(e, "read_char"); |
aoqi@0 | 233 | } |
aoqi@0 | 234 | } |
aoqi@0 | 235 | |
aoqi@0 | 236 | public char read_wchar() { |
aoqi@0 | 237 | return this.read_char(); |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | public byte read_octet() { |
aoqi@0 | 241 | |
aoqi@0 | 242 | // check if size < [ GIOPHeader(12) + requestID(4)] bytes |
aoqi@0 | 243 | if (bis.getPosition() < directReadLength) { |
aoqi@0 | 244 | byte b = (byte) bis.read(); |
aoqi@0 | 245 | if (bis.getPosition() == directReadLength) { |
aoqi@0 | 246 | initObjectInputStream(); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | return b; |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 252 | return ((Byte)markedItemQ.removeFirst()).byteValue(); |
aoqi@0 | 253 | } |
aoqi@0 | 254 | |
aoqi@0 | 255 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 256 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 257 | return ((Byte)markedItemQ.get(peekIndex++)).byteValue(); |
aoqi@0 | 258 | } |
aoqi@0 | 259 | |
aoqi@0 | 260 | try { |
aoqi@0 | 261 | byte value = is.readByte(); |
aoqi@0 | 262 | if (markOn) { // enqueue |
aoqi@0 | 263 | //markedItemQ.addLast(Byte.valueOf(value)); // only in JDK 1.5 |
aoqi@0 | 264 | markedItemQ.addLast(new Byte(value)); |
aoqi@0 | 265 | } |
aoqi@0 | 266 | return value; |
aoqi@0 | 267 | } catch (Exception e) { |
aoqi@0 | 268 | throw wrapper.javaSerializationException(e, "read_octet"); |
aoqi@0 | 269 | } |
aoqi@0 | 270 | } |
aoqi@0 | 271 | |
aoqi@0 | 272 | public short read_short() { |
aoqi@0 | 273 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 274 | return ((Short)markedItemQ.removeFirst()).shortValue(); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 277 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 278 | return ((Short)markedItemQ.get(peekIndex++)).shortValue(); |
aoqi@0 | 279 | } |
aoqi@0 | 280 | |
aoqi@0 | 281 | try { |
aoqi@0 | 282 | short value = is.readShort(); |
aoqi@0 | 283 | if (markOn) { // enqueue |
aoqi@0 | 284 | markedItemQ.addLast(new Short(value)); |
aoqi@0 | 285 | } |
aoqi@0 | 286 | return value; |
aoqi@0 | 287 | } catch (Exception e) { |
aoqi@0 | 288 | throw wrapper.javaSerializationException(e, "read_short"); |
aoqi@0 | 289 | } |
aoqi@0 | 290 | } |
aoqi@0 | 291 | |
aoqi@0 | 292 | public short read_ushort() { |
aoqi@0 | 293 | return this.read_short(); |
aoqi@0 | 294 | } |
aoqi@0 | 295 | |
aoqi@0 | 296 | public int read_long() { |
aoqi@0 | 297 | |
aoqi@0 | 298 | // check if size < [ GIOPHeader(12) + requestID(4)] bytes |
aoqi@0 | 299 | if (bis.getPosition() < directReadLength) { |
aoqi@0 | 300 | |
aoqi@0 | 301 | // Use big endian (network byte order). This is fixed. |
aoqi@0 | 302 | // Both the writer and reader use the same byte order. |
aoqi@0 | 303 | int b1 = (bis.read() << 24) & 0xFF000000; |
aoqi@0 | 304 | int b2 = (bis.read() << 16) & 0x00FF0000; |
aoqi@0 | 305 | int b3 = (bis.read() << 8) & 0x0000FF00; |
aoqi@0 | 306 | int b4 = (bis.read() << 0) & 0x000000FF; |
aoqi@0 | 307 | |
aoqi@0 | 308 | if (bis.getPosition() == directReadLength) { |
aoqi@0 | 309 | initObjectInputStream(); |
aoqi@0 | 310 | } else if (bis.getPosition() > directReadLength) { |
aoqi@0 | 311 | // Cannot happen. All direct reads are contained |
aoqi@0 | 312 | // within the first 16 bytes. |
aoqi@0 | 313 | wrapper.javaSerializationException("read_long"); |
aoqi@0 | 314 | } |
aoqi@0 | 315 | |
aoqi@0 | 316 | return (b1 | b2 | b3 | b4); |
aoqi@0 | 317 | } |
aoqi@0 | 318 | |
aoqi@0 | 319 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 320 | return ((Integer)markedItemQ.removeFirst()).intValue(); |
aoqi@0 | 321 | } |
aoqi@0 | 322 | |
aoqi@0 | 323 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 324 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 325 | return ((Integer)markedItemQ.get(peekIndex++)).intValue(); |
aoqi@0 | 326 | } |
aoqi@0 | 327 | |
aoqi@0 | 328 | try { |
aoqi@0 | 329 | int value = is.readInt(); |
aoqi@0 | 330 | if (markOn) { // enqueue |
aoqi@0 | 331 | markedItemQ.addLast(new Integer(value)); |
aoqi@0 | 332 | } |
aoqi@0 | 333 | return value; |
aoqi@0 | 334 | } catch (Exception e) { |
aoqi@0 | 335 | throw wrapper.javaSerializationException(e, "read_long"); |
aoqi@0 | 336 | } |
aoqi@0 | 337 | } |
aoqi@0 | 338 | |
aoqi@0 | 339 | public int read_ulong() { |
aoqi@0 | 340 | return this.read_long(); |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | public long read_longlong() { |
aoqi@0 | 344 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 345 | return ((Long)markedItemQ.removeFirst()).longValue(); |
aoqi@0 | 346 | } |
aoqi@0 | 347 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 348 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 349 | return ((Long)markedItemQ.get(peekIndex++)).longValue(); |
aoqi@0 | 350 | } |
aoqi@0 | 351 | |
aoqi@0 | 352 | try { |
aoqi@0 | 353 | long value = is.readLong(); |
aoqi@0 | 354 | if (markOn) { // enqueue |
aoqi@0 | 355 | markedItemQ.addLast(new Long(value)); |
aoqi@0 | 356 | } |
aoqi@0 | 357 | return value; |
aoqi@0 | 358 | } catch (Exception e) { |
aoqi@0 | 359 | throw wrapper.javaSerializationException(e, "read_longlong"); |
aoqi@0 | 360 | } |
aoqi@0 | 361 | } |
aoqi@0 | 362 | |
aoqi@0 | 363 | public long read_ulonglong() { |
aoqi@0 | 364 | return read_longlong(); |
aoqi@0 | 365 | } |
aoqi@0 | 366 | |
aoqi@0 | 367 | public float read_float() { |
aoqi@0 | 368 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 369 | return ((Float)markedItemQ.removeFirst()).floatValue(); |
aoqi@0 | 370 | } |
aoqi@0 | 371 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 372 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 373 | return ((Float)markedItemQ.get(peekIndex++)).floatValue(); |
aoqi@0 | 374 | } |
aoqi@0 | 375 | |
aoqi@0 | 376 | try { |
aoqi@0 | 377 | float value = is.readFloat(); |
aoqi@0 | 378 | if (markOn) { // enqueue |
aoqi@0 | 379 | markedItemQ.addLast(new Float(value)); |
aoqi@0 | 380 | } |
aoqi@0 | 381 | return value; |
aoqi@0 | 382 | } catch (Exception e) { |
aoqi@0 | 383 | throw wrapper.javaSerializationException(e, "read_float"); |
aoqi@0 | 384 | } |
aoqi@0 | 385 | } |
aoqi@0 | 386 | |
aoqi@0 | 387 | public double read_double() { |
aoqi@0 | 388 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 389 | return ((Double)markedItemQ.removeFirst()).doubleValue(); |
aoqi@0 | 390 | } |
aoqi@0 | 391 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 392 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 393 | return ((Double)markedItemQ.get(peekIndex++)).doubleValue(); |
aoqi@0 | 394 | } |
aoqi@0 | 395 | |
aoqi@0 | 396 | try { |
aoqi@0 | 397 | double value = is.readDouble(); |
aoqi@0 | 398 | if (markOn) { // enqueue |
aoqi@0 | 399 | markedItemQ.addLast(new Double(value)); |
aoqi@0 | 400 | } |
aoqi@0 | 401 | return value; |
aoqi@0 | 402 | } catch (Exception e) { |
aoqi@0 | 403 | throw wrapper.javaSerializationException(e, "read_double"); |
aoqi@0 | 404 | } |
aoqi@0 | 405 | } |
aoqi@0 | 406 | |
aoqi@0 | 407 | // String types. |
aoqi@0 | 408 | |
aoqi@0 | 409 | public String read_string() { |
aoqi@0 | 410 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 411 | return (String) markedItemQ.removeFirst(); |
aoqi@0 | 412 | } |
aoqi@0 | 413 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 414 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 415 | return (String) markedItemQ.get(peekIndex++); |
aoqi@0 | 416 | } |
aoqi@0 | 417 | try { |
aoqi@0 | 418 | String value = is.readUTF(); |
aoqi@0 | 419 | if (markOn) { // enqueue |
aoqi@0 | 420 | markedItemQ.addLast(value); |
aoqi@0 | 421 | } |
aoqi@0 | 422 | return value; |
aoqi@0 | 423 | } catch (Exception e) { |
aoqi@0 | 424 | throw wrapper.javaSerializationException(e, "read_string"); |
aoqi@0 | 425 | } |
aoqi@0 | 426 | } |
aoqi@0 | 427 | |
aoqi@0 | 428 | public String read_wstring() { |
aoqi@0 | 429 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 430 | return (String) markedItemQ.removeFirst(); |
aoqi@0 | 431 | } |
aoqi@0 | 432 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 433 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 434 | return (String) markedItemQ.get(peekIndex++); |
aoqi@0 | 435 | } |
aoqi@0 | 436 | try { |
aoqi@0 | 437 | String value = (String) is.readObject(); |
aoqi@0 | 438 | if (markOn) { // enqueue |
aoqi@0 | 439 | markedItemQ.addLast(value); |
aoqi@0 | 440 | } |
aoqi@0 | 441 | return value; |
aoqi@0 | 442 | } catch (Exception e) { |
aoqi@0 | 443 | throw wrapper.javaSerializationException(e, "read_wstring"); |
aoqi@0 | 444 | } |
aoqi@0 | 445 | } |
aoqi@0 | 446 | |
aoqi@0 | 447 | // Array types. |
aoqi@0 | 448 | |
aoqi@0 | 449 | public void read_boolean_array(boolean[] value, int offset, int length){ |
aoqi@0 | 450 | for(int i = 0; i < length; i++) { |
aoqi@0 | 451 | value[i+offset] = read_boolean(); |
aoqi@0 | 452 | } |
aoqi@0 | 453 | } |
aoqi@0 | 454 | |
aoqi@0 | 455 | public void read_char_array(char[] value, int offset, int length) { |
aoqi@0 | 456 | for(int i=0; i < length; i++) { |
aoqi@0 | 457 | value[i+offset] = read_char(); |
aoqi@0 | 458 | } |
aoqi@0 | 459 | } |
aoqi@0 | 460 | |
aoqi@0 | 461 | public void read_wchar_array(char[] value, int offset, int length) { |
aoqi@0 | 462 | read_char_array(value, offset, length); |
aoqi@0 | 463 | } |
aoqi@0 | 464 | |
aoqi@0 | 465 | public void read_octet_array(byte[] value, int offset, int length) { |
aoqi@0 | 466 | for(int i=0; i < length; i++) { |
aoqi@0 | 467 | value[i+offset] = read_octet(); |
aoqi@0 | 468 | } |
aoqi@0 | 469 | /* // Cannot use this efficient read due to mark/reset support. |
aoqi@0 | 470 | try { |
aoqi@0 | 471 | while (length > 0) { |
aoqi@0 | 472 | int n = is.read(value, offset, length); |
aoqi@0 | 473 | offset += n; |
aoqi@0 | 474 | length -= n; |
aoqi@0 | 475 | } |
aoqi@0 | 476 | } catch (Exception e) { |
aoqi@0 | 477 | throw wrapper.javaSerializationException(e, "read_octet_array"); |
aoqi@0 | 478 | } |
aoqi@0 | 479 | */ |
aoqi@0 | 480 | } |
aoqi@0 | 481 | |
aoqi@0 | 482 | public void read_short_array(short[] value, int offset, int length) { |
aoqi@0 | 483 | for(int i=0; i < length; i++) { |
aoqi@0 | 484 | value[i+offset] = read_short(); |
aoqi@0 | 485 | } |
aoqi@0 | 486 | } |
aoqi@0 | 487 | |
aoqi@0 | 488 | public void read_ushort_array(short[] value, int offset, int length) { |
aoqi@0 | 489 | read_short_array(value, offset, length); |
aoqi@0 | 490 | } |
aoqi@0 | 491 | |
aoqi@0 | 492 | public void read_long_array(int[] value, int offset, int length) { |
aoqi@0 | 493 | for(int i=0; i < length; i++) { |
aoqi@0 | 494 | value[i+offset] = read_long(); |
aoqi@0 | 495 | } |
aoqi@0 | 496 | } |
aoqi@0 | 497 | |
aoqi@0 | 498 | public void read_ulong_array(int[] value, int offset, int length) { |
aoqi@0 | 499 | read_long_array(value, offset, length); |
aoqi@0 | 500 | } |
aoqi@0 | 501 | |
aoqi@0 | 502 | public void read_longlong_array(long[] value, int offset, int length) { |
aoqi@0 | 503 | for(int i=0; i < length; i++) { |
aoqi@0 | 504 | value[i+offset] = read_longlong(); |
aoqi@0 | 505 | } |
aoqi@0 | 506 | } |
aoqi@0 | 507 | |
aoqi@0 | 508 | public void read_ulonglong_array(long[] value, int offset, int length) { |
aoqi@0 | 509 | read_longlong_array(value, offset, length); |
aoqi@0 | 510 | } |
aoqi@0 | 511 | |
aoqi@0 | 512 | public void read_float_array(float[] value, int offset, int length) { |
aoqi@0 | 513 | for(int i=0; i < length; i++) { |
aoqi@0 | 514 | value[i+offset] = read_float(); |
aoqi@0 | 515 | } |
aoqi@0 | 516 | } |
aoqi@0 | 517 | |
aoqi@0 | 518 | public void read_double_array(double[] value, int offset, int length) { |
aoqi@0 | 519 | for(int i=0; i < length; i++) { |
aoqi@0 | 520 | value[i+offset] = read_double(); |
aoqi@0 | 521 | } |
aoqi@0 | 522 | } |
aoqi@0 | 523 | |
aoqi@0 | 524 | // Complex types. |
aoqi@0 | 525 | |
aoqi@0 | 526 | public org.omg.CORBA.Object read_Object() { |
aoqi@0 | 527 | return read_Object(null); |
aoqi@0 | 528 | } |
aoqi@0 | 529 | |
aoqi@0 | 530 | public TypeCode read_TypeCode() { |
aoqi@0 | 531 | TypeCodeImpl tc = new TypeCodeImpl(orb); |
aoqi@0 | 532 | tc.read_value(parent); |
aoqi@0 | 533 | return tc; |
aoqi@0 | 534 | } |
aoqi@0 | 535 | |
aoqi@0 | 536 | public Any read_any() { |
aoqi@0 | 537 | |
aoqi@0 | 538 | Any any = orb.create_any(); |
aoqi@0 | 539 | TypeCodeImpl tc = new TypeCodeImpl(orb); |
aoqi@0 | 540 | |
aoqi@0 | 541 | // read off the typecode |
aoqi@0 | 542 | |
aoqi@0 | 543 | // REVISIT We could avoid this try-catch if we could peek the typecode |
aoqi@0 | 544 | // kind off this stream and see if it is a tk_value. |
aoqi@0 | 545 | // Looking at the code we know that for tk_value the Any.read_value() |
aoqi@0 | 546 | // below ignores the tc argument anyway (except for the kind field). |
aoqi@0 | 547 | // But still we would need to make sure that the whole typecode, |
aoqi@0 | 548 | // including encapsulations, is read off. |
aoqi@0 | 549 | try { |
aoqi@0 | 550 | tc.read_value(parent); |
aoqi@0 | 551 | } catch (org.omg.CORBA.MARSHAL ex) { |
aoqi@0 | 552 | if (tc.kind().value() != org.omg.CORBA.TCKind._tk_value) { |
aoqi@0 | 553 | throw ex; |
aoqi@0 | 554 | } |
aoqi@0 | 555 | // We can be sure that the whole typecode encapsulation has been |
aoqi@0 | 556 | // read off. |
aoqi@0 | 557 | ex.printStackTrace(); |
aoqi@0 | 558 | } |
aoqi@0 | 559 | |
aoqi@0 | 560 | // read off the value of the any. |
aoqi@0 | 561 | any.read_value(parent, tc); |
aoqi@0 | 562 | |
aoqi@0 | 563 | return any; |
aoqi@0 | 564 | } |
aoqi@0 | 565 | |
aoqi@0 | 566 | public Principal read_Principal() { |
aoqi@0 | 567 | // We don't need an implementation for this method, since principal |
aoqi@0 | 568 | // is absent in GIOP version 1.2 or above. |
aoqi@0 | 569 | int len = read_long(); |
aoqi@0 | 570 | byte[] pvalue = new byte[len]; |
aoqi@0 | 571 | read_octet_array(pvalue,0,len); |
aoqi@0 | 572 | Principal p = new com.sun.corba.se.impl.corba.PrincipalImpl(); |
aoqi@0 | 573 | p.name(pvalue); |
aoqi@0 | 574 | return p; |
aoqi@0 | 575 | } |
aoqi@0 | 576 | |
aoqi@0 | 577 | public BigDecimal read_fixed() { |
aoqi@0 | 578 | return new BigDecimal(read_fixed_buffer().toString()); |
aoqi@0 | 579 | } |
aoqi@0 | 580 | |
aoqi@0 | 581 | // Each octet contains (up to) two decimal digits. If the fixed type has |
aoqi@0 | 582 | // an odd number of decimal digits, then the representation |
aoqi@0 | 583 | // begins with the first (most significant) digit. |
aoqi@0 | 584 | // Otherwise, this first half-octet is all zero, and the first digit |
aoqi@0 | 585 | // is in the second half-octet. |
aoqi@0 | 586 | // The sign configuration, in the last half-octet of the representation, |
aoqi@0 | 587 | // is 0xD for negative numbers and 0xC for positive and zero values. |
aoqi@0 | 588 | private StringBuffer read_fixed_buffer() { |
aoqi@0 | 589 | StringBuffer buffer = new StringBuffer(64); |
aoqi@0 | 590 | byte doubleDigit; |
aoqi@0 | 591 | int firstDigit; |
aoqi@0 | 592 | int secondDigit; |
aoqi@0 | 593 | boolean wroteFirstDigit = false; |
aoqi@0 | 594 | boolean more = true; |
aoqi@0 | 595 | while (more) { |
aoqi@0 | 596 | doubleDigit = read_octet(); |
aoqi@0 | 597 | firstDigit = (int)((doubleDigit & 0xf0) >> 4); |
aoqi@0 | 598 | secondDigit = (int)(doubleDigit & 0x0f); |
aoqi@0 | 599 | if (wroteFirstDigit || firstDigit != 0) { |
aoqi@0 | 600 | buffer.append(Character.forDigit(firstDigit, 10)); |
aoqi@0 | 601 | wroteFirstDigit = true; |
aoqi@0 | 602 | } |
aoqi@0 | 603 | if (secondDigit == 12) { |
aoqi@0 | 604 | // positive number or zero |
aoqi@0 | 605 | if ( ! wroteFirstDigit) { |
aoqi@0 | 606 | // zero |
aoqi@0 | 607 | return new StringBuffer("0.0"); |
aoqi@0 | 608 | } else { |
aoqi@0 | 609 | // positive number |
aoqi@0 | 610 | // done |
aoqi@0 | 611 | } |
aoqi@0 | 612 | more = false; |
aoqi@0 | 613 | } else if (secondDigit == 13) { |
aoqi@0 | 614 | // negative number |
aoqi@0 | 615 | buffer.insert(0, '-'); |
aoqi@0 | 616 | more = false; |
aoqi@0 | 617 | } else { |
aoqi@0 | 618 | buffer.append(Character.forDigit(secondDigit, 10)); |
aoqi@0 | 619 | wroteFirstDigit = true; |
aoqi@0 | 620 | } |
aoqi@0 | 621 | } |
aoqi@0 | 622 | return buffer; |
aoqi@0 | 623 | } |
aoqi@0 | 624 | |
aoqi@0 | 625 | public org.omg.CORBA.Object read_Object(java.lang.Class clz) { |
aoqi@0 | 626 | |
aoqi@0 | 627 | // In any case, we must first read the IOR. |
aoqi@0 | 628 | IOR ior = IORFactories.makeIOR(parent) ; |
aoqi@0 | 629 | if (ior.isNil()) { |
aoqi@0 | 630 | return null; |
aoqi@0 | 631 | } |
aoqi@0 | 632 | |
aoqi@0 | 633 | PresentationManager.StubFactoryFactory sff = |
aoqi@0 | 634 | ORB.getStubFactoryFactory(); |
aoqi@0 | 635 | String codeBase = ior.getProfile().getCodebase(); |
aoqi@0 | 636 | PresentationManager.StubFactory stubFactory = null; |
aoqi@0 | 637 | |
aoqi@0 | 638 | if (clz == null) { |
aoqi@0 | 639 | RepositoryId rid = RepositoryId.cache.getId(ior.getTypeId() ); |
aoqi@0 | 640 | String className = rid.getClassName(); |
aoqi@0 | 641 | boolean isIDLInterface = rid.isIDLType(); |
aoqi@0 | 642 | |
aoqi@0 | 643 | if (className == null || className.equals( "" )) { |
aoqi@0 | 644 | stubFactory = null; |
aoqi@0 | 645 | } else { |
aoqi@0 | 646 | try { |
aoqi@0 | 647 | stubFactory = sff.createStubFactory(className, |
aoqi@0 | 648 | isIDLInterface, codeBase, (Class) null, |
aoqi@0 | 649 | (ClassLoader) null); |
aoqi@0 | 650 | } catch (Exception exc) { |
aoqi@0 | 651 | // Could not create stubFactory, so use null. |
aoqi@0 | 652 | // XXX stubFactory handling is still too complex: |
aoqi@0 | 653 | // Can we resolve the stubFactory question once in |
aoqi@0 | 654 | // a single place? |
aoqi@0 | 655 | stubFactory = null ; |
aoqi@0 | 656 | } |
aoqi@0 | 657 | } |
aoqi@0 | 658 | } else if (StubAdapter.isStubClass(clz)) { |
aoqi@0 | 659 | stubFactory = PresentationDefaults.makeStaticStubFactory(clz); |
aoqi@0 | 660 | } else { |
aoqi@0 | 661 | // clz is an interface class |
aoqi@0 | 662 | boolean isIDL = IDLEntity.class.isAssignableFrom(clz); |
aoqi@0 | 663 | |
aoqi@0 | 664 | stubFactory = sff.createStubFactory( |
aoqi@0 | 665 | clz.getName(), isIDL, codeBase, clz, clz.getClassLoader()); |
aoqi@0 | 666 | } |
aoqi@0 | 667 | |
aoqi@0 | 668 | return CDRInputStream_1_0.internalIORToObject(ior, stubFactory, orb); |
aoqi@0 | 669 | } |
aoqi@0 | 670 | |
aoqi@0 | 671 | public org.omg.CORBA.ORB orb() { |
aoqi@0 | 672 | return this.orb; |
aoqi@0 | 673 | } |
aoqi@0 | 674 | |
aoqi@0 | 675 | // org.omg.CORBA_2_3.portable.InputStream |
aoqi@0 | 676 | |
aoqi@0 | 677 | public java.io.Serializable read_value() { |
aoqi@0 | 678 | if (!markOn && !(markedItemQ.isEmpty())) { // dequeue |
aoqi@0 | 679 | return (Serializable) markedItemQ.removeFirst(); |
aoqi@0 | 680 | } |
aoqi@0 | 681 | if (markOn && !(markedItemQ.isEmpty()) && |
aoqi@0 | 682 | (peekIndex < peekCount)) { // peek |
aoqi@0 | 683 | return (Serializable) markedItemQ.get(peekIndex++); |
aoqi@0 | 684 | } |
aoqi@0 | 685 | try { |
aoqi@0 | 686 | Serializable value = (java.io.Serializable) is.readObject(); |
aoqi@0 | 687 | if (markOn) { // enqueue |
aoqi@0 | 688 | markedItemQ.addLast(value); |
aoqi@0 | 689 | } |
aoqi@0 | 690 | return value; |
aoqi@0 | 691 | } catch (Exception e) { |
aoqi@0 | 692 | throw wrapper.javaSerializationException(e, "read_value"); |
aoqi@0 | 693 | } |
aoqi@0 | 694 | } |
aoqi@0 | 695 | |
aoqi@0 | 696 | public java.io.Serializable read_value(java.lang.Class clz) { |
aoqi@0 | 697 | return read_value(); |
aoqi@0 | 698 | } |
aoqi@0 | 699 | |
aoqi@0 | 700 | public java.io.Serializable read_value( |
aoqi@0 | 701 | org.omg.CORBA.portable.BoxedValueHelper factory) { |
aoqi@0 | 702 | return read_value(); |
aoqi@0 | 703 | } |
aoqi@0 | 704 | |
aoqi@0 | 705 | public java.io.Serializable read_value(java.lang.String rep_id) { |
aoqi@0 | 706 | return read_value(); |
aoqi@0 | 707 | } |
aoqi@0 | 708 | |
aoqi@0 | 709 | public java.io.Serializable read_value(java.io.Serializable value) { |
aoqi@0 | 710 | return read_value(); |
aoqi@0 | 711 | } |
aoqi@0 | 712 | |
aoqi@0 | 713 | public java.lang.Object read_abstract_interface() { |
aoqi@0 | 714 | return read_abstract_interface(null); |
aoqi@0 | 715 | } |
aoqi@0 | 716 | |
aoqi@0 | 717 | public java.lang.Object read_abstract_interface(java.lang.Class clz) { |
aoqi@0 | 718 | boolean isObject = read_boolean(); |
aoqi@0 | 719 | if (isObject) { |
aoqi@0 | 720 | return read_Object(clz); |
aoqi@0 | 721 | } else { |
aoqi@0 | 722 | return read_value(); |
aoqi@0 | 723 | } |
aoqi@0 | 724 | } |
aoqi@0 | 725 | |
aoqi@0 | 726 | // com.sun.corba.se.impl.encoding.MarshalInputStream |
aoqi@0 | 727 | public void consumeEndian() { |
aoqi@0 | 728 | throw wrapper.giopVersionError(); |
aoqi@0 | 729 | } |
aoqi@0 | 730 | |
aoqi@0 | 731 | public int getPosition() { |
aoqi@0 | 732 | try { |
aoqi@0 | 733 | return bis.getPosition(); |
aoqi@0 | 734 | } catch (Exception e) { |
aoqi@0 | 735 | throw wrapper.javaSerializationException(e, "getPosition"); |
aoqi@0 | 736 | } |
aoqi@0 | 737 | } |
aoqi@0 | 738 | |
aoqi@0 | 739 | // org.omg.CORBA.DataInputStream |
aoqi@0 | 740 | public java.lang.Object read_Abstract() { |
aoqi@0 | 741 | return read_abstract_interface(); |
aoqi@0 | 742 | } |
aoqi@0 | 743 | |
aoqi@0 | 744 | public java.io.Serializable read_Value() { |
aoqi@0 | 745 | return read_value(); |
aoqi@0 | 746 | } |
aoqi@0 | 747 | |
aoqi@0 | 748 | public void read_any_array (org.omg.CORBA.AnySeqHolder seq, |
aoqi@0 | 749 | int offset, int length) { |
aoqi@0 | 750 | read_any_array(seq.value, offset, length); |
aoqi@0 | 751 | } |
aoqi@0 | 752 | |
aoqi@0 | 753 | private final void read_any_array(org.omg.CORBA.Any[] value, |
aoqi@0 | 754 | int offset, int length) { |
aoqi@0 | 755 | for(int i=0; i < length; i++) { |
aoqi@0 | 756 | value[i+offset] = read_any(); |
aoqi@0 | 757 | } |
aoqi@0 | 758 | } |
aoqi@0 | 759 | |
aoqi@0 | 760 | public void read_boolean_array (org.omg.CORBA.BooleanSeqHolder seq, |
aoqi@0 | 761 | int offset, int length){ |
aoqi@0 | 762 | read_boolean_array(seq.value, offset, length); |
aoqi@0 | 763 | } |
aoqi@0 | 764 | |
aoqi@0 | 765 | public void read_char_array (org.omg.CORBA.CharSeqHolder seq, |
aoqi@0 | 766 | int offset, int length){ |
aoqi@0 | 767 | read_char_array(seq.value, offset, length); |
aoqi@0 | 768 | } |
aoqi@0 | 769 | |
aoqi@0 | 770 | public void read_wchar_array (org.omg.CORBA.WCharSeqHolder seq, |
aoqi@0 | 771 | int offset, int length){ |
aoqi@0 | 772 | read_wchar_array(seq.value, offset, length); |
aoqi@0 | 773 | } |
aoqi@0 | 774 | |
aoqi@0 | 775 | public void read_octet_array (org.omg.CORBA.OctetSeqHolder seq, |
aoqi@0 | 776 | int offset, int length){ |
aoqi@0 | 777 | read_octet_array(seq.value, offset, length); |
aoqi@0 | 778 | } |
aoqi@0 | 779 | |
aoqi@0 | 780 | public void read_short_array (org.omg.CORBA.ShortSeqHolder seq, |
aoqi@0 | 781 | int offset, int length){ |
aoqi@0 | 782 | read_short_array(seq.value, offset, length); |
aoqi@0 | 783 | } |
aoqi@0 | 784 | |
aoqi@0 | 785 | public void read_ushort_array (org.omg.CORBA.UShortSeqHolder seq, |
aoqi@0 | 786 | int offset, int length){ |
aoqi@0 | 787 | read_ushort_array(seq.value, offset, length); |
aoqi@0 | 788 | } |
aoqi@0 | 789 | |
aoqi@0 | 790 | public void read_long_array (org.omg.CORBA.LongSeqHolder seq, |
aoqi@0 | 791 | int offset, int length){ |
aoqi@0 | 792 | read_long_array(seq.value, offset, length); |
aoqi@0 | 793 | } |
aoqi@0 | 794 | |
aoqi@0 | 795 | public void read_ulong_array (org.omg.CORBA.ULongSeqHolder seq, |
aoqi@0 | 796 | int offset, int length){ |
aoqi@0 | 797 | read_ulong_array(seq.value, offset, length); |
aoqi@0 | 798 | } |
aoqi@0 | 799 | |
aoqi@0 | 800 | public void read_ulonglong_array (org.omg.CORBA.ULongLongSeqHolder seq, |
aoqi@0 | 801 | int offset, int length){ |
aoqi@0 | 802 | read_ulonglong_array(seq.value, offset, length); |
aoqi@0 | 803 | } |
aoqi@0 | 804 | |
aoqi@0 | 805 | public void read_longlong_array (org.omg.CORBA.LongLongSeqHolder seq, |
aoqi@0 | 806 | int offset, int length){ |
aoqi@0 | 807 | read_longlong_array(seq.value, offset, length); |
aoqi@0 | 808 | } |
aoqi@0 | 809 | |
aoqi@0 | 810 | public void read_float_array (org.omg.CORBA.FloatSeqHolder seq, |
aoqi@0 | 811 | int offset, int length){ |
aoqi@0 | 812 | read_float_array(seq.value, offset, length); |
aoqi@0 | 813 | } |
aoqi@0 | 814 | |
aoqi@0 | 815 | public void read_double_array (org.omg.CORBA.DoubleSeqHolder seq, |
aoqi@0 | 816 | int offset, int length){ |
aoqi@0 | 817 | read_double_array(seq.value, offset, length); |
aoqi@0 | 818 | } |
aoqi@0 | 819 | |
aoqi@0 | 820 | // org.omg.CORBA.portable.ValueBase |
aoqi@0 | 821 | |
aoqi@0 | 822 | public String[] _truncatable_ids() { |
aoqi@0 | 823 | throw wrapper.giopVersionError(); |
aoqi@0 | 824 | } |
aoqi@0 | 825 | |
aoqi@0 | 826 | // java.io.InputStream |
aoqi@0 | 827 | // REVISIT - should we make these throw UnsupportedOperationExceptions? |
aoqi@0 | 828 | // Right now, they'll go up to the java.io versions! |
aoqi@0 | 829 | |
aoqi@0 | 830 | // public int read(byte b[]) throws IOException; |
aoqi@0 | 831 | // public int read(byte b[], int off, int len) throws IOException |
aoqi@0 | 832 | // public long skip(long n) throws IOException; |
aoqi@0 | 833 | // public int available() throws IOException; |
aoqi@0 | 834 | // public void close() throws IOException; |
aoqi@0 | 835 | |
aoqi@0 | 836 | public void mark(int readLimit) { |
aoqi@0 | 837 | // Nested mark disallowed. |
aoqi@0 | 838 | // Further, mark is not supported until first 16 bytes are read. |
aoqi@0 | 839 | if (markOn || is == null) { |
aoqi@0 | 840 | throw wrapper.javaSerializationException("mark"); |
aoqi@0 | 841 | } |
aoqi@0 | 842 | markOn = true; |
aoqi@0 | 843 | if (!(markedItemQ.isEmpty())) { |
aoqi@0 | 844 | peekIndex = 0; |
aoqi@0 | 845 | peekCount = markedItemQ.size(); |
aoqi@0 | 846 | } |
aoqi@0 | 847 | /* |
aoqi@0 | 848 | // Note: only ByteArrayInputStream supports mark/reset. |
aoqi@0 | 849 | if (is == null || is.markSupported() == false) { |
aoqi@0 | 850 | throw wrapper.javaSerializationException("mark"); |
aoqi@0 | 851 | } |
aoqi@0 | 852 | is.mark(readLimit); |
aoqi@0 | 853 | */ |
aoqi@0 | 854 | } |
aoqi@0 | 855 | |
aoqi@0 | 856 | public void reset() { |
aoqi@0 | 857 | markOn = false; |
aoqi@0 | 858 | peekIndex = 0; |
aoqi@0 | 859 | peekCount = 0; |
aoqi@0 | 860 | /* |
aoqi@0 | 861 | // Note: only ByteArrayInputStream supports mark/reset. |
aoqi@0 | 862 | if (is == null || is.markSupported() == false) { |
aoqi@0 | 863 | throw wrapper.javaSerializationException("mark"); |
aoqi@0 | 864 | } |
aoqi@0 | 865 | try { |
aoqi@0 | 866 | is.reset(); |
aoqi@0 | 867 | } catch (Exception e) { |
aoqi@0 | 868 | throw wrapper.javaSerializationException(e, "reset"); |
aoqi@0 | 869 | } |
aoqi@0 | 870 | */ |
aoqi@0 | 871 | } |
aoqi@0 | 872 | |
aoqi@0 | 873 | // This should return false so that outside users (people using the JDK) |
aoqi@0 | 874 | // don't have any guarantees that mark/reset will work in their |
aoqi@0 | 875 | // custom marshaling code. This is necessary since they could do things |
aoqi@0 | 876 | // like expect obj1a == obj1b in the following code: |
aoqi@0 | 877 | // |
aoqi@0 | 878 | // is.mark(10000); |
aoqi@0 | 879 | // Object obj1a = is.readObject(); |
aoqi@0 | 880 | // is.reset(); |
aoqi@0 | 881 | // Object obj1b = is.readObject(); |
aoqi@0 | 882 | // |
aoqi@0 | 883 | public boolean markSupported() { |
aoqi@0 | 884 | return true; |
aoqi@0 | 885 | } |
aoqi@0 | 886 | |
aoqi@0 | 887 | // Needed by AnyImpl and ServiceContexts |
aoqi@0 | 888 | public CDRInputStreamBase dup() { |
aoqi@0 | 889 | |
aoqi@0 | 890 | CDRInputStreamBase result = null ; |
aoqi@0 | 891 | |
aoqi@0 | 892 | try { |
aoqi@0 | 893 | result = (CDRInputStreamBase) this.getClass().newInstance(); |
aoqi@0 | 894 | } catch (Exception e) { |
aoqi@0 | 895 | throw wrapper.couldNotDuplicateCdrInputStream(e); |
aoqi@0 | 896 | } |
aoqi@0 | 897 | |
aoqi@0 | 898 | result.init(this.orb, this.buffer, this.bufSize, false, null); |
aoqi@0 | 899 | |
aoqi@0 | 900 | // Set the buffer position. |
aoqi@0 | 901 | ((IDLJavaSerializationInputStream)result).skipBytes(getPosition()); |
aoqi@0 | 902 | |
aoqi@0 | 903 | // Set mark related data. |
aoqi@0 | 904 | ((IDLJavaSerializationInputStream)result). |
aoqi@0 | 905 | setMarkData(markOn, peekIndex, peekCount, |
aoqi@0 | 906 | (LinkedList) markedItemQ.clone()); |
aoqi@0 | 907 | |
aoqi@0 | 908 | return result; |
aoqi@0 | 909 | } |
aoqi@0 | 910 | |
aoqi@0 | 911 | // Used exclusively by the dup() method. |
aoqi@0 | 912 | void skipBytes(int len) { |
aoqi@0 | 913 | try { |
aoqi@0 | 914 | is.skipBytes(len); |
aoqi@0 | 915 | } catch (Exception e) { |
aoqi@0 | 916 | throw wrapper.javaSerializationException(e, "skipBytes"); |
aoqi@0 | 917 | } |
aoqi@0 | 918 | } |
aoqi@0 | 919 | |
aoqi@0 | 920 | // Used exclusively by the dup() method. |
aoqi@0 | 921 | void setMarkData(boolean markOn, int peekIndex, int peekCount, |
aoqi@0 | 922 | LinkedList markedItemQ) { |
aoqi@0 | 923 | this.markOn = markOn; |
aoqi@0 | 924 | this.peekIndex = peekIndex; |
aoqi@0 | 925 | this.peekCount = peekCount; |
aoqi@0 | 926 | this.markedItemQ = markedItemQ; |
aoqi@0 | 927 | } |
aoqi@0 | 928 | |
aoqi@0 | 929 | // Needed by TCUtility |
aoqi@0 | 930 | public java.math.BigDecimal read_fixed(short digits, short scale) { |
aoqi@0 | 931 | // digits isn't really needed here |
aoqi@0 | 932 | StringBuffer buffer = read_fixed_buffer(); |
aoqi@0 | 933 | if (digits != buffer.length()) |
aoqi@0 | 934 | throw wrapper.badFixed( new Integer(digits), |
aoqi@0 | 935 | new Integer(buffer.length()) ) ; |
aoqi@0 | 936 | buffer.insert(digits - scale, '.'); |
aoqi@0 | 937 | return new BigDecimal(buffer.toString()); |
aoqi@0 | 938 | } |
aoqi@0 | 939 | |
aoqi@0 | 940 | // Needed by TypeCodeImpl |
aoqi@0 | 941 | public boolean isLittleEndian() { |
aoqi@0 | 942 | throw wrapper.giopVersionError(); |
aoqi@0 | 943 | } |
aoqi@0 | 944 | |
aoqi@0 | 945 | // Needed by request and reply messages for GIOP versions >= 1.2 only. |
aoqi@0 | 946 | void setHeaderPadding(boolean headerPadding) { |
aoqi@0 | 947 | // no-op. We don't care about body alignment while using |
aoqi@0 | 948 | // Java serialization. What the GIOP spec states does not apply here. |
aoqi@0 | 949 | } |
aoqi@0 | 950 | |
aoqi@0 | 951 | // Needed by IIOPInputStream and other subclasses |
aoqi@0 | 952 | |
aoqi@0 | 953 | public ByteBuffer getByteBuffer() { |
aoqi@0 | 954 | throw wrapper.giopVersionError(); |
aoqi@0 | 955 | } |
aoqi@0 | 956 | |
aoqi@0 | 957 | public void setByteBuffer(ByteBuffer byteBuffer) { |
aoqi@0 | 958 | throw wrapper.giopVersionError(); |
aoqi@0 | 959 | } |
aoqi@0 | 960 | |
aoqi@0 | 961 | public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) { |
aoqi@0 | 962 | throw wrapper.giopVersionError(); |
aoqi@0 | 963 | } |
aoqi@0 | 964 | |
aoqi@0 | 965 | public int getBufferLength() { |
aoqi@0 | 966 | return bufSize; |
aoqi@0 | 967 | } |
aoqi@0 | 968 | |
aoqi@0 | 969 | public void setBufferLength(int value) { |
aoqi@0 | 970 | // this is redundant, since buffer size was already specified |
aoqi@0 | 971 | // as part of the init call. So, ignore. |
aoqi@0 | 972 | } |
aoqi@0 | 973 | |
aoqi@0 | 974 | public int getIndex() { |
aoqi@0 | 975 | return bis.getPosition(); |
aoqi@0 | 976 | } |
aoqi@0 | 977 | |
aoqi@0 | 978 | public void setIndex(int value) { |
aoqi@0 | 979 | try { |
aoqi@0 | 980 | bis.setPosition(value); |
aoqi@0 | 981 | } catch (IndexOutOfBoundsException e) { |
aoqi@0 | 982 | throw wrapper.javaSerializationException(e, "setIndex"); |
aoqi@0 | 983 | } |
aoqi@0 | 984 | } |
aoqi@0 | 985 | |
aoqi@0 | 986 | public void orb(org.omg.CORBA.ORB orb) { |
aoqi@0 | 987 | this.orb = (ORB) orb; |
aoqi@0 | 988 | } |
aoqi@0 | 989 | |
aoqi@0 | 990 | public BufferManagerRead getBufferManager() { |
aoqi@0 | 991 | return bufferManager; |
aoqi@0 | 992 | } |
aoqi@0 | 993 | |
aoqi@0 | 994 | public GIOPVersion getGIOPVersion() { |
aoqi@0 | 995 | return GIOPVersion.V1_2; |
aoqi@0 | 996 | } |
aoqi@0 | 997 | |
aoqi@0 | 998 | com.sun.org.omg.SendingContext.CodeBase getCodeBase() { |
aoqi@0 | 999 | return parent.getCodeBase(); |
aoqi@0 | 1000 | } |
aoqi@0 | 1001 | |
aoqi@0 | 1002 | void printBuffer() { |
aoqi@0 | 1003 | byte[] buf = this.buffer.array(); |
aoqi@0 | 1004 | |
aoqi@0 | 1005 | System.out.println("+++++++ Input Buffer ++++++++"); |
aoqi@0 | 1006 | System.out.println(); |
aoqi@0 | 1007 | System.out.println("Current position: " + getPosition()); |
aoqi@0 | 1008 | System.out.println("Total length : " + this.bufSize); |
aoqi@0 | 1009 | System.out.println(); |
aoqi@0 | 1010 | |
aoqi@0 | 1011 | char[] charBuf = new char[16]; |
aoqi@0 | 1012 | |
aoqi@0 | 1013 | try { |
aoqi@0 | 1014 | |
aoqi@0 | 1015 | for (int i = 0; i < buf.length; i += 16) { |
aoqi@0 | 1016 | |
aoqi@0 | 1017 | int j = 0; |
aoqi@0 | 1018 | |
aoqi@0 | 1019 | // For every 16 bytes, there is one line |
aoqi@0 | 1020 | // of output. First, the hex output of |
aoqi@0 | 1021 | // the 16 bytes with each byte separated |
aoqi@0 | 1022 | // by a space. |
aoqi@0 | 1023 | while (j < 16 && j + i < buf.length) { |
aoqi@0 | 1024 | int k = buf[i + j]; |
aoqi@0 | 1025 | if (k < 0) |
aoqi@0 | 1026 | k = 256 + k; |
aoqi@0 | 1027 | String hex = Integer.toHexString(k); |
aoqi@0 | 1028 | if (hex.length() == 1) |
aoqi@0 | 1029 | hex = "0" + hex; |
aoqi@0 | 1030 | System.out.print(hex + " "); |
aoqi@0 | 1031 | j++; |
aoqi@0 | 1032 | } |
aoqi@0 | 1033 | |
aoqi@0 | 1034 | // Add any extra spaces to align the |
aoqi@0 | 1035 | // text column in case we didn't end |
aoqi@0 | 1036 | // at 16 |
aoqi@0 | 1037 | while (j < 16) { |
aoqi@0 | 1038 | System.out.print(" "); |
aoqi@0 | 1039 | j++; |
aoqi@0 | 1040 | } |
aoqi@0 | 1041 | |
aoqi@0 | 1042 | // Now output the ASCII equivalents. Non-ASCII |
aoqi@0 | 1043 | // characters are shown as periods. |
aoqi@0 | 1044 | int x = 0; |
aoqi@0 | 1045 | |
aoqi@0 | 1046 | while (x < 16 && x + i < buf.length) { |
aoqi@0 | 1047 | if (ORBUtility.isPrintable((char)buf[i + x])) { |
aoqi@0 | 1048 | charBuf[x] = (char) buf[i + x]; |
aoqi@0 | 1049 | } else { |
aoqi@0 | 1050 | charBuf[x] = '.'; |
aoqi@0 | 1051 | } |
aoqi@0 | 1052 | x++; |
aoqi@0 | 1053 | } |
aoqi@0 | 1054 | System.out.println(new String(charBuf, 0, x)); |
aoqi@0 | 1055 | } |
aoqi@0 | 1056 | } catch (Throwable t) { |
aoqi@0 | 1057 | t.printStackTrace(); |
aoqi@0 | 1058 | } |
aoqi@0 | 1059 | System.out.println("++++++++++++++++++++++++++++++"); |
aoqi@0 | 1060 | } |
aoqi@0 | 1061 | |
aoqi@0 | 1062 | void alignOnBoundary(int octetBoundary) { |
aoqi@0 | 1063 | throw wrapper.giopVersionError(); |
aoqi@0 | 1064 | } |
aoqi@0 | 1065 | |
aoqi@0 | 1066 | void performORBVersionSpecificInit() { |
aoqi@0 | 1067 | // No-op. |
aoqi@0 | 1068 | } |
aoqi@0 | 1069 | |
aoqi@0 | 1070 | public void resetCodeSetConverters() { |
aoqi@0 | 1071 | // No-op. |
aoqi@0 | 1072 | } |
aoqi@0 | 1073 | |
aoqi@0 | 1074 | // ValueInputStream ------------------------- |
aoqi@0 | 1075 | |
aoqi@0 | 1076 | public void start_value() { |
aoqi@0 | 1077 | throw wrapper.giopVersionError(); |
aoqi@0 | 1078 | } |
aoqi@0 | 1079 | |
aoqi@0 | 1080 | public void end_value() { |
aoqi@0 | 1081 | throw wrapper.giopVersionError(); |
aoqi@0 | 1082 | } |
aoqi@0 | 1083 | } |