cdrinputstream_1_0.java

来自「JAVA 所有包」· Java 代码 · 共 1,977 行 · 第 1/5 页

JAVA
1,977
字号
        // 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                = readRepositoryIds(vType, null, repositoryId);	    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(orb,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 ||            ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||            ORBVersionFactory.getNEWER().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) {            dprint("readClass codebases: " 		   + codebases		   + " rep Id: "		   + classRepId);        }        Class cl = null;        RepositoryIdInterface repositoryID             = repIdStrs.getFromString(classRepId);                try {            cl = repositoryID.getClassFromType(codebases);        } catch(ClassNotFoundException cnfe) {            throw wrapper.cnfeReadClass( CompletionStatus.COMPLETED_MAYBE,		cnfe, repositoryID.getClassName() ) ;        } catch(MalformedURLException me) {	    throw wrapper.malformedUrl( CompletionStatus.COMPLETED_MAYBE,		me, repositoryID.getClassName(), codebases ) ;        }	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) {	    throw wrapper.couldNotInstantiateHelper( ie,		helper.get_class() ) ;	} 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(orb,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) {	    throw wrapper.couldNotInvokeHelperReadMethod( iae2, helper.get_class() ) ;	} catch(InvocationTargetException ite){	    throw wrapper.couldNotInvokeHelperReadMethod( ite, helper.get_class() ) ;	}    }    private java.lang.Object readBoxedIDLEntity(Class clazz, String codebase)    {	Class cls = null ;	try {            ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader());	    cls = Utility.loadClassForClass(clazz.getName()+"Helper", codebase,                                                   clazzLoader, clazz, clazzLoader);	    final Class helperClass = cls ;	    final Class argTypes[] = {org.omg.CORBA.portable.InputStream.class};            // getDeclaredMethod requires RuntimePermission accessDeclaredMembers            // if a different class loader is used (even though the javadoc says otherwise)            Method readMethod = null;            try {                readMethod = (Method)AccessController.doPrivileged(                    new PrivilegedExceptionAction() {                        public java.lang.Object run() throws NoSuchMethodException {                            return helperClass.getDeclaredMethod(kReadMethod, argTypes);                        }                    }                );            } catch (PrivilegedActionException pae) {                // this gets caught below                throw (NoSuchMethodException)pae.getException();            }	    java.lang.Object args[] = {parent};	    return readMethod.invoke(null, args);	} catch (ClassNotFoundException cnfe) {	    throw wrapper.couldNotInvokeHelperReadMethod( cnfe, cls ) ;	} catch(NoSuchMethodException nsme) {	    throw wrapper.couldNotInvokeHelperReadMethod( nsme, cls ) ;	} catch(IllegalAccessException iae) {	    throw wrapper.couldNotInvokeHelperReadMethod( iae, cls ) ;	} catch(InvocationTargetException ite) {	    throw wrapper.couldNotInvokeHelperReadMethod( ite, cls ) ;	}    }    private java.lang.Object readIDLValue(int indirection, String repId,					  Class clazz, String codebase)    {						ValueFactory factory ;	// Always try to find a ValueFactory first, as required by the spec.	// There are some complications here in the IDL 3.0 mapping (see 1.13.8),	// but basically we must always be able to override the DefaultFactory	// or Helper mappings that are also used.  This appears to be the case	// even in the boxed value cases.  The original code only did the lookup	// in the case of class implementing either StreamableValue or CustomValue,	// but abstract valuetypes only implement ValueBase, and really require	// the use of the repId to find a factory (including the DefaultFactory).	try {	    // use new-style OBV support (factory object)	    factory = Utility.getFactory(clazz, codebase, orb, repId);	} catch (MARSHAL marshal) {	    // XXX log marshal at one of the INFO levels	    // Could not get a factory, so try alternatives	    if (!StreamableValue.class.isAssignableFrom(clazz) &&		!CustomValue.class.isAssignableFrom(clazz) &&	        ValueBase.class.isAssignableFrom(clazz)) {		// use old-style OBV support (helper object)		BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId);		if (helper instanceof ValueHelper)		    return readIDLValueWithHelper((ValueHelper)helper, indirection);		else		    return helper.read_value(parent);	    } else {		// must be a boxed IDLEntity, so make a reflective call to the		// helper's static read method...		return readBoxedIDLEntity(clazz, codebase);	    }	}	// If there was no error in getting the factory, use it.	valueIndirection = indirection;  // for callback	return factory.read_value(parent);    }    /**     * End tags are only written for chunked valuetypes.     *     * Before Merlin, our ORBs wrote end tags which took into account     * all enclosing valuetypes.  This was changed by an interop resolution     * (see details around chunkedValueNestingLevel) to only include     * enclosing chunked types.     *     * ORB versioning and end tag compaction are handled here.     */    private void readEndTag() {        if (isChunked) {            // Read the end tag            int anEndTag = read_long();            // End tags should always be negative, and the outermost            // enclosing chunked valuetype should have a -1 end tag.            //            // handleEndOfValue should have assured that we were            // at the end tag position!            if (anEndTag >= 0) {		throw wrapper.positiveEndTag( CompletionStatus.COMPLETED_MAYBE,		    new Integer(anEndTag), new Integer( get_offset() - 4 ) ) ;            }            // If the ORB is null, or if we're sure we're talking to            // a foreign ORB, Merlin, or something more recent, we            // use the updated end tag computation, and are more strenuous            // about the values.            if (orb == null ||                ORBVersionFactory.getFOREIGN().equals(orb.getORBVersion()) ||                ORBVersionFactory.getNEWER().compareTo(orb.getORBVersion()) <= 0) {                // If the end tag we read was less than what we were expecting,                // then the sender must think it's sent more enclosing                 // chunked valuetypes than we have.  Throw an exception.                if (anEndTag < chunkedValueNestingLevel)		    throw wrapper.unexpectedEnclosingValuetype( 			CompletionStatus.COMPLETED_MAYBE, new Integer( anEndTag ),			new Integer( chunkedValueNestingLevel ) ) ;                // If the end tag is bigger than what we expected, but                // still negative, then the sender has done some end tag                // compaction.  We back up the stream 4 bytes so that the                // next time readEndTag is called, it will get down here                // again.  Even with fragmentation, we'll always be able                // to do this.                if (anEndTag != chunkedValueNestingLevel) {                    bbwi.position(bbwi.position() - 4);                 }            } else {                                // When talking to Kestrel or Ladybird, we use our old                // end tag rules and are less strict.  If the end tag                // isn't what we expected, we back up, assuming                // compaction.                if (anEndTag != end_flag) {                    bbwi.position(bbwi.position() - 4);                }            }            // This only keeps track of the enclosing chunked            // valuetypes            chunkedValueNestingLevel++;        }        // This keeps track of all enclosing valuetypes	end_flag++;    }    protected int get_offset() {	return bbwi.position();    }    private void start_block() {			// if (outerValueDone)	if (!isChunked)	    return;		// if called from alignAndCheck, need to reset blockLength	// to avoid an infinite recursion loop on read_long() call	blockLength = maxBlockLength;	blockLength = read_long();        // Must remember where we began the chunk to calculate how far        // along we are.  See notes above about chunkBeginPos.	if (blockLength > 0 && blockLength < maxBlockLength) {	    blockLength += get_offset();  // _REVISIT_ unsafe, should use a Java long	    // inBlock = true;	} else {            // System.out.println("start_block snooped a " + Integer.toHexString(blockLength));	    // not a chunk length field	    blockLength = maxBlockLength;            bbwi.position(bbwi.position() - 4);	}    }    // Makes sure that if we were reading a chunked value, we end up    // at the right place in the stream, no matter how little the    // unmarshalling code read.    //    // After calling this method, if we are chunking, we should be    // in position to read the end tag.    private void handleEndOfValue() {        // If we're not chunking, we don't have to worry about        // skipping remaining chunks or finding end tags        if (!isChunked)            return;        // Skip any remaining chunks        while (blockLength != maxBlockLength) {            end_block();            start_block();        }        // Now look for the end tag        // This is a little wasteful since we're reading        // this long up to 3 times in the worst cases (once        // in start_block, once here, and once in readEndTag        //         // Peek next long        int nextLong = read_long();        bbwi.position(bbwi.position() - 4);        // We did find an end tag, so we're done.  readEndTag        // should take care of making sure it's the correct        // end tag, etc.  Remember that since end tags,        // chunk lengths, and valuetags have non overlapping        // ranges, we can tell by the value what the longs are.        if (nextLong < 0)            return;        if (nextLong == 0 || nextLong >= maxBlockLength) {            // A custom marshaled valuetype left extra data            // on the wire, and that data had another            // nested value inside of it.  We've just            // read the value tag or null of that nested value.            //            // In an attempt to get by it, we'll try to call            // read_value() to get the nested value off of            // the wire.  Afterwards, we must call handleEndOfValue

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?