src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java

Wed, 27 Apr 2016 01:21:28 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:21:28 +0800
changeset 0
7ef37b2cdcad
child 748
6845b95cba6b
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/corba/
changeset: 765:f46df0af2ca8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2012, 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 /*
aoqi@0 26 * Licensed Materials - Property of IBM
aoqi@0 27 * RMI-IIOP v1.0
aoqi@0 28 * Copyright IBM Corp. 1998 1999 All Rights Reserved
aoqi@0 29 *
aoqi@0 30 */
aoqi@0 31
aoqi@0 32 package com.sun.corba.se.impl.io;
aoqi@0 33
aoqi@0 34 import javax.rmi.CORBA.Util;
aoqi@0 35
aoqi@0 36 import java.util.Hashtable;
aoqi@0 37 import java.io.IOException;
aoqi@0 38
aoqi@0 39 import com.sun.corba.se.impl.util.RepositoryId;
aoqi@0 40 import com.sun.corba.se.impl.util.Utility;
aoqi@0 41
aoqi@0 42 import org.omg.CORBA.TCKind;
aoqi@0 43
aoqi@0 44 import org.omg.CORBA.portable.IndirectionException;
aoqi@0 45 import com.sun.org.omg.SendingContext.CodeBase;
aoqi@0 46 import com.sun.org.omg.SendingContext.CodeBaseHelper;
aoqi@0 47
aoqi@0 48 import java.security.AccessController;
aoqi@0 49 import java.security.PrivilegedAction;
aoqi@0 50 import java.security.PrivilegedExceptionAction;
aoqi@0 51
aoqi@0 52 import com.sun.corba.se.spi.logging.CORBALogDomains;
aoqi@0 53 import com.sun.corba.se.impl.logging.OMGSystemException;
aoqi@0 54 import com.sun.corba.se.impl.logging.UtilSystemException;
aoqi@0 55
aoqi@0 56 public final class ValueHandlerImpl implements javax.rmi.CORBA.ValueHandlerMultiFormat {
aoqi@0 57
aoqi@0 58 // Property to override our maximum stream format version
aoqi@0 59 public static final String FORMAT_VERSION_PROPERTY
aoqi@0 60 = "com.sun.CORBA.MaxStreamFormatVersion";
aoqi@0 61
aoqi@0 62 private static final byte MAX_SUPPORTED_FORMAT_VERSION = (byte)2;
aoqi@0 63 private static final byte STREAM_FORMAT_VERSION_1 = (byte)1;
aoqi@0 64
aoqi@0 65 // The ValueHandler's maximum stream format version to advertise,
aoqi@0 66 // set in a static initializer.
aoqi@0 67 private static final byte MAX_STREAM_FORMAT_VERSION;
aoqi@0 68
aoqi@0 69 static {
aoqi@0 70 MAX_STREAM_FORMAT_VERSION = getMaxStreamFormatVersion();
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 // Looks for the FORMAT_VERSION_PROPERTY system property
aoqi@0 74 // to allow the user to override our default stream format
aoqi@0 75 // version. Note that this still only allows them to pick
aoqi@0 76 // a supported version (1 through MAX_STREAM_FORMAT_VERSION).
aoqi@0 77 private static byte getMaxStreamFormatVersion() {
aoqi@0 78
aoqi@0 79 try {
aoqi@0 80
aoqi@0 81 String propValue = (String) AccessController.doPrivileged(
aoqi@0 82 new PrivilegedAction() {
aoqi@0 83 public java.lang.Object run() {
aoqi@0 84 return System.getProperty(ValueHandlerImpl.FORMAT_VERSION_PROPERTY);
aoqi@0 85 }
aoqi@0 86 });
aoqi@0 87
aoqi@0 88 // The property wasn't set
aoqi@0 89 if (propValue == null)
aoqi@0 90 return MAX_SUPPORTED_FORMAT_VERSION;
aoqi@0 91
aoqi@0 92 byte result = Byte.parseByte(propValue);
aoqi@0 93
aoqi@0 94 // REVISIT. Just set to MAX_SUPPORTED_FORMAT_VERSION
aoqi@0 95 // or really let the system shutdown with this Error?
aoqi@0 96 if (result < 1 || result > MAX_SUPPORTED_FORMAT_VERSION)
aoqi@0 97 // XXX I18N, logging needed.
aoqi@0 98 throw new ExceptionInInitializerError("Invalid stream format version: "
aoqi@0 99 + result
aoqi@0 100 + ". Valid range is 1 through "
aoqi@0 101 + MAX_SUPPORTED_FORMAT_VERSION);
aoqi@0 102
aoqi@0 103 return result;
aoqi@0 104
aoqi@0 105 } catch (Exception ex) {
aoqi@0 106 // REVISIT. Swallow this or really let
aoqi@0 107 // the system shutdown with this Error?
aoqi@0 108
aoqi@0 109 Error err = new ExceptionInInitializerError(ex);
aoqi@0 110 err.initCause( ex ) ;
aoqi@0 111 throw err ;
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 public static final short kRemoteType = 0;
aoqi@0 116 public static final short kAbstractType = 1;
aoqi@0 117 public static final short kValueType = 2;
aoqi@0 118
aoqi@0 119 private Hashtable inputStreamPairs = null;
aoqi@0 120 private Hashtable outputStreamPairs = null;
aoqi@0 121 private CodeBase codeBase = null;
aoqi@0 122 private boolean useHashtables = true;
aoqi@0 123 private boolean isInputStream = true;
aoqi@0 124 private IIOPOutputStream outputStreamBridge = null;
aoqi@0 125 private IIOPInputStream inputStreamBridge = null;
aoqi@0 126 private OMGSystemException omgWrapper = OMGSystemException.get(
aoqi@0 127 CORBALogDomains.RPC_ENCODING ) ;
aoqi@0 128 private UtilSystemException utilWrapper = UtilSystemException.get(
aoqi@0 129 CORBALogDomains.RPC_ENCODING ) ;
aoqi@0 130
aoqi@0 131 // See javax.rmi.CORBA.ValueHandlerMultiFormat
aoqi@0 132 public byte getMaximumStreamFormatVersion() {
aoqi@0 133 return MAX_STREAM_FORMAT_VERSION;
aoqi@0 134 }
aoqi@0 135
aoqi@0 136 // See javax.rmi.CORBA.ValueHandlerMultiFormat
aoqi@0 137 public void writeValue(org.omg.CORBA.portable.OutputStream out,
aoqi@0 138 java.io.Serializable value,
aoqi@0 139 byte streamFormatVersion) {
aoqi@0 140
aoqi@0 141 if (streamFormatVersion == 2) {
aoqi@0 142 if (!(out instanceof org.omg.CORBA.portable.ValueOutputStream)) {
aoqi@0 143 throw omgWrapper.notAValueoutputstream() ;
aoqi@0 144 }
aoqi@0 145 } else if (streamFormatVersion != 1) {
aoqi@0 146 throw omgWrapper.invalidStreamFormatVersion(
aoqi@0 147 new Integer(streamFormatVersion) ) ;
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 writeValueWithVersion(out, value, streamFormatVersion);
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 private ValueHandlerImpl(){}
aoqi@0 154
aoqi@0 155 private ValueHandlerImpl(boolean isInputStream) {
aoqi@0 156 this();
aoqi@0 157 useHashtables = false;
aoqi@0 158 this.isInputStream = isInputStream;
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 static ValueHandlerImpl getInstance() {
aoqi@0 162 return new ValueHandlerImpl();
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 static ValueHandlerImpl getInstance(boolean isInputStream) {
aoqi@0 166 return new ValueHandlerImpl(isInputStream);
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 /**
aoqi@0 170 * Writes the value to the stream using java semantics.
aoqi@0 171 * @param out The stream to write the value to
aoqi@0 172 * @param value The value to be written to the stream
aoqi@0 173 **/
aoqi@0 174 public void writeValue(org.omg.CORBA.portable.OutputStream _out,
aoqi@0 175 java.io.Serializable value) {
aoqi@0 176 writeValueWithVersion(_out, value, STREAM_FORMAT_VERSION_1);
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 private void writeValueWithVersion(org.omg.CORBA.portable.OutputStream _out,
aoqi@0 180 java.io.Serializable value,
aoqi@0 181 byte streamFormatVersion) {
aoqi@0 182
aoqi@0 183 org.omg.CORBA_2_3.portable.OutputStream out =
aoqi@0 184 (org.omg.CORBA_2_3.portable.OutputStream) _out;
aoqi@0 185
aoqi@0 186 if (!useHashtables) {
aoqi@0 187 if (outputStreamBridge == null) {
aoqi@0 188 outputStreamBridge = createOutputStream();
aoqi@0 189 outputStreamBridge.setOrbStream(out);
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 try {
aoqi@0 193 outputStreamBridge.increaseRecursionDepth();
aoqi@0 194 writeValueInternal(outputStreamBridge, out, value, streamFormatVersion);
aoqi@0 195 } finally {
aoqi@0 196 outputStreamBridge.decreaseRecursionDepth();
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 return;
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 IIOPOutputStream jdkToOrbOutputStreamBridge = null;
aoqi@0 203
aoqi@0 204 if (outputStreamPairs == null)
aoqi@0 205 outputStreamPairs = new Hashtable();
aoqi@0 206
aoqi@0 207 jdkToOrbOutputStreamBridge = (IIOPOutputStream)outputStreamPairs.get(_out);
aoqi@0 208
aoqi@0 209 if (jdkToOrbOutputStreamBridge == null) {
aoqi@0 210 jdkToOrbOutputStreamBridge = createOutputStream();
aoqi@0 211 jdkToOrbOutputStreamBridge.setOrbStream(out);
aoqi@0 212 outputStreamPairs.put(_out, jdkToOrbOutputStreamBridge);
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 try {
aoqi@0 216
aoqi@0 217 jdkToOrbOutputStreamBridge.increaseRecursionDepth();
aoqi@0 218 writeValueInternal(jdkToOrbOutputStreamBridge, out, value, streamFormatVersion);
aoqi@0 219 } finally {
aoqi@0 220 if (jdkToOrbOutputStreamBridge.decreaseRecursionDepth() == 0) {
aoqi@0 221 outputStreamPairs.remove(_out);
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 private void writeValueInternal(IIOPOutputStream bridge,
aoqi@0 227 org.omg.CORBA_2_3.portable.OutputStream out,
aoqi@0 228 java.io.Serializable value,
aoqi@0 229 byte streamFormatVersion)
aoqi@0 230 {
aoqi@0 231 Class clazz = value.getClass();
aoqi@0 232
aoqi@0 233 if (clazz.isArray())
aoqi@0 234 write_Array(out, value, clazz.getComponentType());
aoqi@0 235 else
aoqi@0 236 bridge.simpleWriteObject(value, streamFormatVersion);
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 /**
aoqi@0 240 * Reads a value from the stream using java semantics.
aoqi@0 241 * @param in The stream to read the value from
aoqi@0 242 * @param clazz The type of the value to be read in
aoqi@0 243 * @param sender The sending context runtime
aoqi@0 244 **/
aoqi@0 245 public java.io.Serializable readValue(org.omg.CORBA.portable.InputStream _in,
aoqi@0 246 int offset,
aoqi@0 247 java.lang.Class clazz,
aoqi@0 248 String repositoryID,
aoqi@0 249 org.omg.SendingContext.RunTime _sender)
aoqi@0 250 {
aoqi@0 251 // Must use narrow rather than a direct cast to a com.sun
aoqi@0 252 // class. Fix for bug 4379539.
aoqi@0 253 CodeBase sender = CodeBaseHelper.narrow(_sender);
aoqi@0 254
aoqi@0 255 org.omg.CORBA_2_3.portable.InputStream in =
aoqi@0 256 (org.omg.CORBA_2_3.portable.InputStream) _in;
aoqi@0 257
aoqi@0 258 if (!useHashtables) {
aoqi@0 259 if (inputStreamBridge == null) {
aoqi@0 260 inputStreamBridge = createInputStream();
aoqi@0 261 inputStreamBridge.setOrbStream(in);
aoqi@0 262 inputStreamBridge.setSender(sender); //d11638
aoqi@0 263 // backward compatability 4365188
aoqi@0 264 inputStreamBridge.setValueHandler(this);
aoqi@0 265 }
aoqi@0 266
aoqi@0 267 java.io.Serializable result = null;
aoqi@0 268
aoqi@0 269 try {
aoqi@0 270
aoqi@0 271 inputStreamBridge.increaseRecursionDepth();
aoqi@0 272 result = (java.io.Serializable) readValueInternal(inputStreamBridge, in, offset, clazz, repositoryID, sender);
aoqi@0 273
aoqi@0 274 } finally {
aoqi@0 275
aoqi@0 276 if (inputStreamBridge.decreaseRecursionDepth() == 0) {
aoqi@0 277 // Indirections are resolved immediately since
aoqi@0 278 // the change to the active recursion manager,
aoqi@0 279 // so this will never happen.
aoqi@0 280 }
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 return result;
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 IIOPInputStream jdkToOrbInputStreamBridge = null;
aoqi@0 287 if (inputStreamPairs == null)
aoqi@0 288 inputStreamPairs = new Hashtable();
aoqi@0 289
aoqi@0 290 jdkToOrbInputStreamBridge = (IIOPInputStream)inputStreamPairs.get(_in);
aoqi@0 291
aoqi@0 292 if (jdkToOrbInputStreamBridge == null) {
aoqi@0 293
aoqi@0 294 jdkToOrbInputStreamBridge = createInputStream();
aoqi@0 295 jdkToOrbInputStreamBridge.setOrbStream(in);
aoqi@0 296 jdkToOrbInputStreamBridge.setSender(sender); //d11638
aoqi@0 297 // backward compatability 4365188
aoqi@0 298 jdkToOrbInputStreamBridge.setValueHandler(this);
aoqi@0 299 inputStreamPairs.put(_in, jdkToOrbInputStreamBridge);
aoqi@0 300 }
aoqi@0 301
aoqi@0 302 java.io.Serializable result = null;
aoqi@0 303
aoqi@0 304 try {
aoqi@0 305
aoqi@0 306 jdkToOrbInputStreamBridge.increaseRecursionDepth();
aoqi@0 307 result = (java.io.Serializable) readValueInternal(jdkToOrbInputStreamBridge, in, offset, clazz, repositoryID, sender);
aoqi@0 308
aoqi@0 309 } finally {
aoqi@0 310
aoqi@0 311 if (jdkToOrbInputStreamBridge.decreaseRecursionDepth() == 0) {
aoqi@0 312 inputStreamPairs.remove(_in);
aoqi@0 313 }
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 return result;
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 private java.io.Serializable readValueInternal(IIOPInputStream bridge,
aoqi@0 320 org.omg.CORBA_2_3.portable.InputStream in,
aoqi@0 321 int offset,
aoqi@0 322 java.lang.Class clazz,
aoqi@0 323 String repositoryID,
aoqi@0 324 com.sun.org.omg.SendingContext.CodeBase sender)
aoqi@0 325 {
aoqi@0 326 java.io.Serializable result = null;
aoqi@0 327
aoqi@0 328 if (clazz == null) {
aoqi@0 329 // clazz == null indicates an FVD situation for a nonexistant class
aoqi@0 330 if (isArray(repositoryID)){
aoqi@0 331 read_Array(bridge, in, null, sender, offset);
aoqi@0 332 } else {
aoqi@0 333 bridge.simpleSkipObject(repositoryID, sender);
aoqi@0 334 }
aoqi@0 335 return result;
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 if (clazz.isArray()) {
aoqi@0 339 result = (java.io.Serializable)read_Array(bridge, in, clazz, sender, offset);
aoqi@0 340 } else {
aoqi@0 341 result = (java.io.Serializable)bridge.simpleReadObject(clazz, repositoryID, sender, offset);
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 return result;
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 /**
aoqi@0 348 * Returns the repository ID for the given RMI value Class.
aoqi@0 349 * @param clz The class to return a repository ID for.
aoqi@0 350 * @return the repository ID of the Class.
aoqi@0 351 **/
aoqi@0 352 public java.lang.String getRMIRepositoryID(java.lang.Class clz) {
aoqi@0 353 return RepositoryId.createForJavaType(clz);
aoqi@0 354 }
aoqi@0 355
aoqi@0 356 /**
aoqi@0 357 * Indicates whether the given Class performs custom or
aoqi@0 358 * default marshaling.
aoqi@0 359 * @param clz The class to test for custom marshaling.
aoqi@0 360 * @return True if the class performs custom marshaling, false
aoqi@0 361 * if it does not.
aoqi@0 362 **/
aoqi@0 363 public boolean isCustomMarshaled(java.lang.Class clz) {
aoqi@0 364 return ObjectStreamClass.lookup(clz).isCustomMarshaled();
aoqi@0 365 }
aoqi@0 366
aoqi@0 367 /**
aoqi@0 368 * Returns the CodeBase for this ValueHandler. This is used by
aoqi@0 369 * the ORB runtime. The server sends the service context containing
aoqi@0 370 * the IOR for this CodeBase on the first GIOP reply. The clients
aoqi@0 371 * do the same on the first GIOP request.
aoqi@0 372 * @return the SendingContext.CodeBase of this ValueHandler.
aoqi@0 373 **/
aoqi@0 374 public org.omg.SendingContext.RunTime getRunTimeCodeBase() {
aoqi@0 375 if (codeBase != null)
aoqi@0 376 return codeBase;
aoqi@0 377 else {
aoqi@0 378 codeBase = new FVDCodeBaseImpl();
aoqi@0 379
aoqi@0 380 // backward compatability 4365188
aoqi@0 381 // set the valueHandler so that correct/incorrect RepositoryID
aoqi@0 382 // calculations can be done based on the ORB version
aoqi@0 383 FVDCodeBaseImpl fvdImpl = (FVDCodeBaseImpl) codeBase;
aoqi@0 384 fvdImpl.setValueHandler(this);
aoqi@0 385 return codeBase;
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388
aoqi@0 389
aoqi@0 390 // methods supported for backward compatability so that the appropriate
aoqi@0 391 // Rep-id calculations take place based on the ORB version
aoqi@0 392
aoqi@0 393 /**
aoqi@0 394 * Returns a boolean of whether or not RepositoryId indicates
aoqi@0 395 * FullValueDescriptor.
aoqi@0 396 * used for backward compatability
aoqi@0 397 */
aoqi@0 398
aoqi@0 399 public boolean useFullValueDescription(Class clazz, String repositoryID)
aoqi@0 400 throws IOException
aoqi@0 401 {
aoqi@0 402 return RepositoryId.useFullValueDescription(clazz, repositoryID);
aoqi@0 403 }
aoqi@0 404
aoqi@0 405 public String getClassName(String id)
aoqi@0 406 {
aoqi@0 407 RepositoryId repID = RepositoryId.cache.getId(id);
aoqi@0 408 return repID.getClassName();
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 public Class getClassFromType(String id)
aoqi@0 412 throws ClassNotFoundException
aoqi@0 413 {
aoqi@0 414 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 415 return repId.getClassFromType();
aoqi@0 416 }
aoqi@0 417
aoqi@0 418 public Class getAnyClassFromType(String id)
aoqi@0 419 throws ClassNotFoundException
aoqi@0 420 {
aoqi@0 421 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 422 return repId.getAnyClassFromType();
aoqi@0 423 }
aoqi@0 424
aoqi@0 425 public String createForAnyType(Class cl)
aoqi@0 426 {
aoqi@0 427 return RepositoryId.createForAnyType(cl);
aoqi@0 428 }
aoqi@0 429
aoqi@0 430 public String getDefinedInId(String id)
aoqi@0 431 {
aoqi@0 432 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 433 return repId.getDefinedInId();
aoqi@0 434 }
aoqi@0 435
aoqi@0 436 public String getUnqualifiedName(String id)
aoqi@0 437 {
aoqi@0 438 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 439 return repId.getUnqualifiedName();
aoqi@0 440 }
aoqi@0 441
aoqi@0 442 public String getSerialVersionUID(String id)
aoqi@0 443 {
aoqi@0 444 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 445 return repId.getSerialVersionUID();
aoqi@0 446 }
aoqi@0 447
aoqi@0 448
aoqi@0 449 public boolean isAbstractBase(Class clazz)
aoqi@0 450 {
aoqi@0 451 return RepositoryId.isAbstractBase(clazz);
aoqi@0 452 }
aoqi@0 453
aoqi@0 454 public boolean isSequence(String id)
aoqi@0 455 {
aoqi@0 456 RepositoryId repId = RepositoryId.cache.getId(id);
aoqi@0 457 return repId.isSequence();
aoqi@0 458 }
aoqi@0 459
aoqi@0 460 /**
aoqi@0 461 * If the value contains a writeReplace method then the result
aoqi@0 462 * is returned. Otherwise, the value itself is returned.
aoqi@0 463 * @return the true value to marshal on the wire.
aoqi@0 464 **/
aoqi@0 465 public java.io.Serializable writeReplace(java.io.Serializable value) {
aoqi@0 466 return ObjectStreamClass.lookup(value.getClass()).writeReplace(value);
aoqi@0 467 }
aoqi@0 468
aoqi@0 469 private void writeCharArray(org.omg.CORBA_2_3.portable.OutputStream out,
aoqi@0 470 char[] array,
aoqi@0 471 int offset,
aoqi@0 472 int length)
aoqi@0 473 {
aoqi@0 474 out.write_wchar_array(array, offset, length);
aoqi@0 475 }
aoqi@0 476
aoqi@0 477 private void write_Array(org.omg.CORBA_2_3.portable.OutputStream out, java.io.Serializable obj, Class type) {
aoqi@0 478
aoqi@0 479 int i, length;
aoqi@0 480
aoqi@0 481 if (type.isPrimitive()) {
aoqi@0 482 if (type == Integer.TYPE) {
aoqi@0 483 int[] array = (int[])((Object)obj);
aoqi@0 484 length = array.length;
aoqi@0 485 out.write_ulong(length);
aoqi@0 486 out.write_long_array(array, 0, length);
aoqi@0 487 } else if (type == Byte.TYPE) {
aoqi@0 488 byte[] array = (byte[])((Object)obj);
aoqi@0 489 length = array.length;
aoqi@0 490 out.write_ulong(length);
aoqi@0 491 out.write_octet_array(array, 0, length);
aoqi@0 492 } else if (type == Long.TYPE) {
aoqi@0 493 long[] array = (long[])((Object)obj);
aoqi@0 494 length = array.length;
aoqi@0 495 out.write_ulong(length);
aoqi@0 496 out.write_longlong_array(array, 0, length);
aoqi@0 497 } else if (type == Float.TYPE) {
aoqi@0 498 float[] array = (float[])((Object)obj);
aoqi@0 499 length = array.length;
aoqi@0 500 out.write_ulong(length);
aoqi@0 501 out.write_float_array(array, 0, length);
aoqi@0 502 } else if (type == Double.TYPE) {
aoqi@0 503 double[] array = (double[])((Object)obj);
aoqi@0 504 length = array.length;
aoqi@0 505 out.write_ulong(length);
aoqi@0 506 out.write_double_array(array, 0, length);
aoqi@0 507 } else if (type == Short.TYPE) {
aoqi@0 508 short[] array = (short[])((Object)obj);
aoqi@0 509 length = array.length;
aoqi@0 510 out.write_ulong(length);
aoqi@0 511 out.write_short_array(array, 0, length);
aoqi@0 512 } else if (type == Character.TYPE) {
aoqi@0 513 char[] array = (char[])((Object)obj);
aoqi@0 514 length = array.length;
aoqi@0 515 out.write_ulong(length);
aoqi@0 516 writeCharArray(out, array, 0, length);
aoqi@0 517 } else if (type == Boolean.TYPE) {
aoqi@0 518 boolean[] array = (boolean[])((Object)obj);
aoqi@0 519 length = array.length;
aoqi@0 520 out.write_ulong(length);
aoqi@0 521 out.write_boolean_array(array, 0, length);
aoqi@0 522 } else {
aoqi@0 523 // XXX I18N, logging needed.
aoqi@0 524 throw new Error("Invalid primitive type : " +
aoqi@0 525 obj.getClass().getName());
aoqi@0 526 }
aoqi@0 527 } else if (type == java.lang.Object.class) {
aoqi@0 528 Object[] array = (Object[])((Object)obj);
aoqi@0 529 length = array.length;
aoqi@0 530 out.write_ulong(length);
aoqi@0 531 for (i = 0; i < length; i++) {
aoqi@0 532 Util.writeAny(out, array[i]);
aoqi@0 533 }
aoqi@0 534 } else {
aoqi@0 535 Object[] array = (Object[])((Object)obj);
aoqi@0 536 length = array.length;
aoqi@0 537 out.write_ulong(length);
aoqi@0 538 int callType = kValueType;
aoqi@0 539
aoqi@0 540 if (type.isInterface()) {
aoqi@0 541 String className = type.getName();
aoqi@0 542
aoqi@0 543 if (java.rmi.Remote.class.isAssignableFrom(type)) {
aoqi@0 544 // RMI Object reference...
aoqi@0 545 callType = kRemoteType;
aoqi@0 546 } else if (org.omg.CORBA.Object.class.isAssignableFrom(type)){
aoqi@0 547 // IDL Object reference...
aoqi@0 548 callType = kRemoteType;
aoqi@0 549 } else if (RepositoryId.isAbstractBase(type)) {
aoqi@0 550 // IDL Abstract Object reference...
aoqi@0 551 callType = kAbstractType;
aoqi@0 552 } else if (ObjectStreamClassCorbaExt.isAbstractInterface(type)) {
aoqi@0 553 callType = kAbstractType;
aoqi@0 554 }
aoqi@0 555 }
aoqi@0 556
aoqi@0 557 for (i = 0; i < length; i++) {
aoqi@0 558 switch (callType) {
aoqi@0 559 case kRemoteType:
aoqi@0 560 Util.writeRemoteObject(out, array[i]);
aoqi@0 561 break;
aoqi@0 562 case kAbstractType:
aoqi@0 563 Util.writeAbstractObject(out,array[i]);
aoqi@0 564 break;
aoqi@0 565 case kValueType:
aoqi@0 566 try{
aoqi@0 567 out.write_value((java.io.Serializable)array[i]);
aoqi@0 568 } catch(ClassCastException cce){
aoqi@0 569 if (array[i] instanceof java.io.Serializable)
aoqi@0 570 throw cce;
aoqi@0 571 else {
aoqi@0 572 Utility.throwNotSerializableForCorba(
aoqi@0 573 array[i].getClass().getName());
aoqi@0 574 }
aoqi@0 575 }
aoqi@0 576 break;
aoqi@0 577 }
aoqi@0 578 }
aoqi@0 579 }
aoqi@0 580 }
aoqi@0 581
aoqi@0 582 private void readCharArray(org.omg.CORBA_2_3.portable.InputStream in,
aoqi@0 583 char[] array,
aoqi@0 584 int offset,
aoqi@0 585 int length)
aoqi@0 586 {
aoqi@0 587 in.read_wchar_array(array, offset, length);
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 private java.lang.Object read_Array(IIOPInputStream bridge,
aoqi@0 591 org.omg.CORBA_2_3.portable.InputStream in,
aoqi@0 592 Class sequence,
aoqi@0 593 com.sun.org.omg.SendingContext.CodeBase sender,
aoqi@0 594 int offset)
aoqi@0 595 {
aoqi@0 596 try {
aoqi@0 597 // Read length of coming array
aoqi@0 598 int length = in.read_ulong();
aoqi@0 599 int i;
aoqi@0 600
aoqi@0 601 if (sequence == null) {
aoqi@0 602 for (i = 0; i < length; i++)
aoqi@0 603 in.read_value();
aoqi@0 604
aoqi@0 605 return null;
aoqi@0 606 }
aoqi@0 607
aoqi@0 608 Class componentType = sequence.getComponentType();
aoqi@0 609 Class actualType = componentType;
aoqi@0 610
aoqi@0 611
aoqi@0 612 if (componentType.isPrimitive()) {
aoqi@0 613 if (componentType == Integer.TYPE) {
aoqi@0 614 int[] array = new int[length];
aoqi@0 615 in.read_long_array(array, 0, length);
aoqi@0 616 return ((java.io.Serializable)((Object)array));
aoqi@0 617 } else if (componentType == Byte.TYPE) {
aoqi@0 618 byte[] array = new byte[length];
aoqi@0 619 in.read_octet_array(array, 0, length);
aoqi@0 620 return ((java.io.Serializable)((Object)array));
aoqi@0 621 } else if (componentType == Long.TYPE) {
aoqi@0 622 long[] array = new long[length];
aoqi@0 623 in.read_longlong_array(array, 0, length);
aoqi@0 624 return ((java.io.Serializable)((Object)array));
aoqi@0 625 } else if (componentType == Float.TYPE) {
aoqi@0 626 float[] array = new float[length];
aoqi@0 627 in.read_float_array(array, 0, length);
aoqi@0 628 return ((java.io.Serializable)((Object)array));
aoqi@0 629 } else if (componentType == Double.TYPE) {
aoqi@0 630 double[] array = new double[length];
aoqi@0 631 in.read_double_array(array, 0, length);
aoqi@0 632 return ((java.io.Serializable)((Object)array));
aoqi@0 633 } else if (componentType == Short.TYPE) {
aoqi@0 634 short[] array = new short[length];
aoqi@0 635 in.read_short_array(array, 0, length);
aoqi@0 636 return ((java.io.Serializable)((Object)array));
aoqi@0 637 } else if (componentType == Character.TYPE) {
aoqi@0 638 char[] array = new char[length];
aoqi@0 639 readCharArray(in, array, 0, length);
aoqi@0 640 return ((java.io.Serializable)((Object)array));
aoqi@0 641 } else if (componentType == Boolean.TYPE) {
aoqi@0 642 boolean[] array = new boolean[length];
aoqi@0 643 in.read_boolean_array(array, 0, length);
aoqi@0 644 return ((java.io.Serializable)((Object)array));
aoqi@0 645 } else {
aoqi@0 646 // XXX I18N, logging needed.
aoqi@0 647 throw new Error("Invalid primitive componentType : " + sequence.getName());
aoqi@0 648 }
aoqi@0 649 } else if (componentType == java.lang.Object.class) {
aoqi@0 650 Object[] array = (Object[])java.lang.reflect.Array.newInstance(
aoqi@0 651 componentType, length);
aoqi@0 652
aoqi@0 653 // Store this object and its beginning position
aoqi@0 654 // since there might be indirections to it while
aoqi@0 655 // it's been unmarshalled.
aoqi@0 656 bridge.activeRecursionMgr.addObject(offset, array);
aoqi@0 657
aoqi@0 658 for (i = 0; i < length; i++) {
aoqi@0 659 Object objectValue = null;
aoqi@0 660 try {
aoqi@0 661 objectValue = Util.readAny(in);
aoqi@0 662 } catch(IndirectionException cdrie) {
aoqi@0 663 try {
aoqi@0 664 // The CDR stream had never seen the given offset
aoqi@0 665 // before, so check the recursion manager (it will
aoqi@0 666 // throw an IOException if it doesn't have a
aoqi@0 667 // reference, either).
aoqi@0 668 objectValue = bridge.activeRecursionMgr.getObject(
aoqi@0 669 cdrie.offset);
aoqi@0 670 } catch (IOException ie) {
aoqi@0 671 // Translate to a MARSHAL exception since
aoqi@0 672 // ValueHandlers aren't allowed to throw
aoqi@0 673 // IOExceptions
aoqi@0 674 throw utilWrapper.invalidIndirection( ie,
aoqi@0 675 new Integer( cdrie.offset ) ) ;
aoqi@0 676 }
aoqi@0 677 }
aoqi@0 678
aoqi@0 679 array[i] = objectValue;
aoqi@0 680 }
aoqi@0 681 return ((java.io.Serializable)((Object)array));
aoqi@0 682 } else {
aoqi@0 683 Object[] array = (Object[])java.lang.reflect.Array.newInstance(
aoqi@0 684 componentType, length);
aoqi@0 685 // Store this object and its beginning position
aoqi@0 686 // since there might be indirections to it while
aoqi@0 687 // it's been unmarshalled.
aoqi@0 688 bridge.activeRecursionMgr.addObject(offset, array);
aoqi@0 689
aoqi@0 690 // Decide what method call to make based on the componentType.
aoqi@0 691 // If it is a componentType for which we need to load a stub,
aoqi@0 692 // convert the componentType to the correct stub type.
aoqi@0 693
aoqi@0 694 int callType = kValueType;
aoqi@0 695 boolean narrow = false;
aoqi@0 696
aoqi@0 697 if (componentType.isInterface()) {
aoqi@0 698 boolean loadStubClass = false;
aoqi@0 699 // String className = componentType.getName();
aoqi@0 700
aoqi@0 701 if (java.rmi.Remote.class.isAssignableFrom(componentType)) {
aoqi@0 702
aoqi@0 703 // RMI Object reference...
aoqi@0 704 callType = kRemoteType;
aoqi@0 705
aoqi@0 706 // for better performance, load the stub class once
aoqi@0 707 // instead of for each element of the array
aoqi@0 708 loadStubClass = true;
aoqi@0 709 } else if (org.omg.CORBA.Object.class.isAssignableFrom(componentType)){
aoqi@0 710 // IDL Object reference...
aoqi@0 711 callType = kRemoteType;
aoqi@0 712 loadStubClass = true;
aoqi@0 713 } else if (RepositoryId.isAbstractBase(componentType)) {
aoqi@0 714 // IDL Abstract Object reference...
aoqi@0 715 callType = kAbstractType;
aoqi@0 716 loadStubClass = true;
aoqi@0 717 } else if (ObjectStreamClassCorbaExt.isAbstractInterface(componentType)) {
aoqi@0 718
aoqi@0 719 // RMI Abstract Object reference...
aoqi@0 720
aoqi@0 721 // componentType = null;
aoqi@0 722 callType = kAbstractType;
aoqi@0 723 }
aoqi@0 724
aoqi@0 725 if (loadStubClass) {
aoqi@0 726 try {
aoqi@0 727 String codebase = Util.getCodebase(componentType);
aoqi@0 728 String repID = RepositoryId.createForAnyType(componentType);
aoqi@0 729 Class stubType =
aoqi@0 730 Utility.loadStubClass(repID, codebase, componentType);
aoqi@0 731 actualType = stubType;
aoqi@0 732 } catch (ClassNotFoundException e) {
aoqi@0 733 narrow = true;
aoqi@0 734 }
aoqi@0 735 } else {
aoqi@0 736 narrow = true;
aoqi@0 737 }
aoqi@0 738 }
aoqi@0 739
aoqi@0 740 for (i = 0; i < length; i++) {
aoqi@0 741
aoqi@0 742 try {
aoqi@0 743 switch (callType) {
aoqi@0 744 case kRemoteType:
aoqi@0 745 if (!narrow)
aoqi@0 746 array[i] = (Object)in.read_Object(actualType);
aoqi@0 747 else {
aoqi@0 748 array[i] = Utility.readObjectAndNarrow(in, actualType);
aoqi@0 749
aoqi@0 750 }
aoqi@0 751 break;
aoqi@0 752 case kAbstractType:
aoqi@0 753 if (!narrow)
aoqi@0 754 array[i] = (Object)in.read_abstract_interface(actualType);
aoqi@0 755 else {
aoqi@0 756 array[i] = Utility.readAbstractAndNarrow(in, actualType);
aoqi@0 757 }
aoqi@0 758 break;
aoqi@0 759 case kValueType:
aoqi@0 760 array[i] = (Object)in.read_value(actualType);
aoqi@0 761 break;
aoqi@0 762 }
aoqi@0 763 } catch(IndirectionException cdrie) {
aoqi@0 764 // The CDR stream had never seen the given offset before,
aoqi@0 765 // so check the recursion manager (it will throw an
aoqi@0 766 // IOException if it doesn't have a reference, either).
aoqi@0 767 try {
aoqi@0 768 array[i] = bridge.activeRecursionMgr.getObject(
aoqi@0 769 cdrie.offset);
aoqi@0 770 } catch (IOException ioe) {
aoqi@0 771 // Translate to a MARSHAL exception since
aoqi@0 772 // ValueHandlers aren't allowed to throw
aoqi@0 773 // IOExceptions
aoqi@0 774 throw utilWrapper.invalidIndirection( ioe,
aoqi@0 775 new Integer( cdrie.offset ) ) ;
aoqi@0 776 }
aoqi@0 777 }
aoqi@0 778
aoqi@0 779 }
aoqi@0 780
aoqi@0 781 return ((java.io.Serializable)((Object)array));
aoqi@0 782 }
aoqi@0 783 } finally {
aoqi@0 784 // We've completed deserializing this object. Any
aoqi@0 785 // future indirections will be handled correctly at the
aoqi@0 786 // CDR level. The ActiveRecursionManager only deals with
aoqi@0 787 // objects currently being deserialized.
aoqi@0 788 bridge.activeRecursionMgr.removeObject(offset);
aoqi@0 789 }
aoqi@0 790 }
aoqi@0 791
aoqi@0 792 private boolean isArray(String repId){
aoqi@0 793 return RepositoryId.cache.getId(repId).isSequence();
aoqi@0 794 }
aoqi@0 795
aoqi@0 796 private String getOutputStreamClassName() {
aoqi@0 797 return "com.sun.corba.se.impl.io.IIOPOutputStream";
aoqi@0 798 }
aoqi@0 799
aoqi@0 800 private IIOPOutputStream createOutputStream() {
aoqi@0 801 final String name = getOutputStreamClassName();
aoqi@0 802 try {
aoqi@0 803 IIOPOutputStream stream = createOutputStreamBuiltIn(name);
aoqi@0 804 if (stream != null) {
aoqi@0 805 return stream;
aoqi@0 806 }
aoqi@0 807 return createCustom(IIOPOutputStream.class, name);
aoqi@0 808 } catch (Throwable t) {
aoqi@0 809 // Throw exception under the carpet.
aoqi@0 810 InternalError ie = new InternalError(
aoqi@0 811 "Error loading " + name
aoqi@0 812 );
aoqi@0 813 ie.initCause(t);
aoqi@0 814 throw ie;
aoqi@0 815 }
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 /**
aoqi@0 819 * Construct a built in implementation with priveleges.
aoqi@0 820 * Returning null indicates a non-built is specified.
aoqi@0 821 */
aoqi@0 822 private IIOPOutputStream createOutputStreamBuiltIn(
aoqi@0 823 final String name
aoqi@0 824 ) throws Throwable {
aoqi@0 825 try {
aoqi@0 826 return AccessController.doPrivileged(
aoqi@0 827 new PrivilegedExceptionAction<IIOPOutputStream>() {
aoqi@0 828 public IIOPOutputStream run() throws IOException {
aoqi@0 829 return createOutputStreamBuiltInNoPriv(name);
aoqi@0 830 }
aoqi@0 831 }
aoqi@0 832 );
aoqi@0 833 } catch (java.security.PrivilegedActionException exc) {
aoqi@0 834 throw exc.getCause();
aoqi@0 835 }
aoqi@0 836 }
aoqi@0 837
aoqi@0 838 /**
aoqi@0 839 * Returning null indicates a non-built is specified.
aoqi@0 840 */
aoqi@0 841 private IIOPOutputStream createOutputStreamBuiltInNoPriv(
aoqi@0 842 final String name
aoqi@0 843 ) throws IOException {
aoqi@0 844 return name.equals(IIOPOutputStream.class.getName()) ?
aoqi@0 845 new IIOPOutputStream() : null;
aoqi@0 846 }
aoqi@0 847
aoqi@0 848 private String getInputStreamClassName() {
aoqi@0 849 return "com.sun.corba.se.impl.io.IIOPInputStream";
aoqi@0 850 }
aoqi@0 851
aoqi@0 852 private IIOPInputStream createInputStream() {
aoqi@0 853 final String name = getInputStreamClassName();
aoqi@0 854 try {
aoqi@0 855 IIOPInputStream stream = createInputStreamBuiltIn(name);
aoqi@0 856 if (stream != null) {
aoqi@0 857 return stream;
aoqi@0 858 }
aoqi@0 859 return createCustom(IIOPInputStream.class, name);
aoqi@0 860 } catch (Throwable t) {
aoqi@0 861 // Throw exception under the carpet.
aoqi@0 862 InternalError ie = new InternalError(
aoqi@0 863 "Error loading " + name
aoqi@0 864 );
aoqi@0 865 ie.initCause(t);
aoqi@0 866 throw ie;
aoqi@0 867 }
aoqi@0 868 }
aoqi@0 869
aoqi@0 870 /**
aoqi@0 871 * Construct a built in implementation with priveleges.
aoqi@0 872 * Returning null indicates a non-built is specified.
aoqi@0 873 */
aoqi@0 874 private IIOPInputStream createInputStreamBuiltIn(
aoqi@0 875 final String name
aoqi@0 876 ) throws Throwable {
aoqi@0 877 try {
aoqi@0 878 return AccessController.doPrivileged(
aoqi@0 879 new PrivilegedExceptionAction<IIOPInputStream>() {
aoqi@0 880 public IIOPInputStream run() throws IOException {
aoqi@0 881 return createInputStreamBuiltInNoPriv(name);
aoqi@0 882 }
aoqi@0 883 }
aoqi@0 884 );
aoqi@0 885 } catch (java.security.PrivilegedActionException exc) {
aoqi@0 886 throw exc.getCause();
aoqi@0 887 }
aoqi@0 888 }
aoqi@0 889
aoqi@0 890 /**
aoqi@0 891 * Returning null indicates a non-built is specified.
aoqi@0 892 */
aoqi@0 893 private IIOPInputStream createInputStreamBuiltInNoPriv(
aoqi@0 894 final String name
aoqi@0 895 ) throws IOException {
aoqi@0 896 return name.equals(IIOPInputStream.class.getName()) ?
aoqi@0 897 new IIOPInputStream() : null;
aoqi@0 898 }
aoqi@0 899
aoqi@0 900 /**
aoqi@0 901 * Create a custom implementation without privileges.
aoqi@0 902 */
aoqi@0 903 private <T> T createCustom(
aoqi@0 904 final Class<T> type, final String className
aoqi@0 905 ) throws Throwable {
aoqi@0 906 // Note: We use the thread context or system ClassLoader here
aoqi@0 907 // since we want to load classes outside of the
aoqi@0 908 // core JDK when running J2EE Pure ORB and
aoqi@0 909 // talking to Kestrel.
aoqi@0 910 ClassLoader cl = Thread.currentThread().getContextClassLoader();
aoqi@0 911 if (cl == null)
aoqi@0 912 cl = ClassLoader.getSystemClassLoader();
aoqi@0 913
aoqi@0 914 Class<?> clazz = cl.loadClass(className);
aoqi@0 915 Class<? extends T> streamClass = clazz.asSubclass(type);
aoqi@0 916
aoqi@0 917 // Since the ClassLoader should cache the class, this isn't
aoqi@0 918 // as expensive as it looks.
aoqi@0 919 return streamClass.newInstance();
aoqi@0 920
aoqi@0 921 }
aoqi@0 922
aoqi@0 923 TCKind getJavaCharTCKind() {
aoqi@0 924 return TCKind.tk_wchar;
aoqi@0 925 }
aoqi@0 926 }

mercurial