- /*
- * @(#)CDRInputStream_1_0.java 1.83 04/01/13
- *
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
- /*
- * Licensed Materials - Property of IBM
- * RMI-IIOP v1.0
- * Copyright IBM Corp. 1998 1999 All Rights Reserved
- *
- * US Government Users Restricted Rights - Use, duplication or
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- package com.sun.corba.se.internal.iiop;
- import java.io.IOException;
- import java.io.Serializable;
- import java.io.ByteArrayInputStream;
- import java.io.ObjectInputStream;
- import java.io.IOException;
- import java.io.StreamCorruptedException;
- import java.io.OptionalDataException;
- import java.io.IOException;
- import java.util.Stack;
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import java.math.BigDecimal;
- import java.rmi.Remote;
- import java.rmi.StubNotFoundException;
- import org.omg.CORBA.SystemException;
- import org.omg.CORBA.INTERNAL;
- import org.omg.CORBA.MARSHAL;
- import org.omg.CORBA.DATA_CONVERSION;
- import org.omg.CORBA.BAD_PARAM;
- import org.omg.CORBA.Object;
- import org.omg.CORBA.Principal;
- import org.omg.CORBA.TypeCode;
- import org.omg.CORBA.Any;
- import org.omg.CORBA.portable.Delegate;
- import org.omg.CORBA.portable.ValueBase;
- import org.omg.CORBA.portable.IndirectionException;
- import org.omg.CORBA.NO_IMPLEMENT;
- import org.omg.CORBA.CompletionStatus;
- import org.omg.CORBA.TCKind;
- import org.omg.CORBA.TypeCodePackage.BadKind;
- import org.omg.CORBA.CustomMarshal;
- import org.omg.CORBA.TypeCode;
- import org.omg.CORBA.Principal;
- import org.omg.CORBA.Any;
- import org.omg.CORBA.portable.BoxedValueHelper;
- import org.omg.CORBA.portable.ValueFactory;
- import org.omg.CORBA.portable.CustomValue;
- import org.omg.CORBA.portable.StreamableValue;
- import org.omg.CORBA.portable.ObjectImpl;
- import org.omg.CORBA.MARSHAL;
- import javax.rmi.PortableRemoteObject;
- import javax.rmi.CORBA.Tie;
- import javax.rmi.CORBA.Util;
- import javax.rmi.CORBA.ValueHandler;
- import com.sun.corba.se.internal.corba.ServerDelegate;
- import com.sun.corba.se.internal.corba.PrincipalImpl;
- import com.sun.corba.se.internal.corba.TypeCodeImpl;
- import com.sun.corba.se.internal.core.IOR;
- import com.sun.corba.se.internal.core.SubcontractRegistry;
- import com.sun.corba.se.internal.core.ServerSubcontract;
- import com.sun.corba.se.internal.core.ClientSubcontract;
- import com.sun.corba.se.internal.core.GIOPVersion;
- import com.sun.corba.se.internal.core.ORBVersionImpl;
- import com.sun.corba.se.internal.core.ORBVersion;
- import com.sun.corba.se.internal.core.CodeSetConversion;
- import com.sun.corba.se.internal.util.Utility;
- import com.sun.corba.se.internal.orbutil.RepositoryIdStrings;
- import com.sun.corba.se.internal.orbutil.RepositoryIdInterface;
- import com.sun.corba.se.internal.orbutil.RepositoryIdUtility;
- import com.sun.corba.se.internal.orbutil.RepositoryIdFactory;
- import com.sun.corba.se.internal.orbutil.ORBUtility;
- import com.sun.corba.se.internal.orbutil.CacheTable;
- import com.sun.corba.se.internal.orbutil.MinorCodes;
- import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;
- import com.sun.org.omg.CORBA.portable.ValueHelper;
- import com.sun.org.omg.SendingContext.CodeBase;
- import java.security.AccessController;
- import java.security.PrivilegedExceptionAction;
- import java.security.PrivilegedActionException;
- public class CDRInputStream_1_0 extends CDRInputStreamBase
- implements RestorableInputStream
- {
- private static final String kReadMethod = "read";
- private static final int maxBlockLength = 0x7fffff00;
- protected BufferManagerRead bufferManagerRead;
- protected ByteBufferWithInfo bbwi;
- // Set to the ORB's transportDebugFlag value. This value is
- // used if the ORB is null.
- private boolean debug = false;
- protected boolean littleEndian;
- protected com.sun.corba.se.internal.corba.ORB orb;
- protected ValueHandler valueHandler = null;
- // Value cache
- private CacheTable valueCache = null;
- // Repository ID cache
- private CacheTable repositoryIdCache = null;
- // codebase cache
- private CacheTable codebaseCache = null;
- // Current Class Stack (repository Ids of current class being read)
- // private Stack currentStack = null;
- // Length of current chunk, or a large positive number if not in a chunk
- protected int blockLength = maxBlockLength;
- // Read end flag (value nesting depth)
- protected int end_flag = 0;
- // Beginning with the resolution to interop issue 4328,
- // only enclosing chunked valuetypes are taken into account
- // when computing the nesting level. However, we still need
- // the old computation around for interoperability with our
- // older ORBs.
- private int chunkedValueNestingLevel = 0;
- // Flag used to determine whether blocksize was zero
- // private int checkForNullBlock = -1;
- // In block flag
- // private boolean inBlock = false;
- // Indicates whether we are inside a value
- // private boolean outerValueDone = true;
- // Int used by read_value(Serializable) that is set by this class
- // before calling ValueFactory.read_value
- protected int valueIndirection = 0;
- // Int set by readStringOrIndirection to communicate the actual
- // offset of the string length field back to the caller
- protected int stringIndirection = 0;
- // Flag indicating whether we are unmarshalling a chunked value
- protected boolean isChunked = false;
- // Repository ID handlers
- private RepositoryIdUtility repIdUtil;
- private RepositoryIdStrings repIdStrs;
- // Code set converters (created when first needed)
- private CodeSetConversion.BTCConverter charConverter;
- private CodeSetConversion.BTCConverter wcharConverter;
- // Template method
- public CDRInputStreamBase dup() {
- CDRInputStreamBase result;
- try {
- result = (CDRInputStreamBase)this.getClass().newInstance();
- } catch (InstantiationException e) {
- debugPrintThrowable(e);
- throw new INTERNAL();
- } catch (IllegalAccessException e) {
- debugPrintThrowable(e);
- throw new INTERNAL();
- }
- result.init(this.orb,
- this.bbwi.buf,
- this.bbwi.buflen,
- this.littleEndian,
- this.bufferManagerRead);
- ((CDRInputStream_1_0)result).bbwi.index = this.bbwi.index;
- return result;
- }
- /**
- * NOTE: size passed to init means buffer size
- */
- public void init(org.omg.CORBA.ORB orb,
- byte[] data,
- int size,
- boolean littleEndian,
- BufferManagerRead bufferManager)
- {
- this.orb = (com.sun.corba.se.internal.corba.ORB)orb;
- this.littleEndian = littleEndian;
- this.bufferManagerRead = bufferManager;
- this.bbwi = new ByteBufferWithInfo(data, 0);
- this.bbwi.buflen = size;
- this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();
- // The ORB seems to be null in some cases due to primitive
- // TypeCodeImpls (which are singletons) not having ORB instances.
- if (orb != null)
- debug = ((com.sun.corba.se.internal.corba.ORB)orb).transportDebugFlag;
- }
- // See description in CDRInputStream
- void performORBVersionSpecificInit() {
- createRepositoryIdHandlers();
- }
- private final void createRepositoryIdHandlers()
- {
- if (orb != null) {
- // Get the appropriate versions based on the ORB version. The
- // ORB versioning info is only in the corba ORB.
- repIdUtil = RepositoryIdFactory.getRepIdUtility(orb);
- repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb);
- } else {
- // Get the latest versions
- repIdUtil = RepositoryIdFactory.getRepIdUtility();
- repIdStrs = RepositoryIdFactory.getRepIdStringsFactory();
- }
- }
- public GIOPVersion getGIOPVersion() {
- return GIOPVersion.V1_0;
- }
- protected final int computeAlignment(int align) {
- if (align > 1) {
- int incr = bbwi.index & (align - 1);
- if (incr != 0)
- return align - incr;
- }
- return 0;
- }
- public int getSize()
- {
- return bbwi.index;
- }
- protected void checkBlockLength() {
- // Since chunks can end at arbitrary points (though not within
- // primitive CDR types, arrays of primitives, strings, or wstrings),
- // we must check here for termination of the current chunk.
- // This also takes care of terminating an open chunk when a
- // value tag is encountered.
- if (!isChunked)
- return;
- if (blockLength == get_offset()) {
- blockLength = maxBlockLength;
- start_block();
- } else if (blockLength < get_offset()) {
- // current chunk has overflowed
- throw new MARSHAL("Chunk overflow at offset " + get_offset(),
- com.sun.corba.se.internal.orbutil.MinorCodes.CHUNK_OVERFLOW,
- CompletionStatus.COMPLETED_NO);
- }
- }
- protected void alignAndCheck(int align, int n) {
- checkBlockLength();
- bbwi.index += computeAlignment(align);
- if (bbwi.index + n > bbwi.buflen)
- grow(align, n);
- }
- //
- // This can be overridden....
- //
- protected void grow(int align, int n) {
- bbwi.needed = n;
- bbwi = bufferManagerRead.underflow(bbwi);
- }
- //
- // Marshal primitives.
- //
- public final void consumeEndian() {
- littleEndian = read_boolean();
- }
- // No such type in java
- public final double read_longdouble() {
- throw new NO_IMPLEMENT(com.sun.corba.se.internal.orbutil.MinorCodes.SEND_DEFERRED_NOTIMPLEMENTED,
- CompletionStatus.COMPLETED_MAYBE);
- }
- public final boolean read_boolean() {
- return (read_octet() != 0);
- }
- public final char read_char() {
- alignAndCheck(1, 1);
- return getConvertedChars(1, getCharConverter())[0];
- }
- public char read_wchar() {
- // Don't allow transmission of wchar/wstring data with
- // foreign ORBs since it's against the spec.
- if (ORBUtility.isForeignORB((com.sun.corba.se.internal.corba.ORB)orb)) {
- throw new MARSHAL(MinorCodes.WCHAR_DATA_IN_GIOP_1_0,
- CompletionStatus.COMPLETED_MAYBE);
- }
- // If we're talking to one of our legacy ORBs, do what
- // they did:
- int b1, b2;
- alignAndCheck(2, 2);
- if (littleEndian) {
- b2 = bbwi.buf[bbwi.index++] & 0x00FF;
- b1 = bbwi.buf[bbwi.index++] & 0x00FF;
- } else {
- b1 = bbwi.buf[bbwi.index++] & 0x00FF;
- b2 = bbwi.buf[bbwi.index++] & 0x00FF;
- }
- return (char)((b1 << 8) + (b2 << 0));
- }
- public final byte read_octet() {
- alignAndCheck(1, 1);
- return bbwi.buf[bbwi.index++];
- }
- public final short read_short() {
- int b1, b2;
- alignAndCheck(2, 2);
- if (littleEndian) {
- b2 = (bbwi.buf[bbwi.index++] << 0) & 0x000000FF;
- b1 = (bbwi.buf[bbwi.index++] << 8) & 0x0000FF00;
- } else {
- b1 = (bbwi.buf[bbwi.index++] << 8) & 0x0000FF00;
- b2 = (bbwi.buf[bbwi.index++] << 0) & 0x000000FF;
- }
- return (short)(b1 | b2);
- }
- public final short read_ushort() {
- return read_short();
- }
- public final int read_long() {
- int b1, b2, b3, b4;
- alignAndCheck(4, 4);
- if (littleEndian) {
- b4 = bbwi.buf[bbwi.index++] & 0xFF;
- b3 = bbwi.buf[bbwi.index++] & 0xFF;
- b2 = bbwi.buf[bbwi.index++] & 0xFF;
- b1 = bbwi.buf[bbwi.index++] & 0xFF;
- } else {
- b1 = bbwi.buf[bbwi.index++] & 0xFF;
- b2 = bbwi.buf[bbwi.index++] & 0xFF;
- b3 = bbwi.buf[bbwi.index++] & 0xFF;
- b4 = bbwi.buf[bbwi.index++] & 0xFF;
- }
- return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
- }
- public final int read_ulong() {
- return read_long();
- }
- public final long read_longlong() {
- long i1, i2;
- alignAndCheck(8, 8);
- if (littleEndian) {
- i2 = read_long() & 0xFFFFFFFFL;
- i1 = (long)read_long() << 32;
- } else {
- i1 = (long)read_long() << 32;
- i2 = read_long() & 0xFFFFFFFFL;
- }
- return (i1 | i2);
- }
- public final long read_ulonglong() {
- return read_longlong();
- }
- public final float read_float() {
- return Float.intBitsToFloat(read_long());
- }
- public final double read_double() {
- return Double.longBitsToDouble(read_longlong());
- }
- protected final void checkForNegativeLength(int length) {
- if (length < 0)
- throw new MARSHAL("Bad string length: " + length,
- MinorCodes.NEGATIVE_STRING_LENGTH,
- CompletionStatus.COMPLETED_MAYBE);
- }
- protected final String readStringOrIndirection(boolean allowIndirection) {
- int len = read_long();
- //
- // Check for indirection
- //
- if (allowIndirection) {
- if (len == 0xffffffff)
- return null;
- else
- stringIndirection = get_offset() - 4;
- }
- checkForNegativeLength(len);
- if (orb != null && ORBUtility.isLegacyORB((com.sun.corba.se.internal.corba.ORB)orb))
- return legacyReadString(len);
- else
- return internalReadString(len);
- }
- private final String internalReadString(int len) {
- // Workaround for ORBs which send string lengths of
- // zero to mean empty string.
- // IMPORTANT: Do not replace 'new String("")' with "", it may result
- // in a Serialization bug (See serialization.zerolengthstring) and
- // bug id: 4728756 for details
- if (len == 0)
- return new String("");
- char[] result = getConvertedChars(len - 1, getCharConverter());
- // Skip over the 1 byte null
- read_octet();
- return new String(result, 0, getCharConverter().getNumChars());
- }
- private final String legacyReadString(int len) {
- //
- // Workaround for ORBs which send string lengths of
- // zero to mean empty string.
- //
- // IMPORTANT: Do not replace 'new String("")' with "", it may result
- // in a Serialization bug (See serialization.zerolengthstring) and
- // bug id: 4728756 for details
- if (len == 0)
- return new String("");
- len--;
- char[] c = new char[len];
- int n = 0;
- while (n < len) {
- int avail;
- int bytes;
- int wanted;
- avail = bbwi.buflen - bbwi.index;
- if (avail <= 0) {
- grow(1, 1);
- avail = bbwi.buflen - bbwi.index;
- }
- wanted = len - n;
- bytes = (wanted < avail) ? wanted : avail;
- for (int i=0; i<bytes; i++) {
- c[n+i] = (char) (bbwi.buf[bbwi.index+i] & 0xFF);
- }
- bbwi.index += bytes;
- n += bytes;
- }
- //
- // Skip past terminating null byte
- //
- if (bbwi.index + 1 > bbwi.buflen)
- alignAndCheck(1, 1);
- bbwi.index++;
- return new String(c);
- }
- public final String read_string() {
- return readStringOrIndirection(false);
- }
- public String read_wstring() {
- // Don't allow transmission of wchar/wstring data with
- // foreign ORBs since it's against the spec.
- if (ORBUtility.isForeignORB((com.sun.corba.se.internal.corba.ORB)orb)) {
- throw new MARSHAL(MinorCodes.WCHAR_DATA_IN_GIOP_1_0,
- CompletionStatus.COMPLETED_MAYBE);
- }
- int len = read_long();
- //
- // Workaround for ORBs which send string lengths of
- // zero to mean empty string.
- //
- // IMPORTANT: Do not replace 'new String("")' with "", it may result
- // in a Serialization bug (See serialization.zerolengthstring) and
- // bug id: 4728756 for details
- if (len == 0)
- return new String("");
- checkForNegativeLength(len);
- len--;
- char[] c = new char[len];
- for (int i = 0; i < len; i++)
- c[i] = read_wchar();
- // skip the two null terminator bytes
- read_wchar();
- // bbwi.index += 2;
- return new String(c);
- }
- public final void read_octet_array(byte[] b, int offset, int length) {
- if ( b == null )
- throw new BAD_PARAM();
- // Must call alignAndCheck at least once to ensure
- // we aren't at the end of a chunk. Of course, we
- // should only call it if we actually need to read
- // something, otherwise we might end up with an
- // exception at the end of the stream.
- if (length == 0)
- return;
- alignAndCheck(1, 1);
- int n = offset;
- while (n < length+offset) {
- int avail;
- int bytes;
- int wanted;
- avail = bbwi.buflen - bbwi.index;
- if (avail <= 0) {
- grow(1, 1);
- avail = bbwi.buflen - bbwi.index;
- }
- wanted = (length + offset) - n;
- bytes = (wanted < avail) ? wanted : avail;
- System.arraycopy(bbwi.buf, bbwi.index, b, n, bytes);
- bbwi.index += bytes;
- n += bytes;
- }
- }
- public Principal read_Principal() {
- int len = read_long();
- byte[] pvalue = new byte[len];
- read_octet_array(pvalue,0,len);
- Principal p = new PrincipalImpl();
- p.name(pvalue);
- return p;
- }
- public TypeCode read_TypeCode() {
- TypeCodeImpl tc = new TypeCodeImpl(orb);
- tc.read_value(parent);
- return tc;
- }
- public Any read_any() {
- Any any = orb.create_any();
- TypeCodeImpl tc = new TypeCodeImpl(orb);
- // read off the typecode
- // REVISIT We could avoid this try-catch if we could peek the typecode kind
- // off this stream and see if it is a tk_value.
- // Looking at the code we know that for tk_value the Any.read_value() below
- // ignores the tc argument anyway (except for the kind field).
- // But still we would need to make sure that the whole typecode, including
- // encapsulations, is read off.
- try {
- tc.read_value(parent);
- } catch (MARSHAL ex) {
- if (tc.kind().value() != TCKind._tk_value)
- throw ex;
- // We can be sure that the whole typecode encapsulation has been read off.
- //System.out.println("Error reading value tc " + tc + ", falling back on ValueHandler");
- debugPrintThrowable(ex);
- }
- // read off the value of the any
- any.read_value(parent, tc);
- return any;
- }
- public org.omg.CORBA.Object read_Object() {
- return read_Object(null);
- }
- // ------------ RMI related methods --------------------------
- // IDL to Java ptc-00-01-08 1.21.4.1
- //
- // The clz argument to read_Object can be either a stub
- // Class or the "Class object for the RMI/IDL interface type
- // that is statically expected."
- public org.omg.CORBA.Object read_Object(Class clz) {
- IOR ior = new IOR(parent) ;
- if (clz == null || ObjectImpl.class.isAssignableFrom(clz)) {
- // We were given null or a stub class
- return CDRInputStream_1_0.internalIORToObject(ior, clz, orb);
- } else {
- // We must have been given the Class object for the RMI/IDL
- // interface
- try {
- Class stubClass
- = Utility.loadStubClass(ior.getTypeId(),
- ior.getCodebase(),
- clz);
- return CDRInputStream_1_0.internalIORToObject(ior,
- stubClass,
- orb);
- } catch (ClassNotFoundException cnfe) {
- // Failed to load the stub class.
- throw new MARSHAL("Failed to load stub for "
- + ior.getTypeId()
- + " with Class "
- + (clz == null ? "null" : clz.getName()),
- MinorCodes.READ_OBJECT_EXCEPTION,
- CompletionStatus.COMPLETED_NO);
- }
- }
- }
- /*
- * This is used as a general utility (e.g., the PortableInterceptor
- * implementation uses it. NOTE: The Class passed in must be the
- * Stub Class.
- */
- public static org.omg.CORBA.Object internalIORToObject(
- IOR ior, Class stubClass, com.sun.corba.se.internal.core.ORB orb)
- {
- if (ior.is_nil())
- return null;
- if (ior.isLocal()) {
- // Ok so far. Can we get a valid servant?
- ServerSubcontract sc = ior.getServerSubcontract() ;
- if (sc != null && (sc.isServantSupported())) {
- java.lang.Object servant = sc.getServant(ior);
- if (servant != null ) {
- // Got a valid servant. Is it a Tie?
- if (servant instanceof Tie) {
- // Yes, so it is a local servant. Load a stub
- // for it using the codebase from the IOR and
- // the delegate from the tie.
- String codebase = ior.getCodebase();
- org.omg.CORBA.Object objref = (org.omg.CORBA.Object)
- Utility.loadStub((Tie)servant,stubClass,codebase,false);
- // If we managed to load a stub, return it, otherwise we
- // must fail...
- if (objref != null) {
- return objref;
- } else {
- throw new MARSHAL(
- com.sun.corba.se.internal.orbutil.MinorCodes.READ_OBJECT_EXCEPTION,
- CompletionStatus.COMPLETED_NO);
- }
- } else if (servant instanceof org.omg.CORBA.Object) {
- if (servant instanceof org.omg.CORBA.portable.InvokeHandler) {
- // Old ImplBase stubs are CORBA.Objects.
- // However, they are not stubs.
- return createDelegate(ior, stubClass, orb);
- } else {
- // No, so assume IDL style stub...
- return (org.omg.CORBA.Object) servant;
- }
- } else
- throw new INTERNAL( MinorCodes.BAD_SERVANT_READ_OBJECT,
- CompletionStatus.COMPLETED_NO ) ;
- }
- }
- }
- return createDelegate(ior, stubClass, orb);
- }
- protected static org.omg.CORBA.Object createDelegate(
- IOR ior, Class stubClass, com.sun.corba.se.internal.core.ORB orb)
- {
- SubcontractRegistry registry = orb.getSubcontractRegistry() ;
- ObjectKeyTemplate temp = ior.getProfile().getTemplate().getObjectKeyTemplate() ;
- ClientSubcontract rep = registry.getClientSubcontract(temp);
- rep.unmarshal(ior);
- rep.setOrb(orb);
- // Load stub, set the delegate and return it...
- return loadStub(ior,stubClass,(Delegate)rep);
- }
- protected static ObjectImpl loadStub(IOR ior,
- Class stubClass,
- Delegate delegate) {
- // Use the stubClass, if we have it...
- if (stubClass != null) {
- try {
- return newStub(stubClass,delegate);
- } catch (Throwable e) {
- if (e instanceof ThreadDeath) {
- throw (ThreadDeath) e;
- }
- }
- } else {
- // Try to load from the ior...
- try {
- String repID = ior.getTypeId();
- // If the repID is "", fall thru to returning the default
- // stub, otherwise try to load the class...
- if (repID.length() > 0) {
- String codebase = ior.getCodebase();
- Class clz = Utility.loadStubClass(repID, codebase, null); //d11638
- return newStub(clz,delegate);
- }
- } catch (Throwable e) {
- if (e instanceof ThreadDeath) {
- throw (ThreadDeath) e;
- }
- }
- // Return the "default" stub...
- ObjectImpl objref = new org.omg.CORBA_2_3.portable.ObjectImpl() {
- public String[] _ids() {
- String[] typeids = new String[1];
- typeids[0] = "IDL:omg.org/CORBA/Object:1.0";
- return typeids;
- }
- };
- objref._set_delegate(delegate);
- return objref;
- }
- // We failed...
- throw new MARSHAL(com.sun.corba.se.internal.orbutil.MinorCodes.READ_OBJECT_EXCEPTION,
- CompletionStatus.COMPLETED_NO);
- }
- protected static ObjectImpl newStub(Class stubClass,Delegate delegate)
- throws InstantiationException,
- IllegalAccessException,
- NoSuchMethodException,
- InvocationTargetException {
- // What kind of stub do we have?
- if (java.rmi.Remote.class.isAssignableFrom(stubClass)) {
- // RMI. Instantiate, set delegate and return...
- ObjectImpl objref = (ObjectImpl) stubClass.newInstance();
- objref._set_delegate(delegate);
- return objref;
- }
- // RMI Abstract OR IDL. Instantiate, set delegate and return...
- try {
- // Try creating the stub using the default constructor...
- ObjectImpl result = (ObjectImpl)stubClass.newInstance();
- result._set_delegate(delegate);
- return result;
- } catch (Throwable e) {
- if (e instanceof ThreadDeath) {
- throw (ThreadDeath) e;
- }
- }
- // Try creating the stub using the delegate constructor...
- Class[] intArgsClass = new Class[] {org.omg.CORBA.portable.Delegate.class};
- java.lang.Object[]intArgs = new java.lang.Object[] {delegate};
- java.lang.reflect.Constructor intArgsConstructor;
- intArgsConstructor = stubClass.getConstructor(intArgsClass);
- return (ObjectImpl)intArgsConstructor.newInstance(intArgs);
- }
- public java.lang.Object read_abstract_interface() {
- return read_abstract_interface(null);
- }
- public java.lang.Object read_abstract_interface(java.lang.Class clz) {
- boolean object = read_boolean();
- if (object) {
- return read_Object(clz);
- } else {
- return read_value();
- }
- }
- public Serializable read_value() {
- // Read value tag
- int vType = readValueTag();
- if (vType == 0)
- return null; // value is null
- else if (vType == 0xffffffff) { // Indirection tag
- int indirection = read_long() + get_offset() - 4;
- if (valueCache != null && valueCache.containsVal(indirection))
- {
- java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection);
- return cachedValue;
- }
- else {
- throw new IndirectionException(indirection);
- }
- }
- else {
- int indirection = get_offset() - 4;
- // end_block();
- boolean saveIsChunked = isChunked;
- isChunked = repIdUtil.isChunkedEncoding(vType);
- java.lang.Object value = null;
- String codebase_URL = null;
- if (repIdUtil.isCodeBasePresent(vType)){
- codebase_URL = read_codebase_URL();
- }
- // Read repository id
- String repositoryIDString = null;
- switch(repIdUtil.getTypeInfo(vType)){
- case RepositoryIdUtility.NO_TYPE_INFO :
- throw new MARSHAL("read_value() with no repository ID info",
- MinorCodes.READ_VALUE_AND_NO_REP_ID,
- CompletionStatus.COMPLETED_MAYBE);
- case RepositoryIdUtility.SINGLE_REP_TYPE_INFO :
- repositoryIDString = read_repositoryId();
- break;
- case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO :
- repositoryIDString = read_repositoryIds();
- break;
- }
- // indirection = get_offset();
- start_block();
- end_flag--;
- if (isChunked)
- chunkedValueNestingLevel--;
- if (repositoryIDString.equals(repIdStrs.getWStringValueRepId()))
- {
- value = read_wstring();
- }
- else if (repositoryIDString.equals(repIdStrs.getClassDescValueRepId())) {
- // read the class either with the wrong RepId or the
- // correct RepId for the classDesc
- value = readClass();
- }
- else {
- Class valueClass = getClassFromString(repositoryIDString,
- codebase_URL);
- if ((valueClass != null) &&
- org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(valueClass)) {
- value = readIDLValue(indirection, repositoryIDString, valueClass, codebase_URL);
- } else {
- try {
- // cannot cache this since this value will be different
- if (valueHandler == null) {
- valueHandler = ORBUtility.createValueHandler(orb);
- }
- value = valueHandler.readValue(parent, indirection, valueClass,
- repositoryIDString, getCodeBase());
- } catch(Exception ex) {
- debugPrintThrowable(ex);
- throw new org.omg.CORBA.MARSHAL("Unable to read value from underlying bridge : "
- + ex.getMessage(),
- MinorCodes.VALUEHANDLER_READ_EXCEPTION,
- CompletionStatus.COMPLETED_MAYBE);
- } catch(Error e) {
- debugPrintThrowable(e);
- throw new org.omg.CORBA.MARSHAL("Unable to read value from underlying bridge : "
- + e.getMessage(),
- MinorCodes.VALUEHANDLER_READ_ERROR,
- CompletionStatus.COMPLETED_MAYBE);
- }
- }
- }
- handleEndOfValue();
- readEndTag();
- // Put into valueCache
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(value, indirection);
- // allow for possible continuation chunk
- isChunked = saveIsChunked;
- start_block();
- return (java.io.Serializable)value;
- }
- }
- public Serializable read_value(Class expectedType) {
- // Read value tag
- int vType = readValueTag();
- if (vType == 0)
- return null; // value is null
- else if (vType == 0xffffffff) { // Indirection tag
- int indirection = read_long() + get_offset() - 4;
- if (valueCache != null && valueCache.containsVal(indirection))
- {
- java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection);
- return cachedValue;
- }
- else {
- throw new IndirectionException(indirection);
- }
- }
- else {
- int indirection = get_offset() - 4;
- // end_block();
- boolean saveIsChunked = isChunked;
- isChunked = repIdUtil.isChunkedEncoding(vType);
- java.lang.Object value = null;
- String codebase_URL = null;
- if (repIdUtil.isCodeBasePresent(vType)){
- codebase_URL = read_codebase_URL();
- }
- // Read repository id
- String repositoryIDString = null;
- switch(repIdUtil.getTypeInfo(vType)){
- case RepositoryIdUtility.NO_TYPE_INFO :
- // Throw an exception if we have no repository ID info and
- // no expectedType to work with. Otherwise, how would we
- // know what to unmarshal?
- if (expectedType == null)
- throw new MARSHAL("Expected type null and no repository ID info",
- MinorCodes.EXPECTED_TYPE_NULL_AND_NO_REP_ID,
- CompletionStatus.COMPLETED_MAYBE);
- repositoryIDString = repIdStrs.createForAnyType(expectedType);
- break;
- case RepositoryIdUtility.SINGLE_REP_TYPE_INFO :
- repositoryIDString = read_repositoryId();
- break;
- case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO :
- repositoryIDString = read_repositoryIds();
- break;
- }
- // indirection = get_offset();
- start_block();
- end_flag--;
- if (isChunked)
- chunkedValueNestingLevel--;
- if (repositoryIDString.equals(repIdStrs.getWStringValueRepId()))
- {
- value = read_wstring();
- }
- else if (repositoryIDString.equals(repIdStrs.getClassDescValueRepId()))
- {
- // read in the class whether with the old ClassDesc or the
- // new one
- value = readClass();
- }
- else {
- Class valueClass = expectedType;
- // By this point, either the expectedType or repositoryIDString
- // is guaranteed to be non-null.
- if (expectedType == null ||
- !repositoryIDString.equals(repIdStrs.createForAnyType(expectedType))) {
- valueClass = getClassFromString(repositoryIDString,
- codebase_URL,
- expectedType);
- }
- if ((valueClass != null) &&
- org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(valueClass)) {
- value = readIDLValue(indirection, repositoryIDString, valueClass, codebase_URL);
- } else {
- try {
- if (valueHandler == null) {
- valueHandler = ORBUtility.createValueHandler(orb);
- }
- value = valueHandler.readValue(parent, indirection, valueClass,
- repositoryIDString, getCodeBase());
- } catch(Exception ex) {
- debugPrintThrowable(ex);
- throw new org.omg.CORBA.MARSHAL("Unable to read value from underlying bridge : "
- + ex.getMessage(),
- MinorCodes.VALUEHANDLER_READ_EXCEPTION,
- CompletionStatus.COMPLETED_MAYBE);
- } catch(Error e){
- debugPrintThrowable(e);
- throw new org.omg.CORBA.MARSHAL("Unable to read value from underlying bridge : "
- + e.getMessage(),
- MinorCodes.VALUEHANDLER_READ_ERROR,
- CompletionStatus.COMPLETED_MAYBE);
- }
- }
- }
- handleEndOfValue();
- readEndTag();
- // Put into valueCache
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(value, indirection);
- // allow for possible continuation chunk
- isChunked = saveIsChunked;
- start_block();
- return (java.io.Serializable)value;
- }
- }
- public Serializable read_value(BoxedValueHelper factory) {
- // Read value tag
- int vType = readValueTag();
- if (vType == 0)
- return null; // value is null
- else if (vType == 0xffffffff) { // Indirection tag
- int indirection = read_long() + get_offset() - 4;
- if (valueCache != null && valueCache.containsVal(indirection))
- {
- java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection);
- return cachedValue;
- }
- else {
- throw new IndirectionException(indirection);
- }
- }
- else {
- int indirection = get_offset() - 4;
- // end_block();
- boolean saveIsChunked = isChunked;
- isChunked = repIdUtil.isChunkedEncoding(vType);
- java.lang.Object value = null;
- String codebase_URL = null;
- if (repIdUtil.isCodeBasePresent(vType)){
- codebase_URL = read_codebase_URL();
- }
- // Read repository id
- String repositoryIDString = null;
- switch(repIdUtil.getTypeInfo(vType)){
- case RepositoryIdUtility.NO_TYPE_INFO :
- throw new org.omg.CORBA.MARSHAL("No class description available (value_tag indicates no type information present)");
- case RepositoryIdUtility.SINGLE_REP_TYPE_INFO :
- repositoryIDString = read_repositoryId();
- break;
- case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO :
- repositoryIDString = read_repositoryIds();
- break;
- }
- // Compare rep. ids to see if we should use passed helper
- if (!repositoryIDString.equals(factory.get_id()))
- factory = Utility.getHelper(null, codebase_URL, repositoryIDString);
- start_block();
- end_flag--;
- if (isChunked)
- chunkedValueNestingLevel--;
- if (factory instanceof ValueHelper) {
- value = readIDLValueWithHelper((ValueHelper)factory, indirection);
- } else {
- valueIndirection = indirection; // for callback
- value = factory.read_value(parent);
- }
- handleEndOfValue();
- readEndTag();
- // Put into valueCache
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(value, indirection);
- // allow for possible continuation chunk
- isChunked = saveIsChunked;
- start_block();
- return (java.io.Serializable)value;
- }
- }
- private boolean isCustomType(ValueHelper helper) {
- try{
- TypeCode tc = helper.get_type();
- int kind = tc.kind().value();
- if (kind == TCKind._tk_value) {
- return (tc.type_modifier() == org.omg.CORBA.VM_CUSTOM.value);
- }
- }
- catch(BadKind ex) {
- throw new org.omg.CORBA.MARSHAL(MinorCodes.BAD_KIND,
- CompletionStatus.COMPLETED_MAYBE);
- }
- return false;
- }
- // This method is actually called indirectly by
- // read_value(String repositoryId).
- // Therefore, it is not a truly independent read call that handles
- // header information itself.
- public java.io.Serializable read_value(java.io.Serializable value) {
- // Put into valueCache using valueIndirection
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(value, valueIndirection);
- if (value instanceof StreamableValue)
- ((StreamableValue)value)._read(parent);
- else if (value instanceof CustomValue)
- ((CustomValue)value).unmarshal(parent);
- return value;
- }
- public java.io.Serializable read_value(java.lang.String repositoryId) {
- // if (inBlock)
- // end_block();
- // Read value tag
- int vType = readValueTag();
- if (vType == 0)
- return null; // value is null
- else if (vType == 0xffffffff) { // Indirection tag
- int indirection = read_long() + get_offset() - 4;
- if (valueCache != null && valueCache.containsVal(indirection))
- {
- java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection);
- return cachedValue;
- }
- else {
- throw new IndirectionException(indirection);
- }
- }
- else {
- int indirection = get_offset() - 4;
- // end_block();
- boolean saveIsChunked = isChunked;
- isChunked = repIdUtil.isChunkedEncoding(vType);
- java.lang.Object value = null;
- String codebase_URL = null;
- if (repIdUtil.isCodeBasePresent(vType)){
- codebase_URL = read_codebase_URL();
- }
- // Read repository id
- String repositoryIDString = null;
- switch(repIdUtil.getTypeInfo(vType)){
- case RepositoryIdUtility.NO_TYPE_INFO :
- repositoryIDString = repositoryId;
- break;
- case RepositoryIdUtility.SINGLE_REP_TYPE_INFO :
- repositoryIDString = read_repositoryId();
- break;
- case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO :
- repositoryIDString = read_repositoryIds();
- break;
- }
- ValueFactory factory = Utility.getFactory(null, codebase_URL, orb, repositoryIDString);
- start_block();
- end_flag--;
- if (isChunked)
- chunkedValueNestingLevel--;
- valueIndirection = indirection; // for callback
- value = factory.read_value(parent);
- handleEndOfValue();
- readEndTag();
- // Put into valueCache
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(value, indirection);
- // allow for possible continuation chunk
- isChunked = saveIsChunked;
- start_block();
- return (java.io.Serializable)value;
- }
- }
- private Class readClass() {
- String codebases = null, classRepId = null;
- if (orb == null ||
- ORBVersionImpl.FOREIGN.equals(orb.getORBVersion()) ||
- ORBVersionImpl.NEWER.compareTo(orb.getORBVersion()) <= 0) {
- codebases = (String)read_value(java.lang.String.class);
- classRepId = (String)read_value(java.lang.String.class);
- } else {
- // Pre-Merlin/J2EE 1.3 ORBs wrote the repository ID
- // and codebase strings in the wrong order.
- classRepId = (String)read_value(java.lang.String.class);
- codebases = (String)read_value(java.lang.String.class);
- }
- if (debug) {
- debugPrintMessage("readClass codebases: "
- + codebases
- + " rep Id: "
- + classRepId);
- }
- Class cl = null;
- RepositoryIdInterface repositoryID
- = repIdStrs.getFromString(classRepId);
- try {
- cl = repositoryID.getClassFromType(codebases);
- } catch(ClassNotFoundException cnfe){
- debugPrintThrowable(cnfe);
- throw new org.omg.CORBA.MARSHAL("Unable to load Class "
- + repositoryID.getClassName()
- + " : " + cnfe.getMessage(),
- MinorCodes.CNFE_READ_CLASS,
- CompletionStatus.COMPLETED_MAYBE);
- }
- catch(MalformedURLException me){
- debugPrintThrowable(me);
- throw new org.omg.CORBA.MARSHAL("Unable to load Class "
- + repositoryID.getClassName()
- + " : " + me.getMessage(),
- MinorCodes.MALFORMED_URL,
- CompletionStatus.COMPLETED_MAYBE);
- }
- return cl;
- }
- private java.lang.Object readIDLValueWithHelper(ValueHelper helper, int indirection) {
- // look for two-argument static read method
- Method readMethod;
- try {
- Class argTypes[] = {org.omg.CORBA.portable.InputStream.class, helper.get_class()};
- readMethod = helper.getClass().getDeclaredMethod(kReadMethod, argTypes);
- }
- catch(NoSuchMethodException nsme) { // must be boxed value helper
- java.lang.Object result = helper.read_value(parent);
- return result;
- }
- // found two-argument read method, so must be non-boxed value...
- // ...create a blank instance
- java.lang.Object val = null;
- try {
- val = helper.get_class().newInstance();
- }
- catch(java.lang.InstantiationException ie){
- debugPrintThrowable(ie);
- throw new org.omg.CORBA.MARSHAL(ie.getMessage());
- }
- catch(IllegalAccessException iae){
- // Value's constructor is protected or private
- //
- // So, use the helper to read the value.
- //
- // NOTE : This means that in this particular case a recursive ref.
- // would fail.
- return helper.read_value(parent);
- }
- // add blank instance to cache table
- if (valueCache == null)
- valueCache = new CacheTable(false);
- valueCache.put(val, indirection);
- // if custom type, call unmarshal method
- if (val instanceof CustomMarshal && isCustomType(helper)) {
- ((CustomMarshal)val).unmarshal(parent);
- return val;
- }
- // call two-argument read method using reflection
- try {
- java.lang.Object args[] = {parent, val};
- readMethod.invoke(helper, args);
- return val;
- }
- catch(IllegalAccessException iae2){
- debugPrintThrowable(iae2);
- throw new org.omg.CORBA.MARSHAL(iae2.getMessage());
- }
- catch(InvocationTargetException ite){
- debugPrintThrowable(ite);
- throw new org.omg.CORBA.MARSHAL(ite.getMessage());
- }
- }
- private java.lang.Object readBoxedIDLEntity(Class clazz, String codebase)
- {
- try {
- ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader());
- final Class helperClass = Utility.loadClassForClass(clazz.getName()+"Helper", codebase,
- clazzLoader, clazz, clazzLoader