iiopinputstream.java

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

JAVA
1,852
字号
    		    classes = newclasses;    		    classdesc = newclassdesc;    		}    		if (cl == null) {    		    /* Class not found corresponding to this descriptor.    		     * Pop off all the extra classes pushed.    		     * Push the descriptor and a null class.    		     */    		    classdesc[spClass] = currdesc;    		    classes[spClass] = null;    		} else {		    /* Current class descriptor matches current class.    		     * Some classes may have been inserted.    		     * Record the match and advance the class, continue    		     * with the next descriptor.    		     */    		    classdesc[spClass] = currdesc;    		    classes[spClass] = cl;    		    currclass = cl.getSuperclass();    		}    	    } // end : for (currdesc = currentClassDesc, currclass = currentClass;    	    /* Allocate a new object.  The object is only constructed    	     * above the highest serializable class and is set to    	     * default values for all more specialized classes.    	     */    	    try {    		currentObject = (currentClass == null) ?		    null : currentClassDesc.newInstance() ;                // Store this object and its beginning position                // since there might be indirections to it while                // it's been unmarshalled.                activeRecursionMgr.addObject(offset, currentObject);	    } catch (InvocationTargetException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "InvocationTargetException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;	    } catch (UnsupportedOperationException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "UnsupportedOperationException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;    	    } catch (InstantiationException e) {		InvalidClassException exc = new InvalidClassException(		    currentClass.getName(), 		    "InstantiationException accessing no-arg constructor");		exc.initCause( e ) ;		throw exc ;    	    }    	    /*    	     * For all the pushed descriptors and classes.    	     * 	if the class has its own writeObject and readObject methods    	     *	    call the readObject method    	     *	else    	     *	    invoke the defaultReadObject method    	     */    	    try {    		for (spClass = spClass; spClass > spBase; spClass--) {    		    /*    		     * Set current descriptor and corresponding class    		     */    		    currentClassDesc = classdesc[spClass];    		    currentClass = classes[spClass];    		    if (classes[spClass] != null) {    			/* Read the data from the stream described by the    			 * descriptor and store into the matching class.    			 */                        ReadObjectState oldState = readObjectState;                        setState(DEFAULT_STATE);                        try {                            // Changed since invokeObjectReader no longer does this.                            if (currentClassDesc.hasWriteObject()) {                                // Read format version                                readFormatVersion();                                // Read defaultWriteObject indicator                                boolean calledDefaultWriteObject = readBoolean();                                readObjectState.beginUnmarshalCustomValue(this,                                                                          calledDefaultWriteObject,                                                                          (currentClassDesc.readObjectMethod                                                                           != null));                            } else {                                if (currentClassDesc.hasReadObject())                                    setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED);                            }                            if (!invokeObjectReader(currentClassDesc, currentObject, currentClass) ||                                readObjectState == IN_READ_OBJECT_DEFAULTS_SENT) {                                // Error case of no readObject and didn't call                                // defaultWriteObject handled in default state				ObjectStreamField[] fields =				    currentClassDesc.getFieldsNoCopy();				if (fields.length > 0) {				    inputClassFields(currentObject, currentClass, fields, sender);				}                            }                            if (currentClassDesc.hasWriteObject())                                readObjectState.endUnmarshalCustomValue(this);                        } finally {                            setState(oldState);                        }    		    } else {			// _REVISIT_ : Can we ever get here?			/* No local class for this descriptor,			 * Skip over the data for this class.			 * like defaultReadObject with a null currentObject.			 * The code will read the values but discard them.			 */			    ObjectStreamField[] fields =				currentClassDesc.getFieldsNoCopy();			    if (fields.length > 0) {				inputClassFields(null, currentClass, fields, sender);			    }									}							}    	    } finally {				// Make sure we exit at the same stack level as when we started.		spClass = spBase;    	    }    	}        } finally {            // We've completed deserializing this object.  Any            // future indirections will be handled correctly at the            // CDR level.  The ActiveRecursionManager only deals with            // objects currently being deserialized.            activeRecursionMgr.removeObject(offset);        }		    	return currentObject;    }    // This retrieves a vector of FVD's for the hierarchy of serializable classes stemming from     // repositoryID.  It is assumed that the sender will not provide base_value id's for non-serializable    // classes!    private Vector getOrderedDescriptions(String repositoryID,					  com.sun.org.omg.SendingContext.CodeBase sender) {	Vector descs = new Vector();        if (sender == null) {            return descs;        }        	FullValueDescription aFVD = sender.meta(repositoryID);	while (aFVD != null) {	    descs.insertElementAt(aFVD, 0);	    if ((aFVD.base_value != null) && !kEmptyStr.equals(aFVD.base_value)) {		aFVD = sender.meta(aFVD.base_value);	    }	    else return descs;	}	return descs;    }    /**     * This input method uses FullValueDescriptions retrieved from the sender's runtime to      * read in the data.  This method is capable of throwing out data not applicable to client's fields.     * This method handles instances where the reader has a class not sent by the sender, the sender sent     * a class not present on the reader, and/or the reader's class does not match the sender's class.     *     * NOTE : If the local description indicates custom marshaling and the remote type's FVD also     * indicates custom marsahling than the local type is used to read the data off the wire.  However,     * if either says custom while the other does not, a MARSHAL error is thrown.  Externalizable is      * a form of custom marshaling.     *     */    private Object inputObjectUsingFVD(Class clz,				       String repositoryID,				       com.sun.org.omg.SendingContext.CodeBase sender,                                       int offset)	throws IOException, ClassNotFoundException    {	int spBase = spClass;	// current top of stack	try{				    /*	     * Get the descriptor and then class of the incoming object.	     */				    ObjectStreamClass currdesc = currentClassDesc = ObjectStreamClass.lookup(clz);	    Class currclass = currentClass = clz;				    /* If Externalizable,	     *  Create an instance and tell it to read its data.	     * else,	     *  Handle it as a serializable class.	     */	    if (currentClassDesc.isExternalizable()) {		try {		    currentObject = (currentClass == null) ?			null : currentClassDesc.newInstance();		    if (currentObject != null) {                        // Store this object and its beginning position                        // since there might be indirections to it while                        // it's been unmarshalled.                        activeRecursionMgr.addObject(offset, currentObject);			// Read format version			readFormatVersion();									Externalizable ext = (Externalizable)currentObject;			ext.readExternal(this);		    }		} catch (InvocationTargetException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"InvocationTargetException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		} catch (UnsupportedOperationException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"UnsupportedOperationException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		} catch (InstantiationException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"InstantiationException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		}	    } else {		/*		 * This is your basic diff pattern, made simpler		 * because reordering is not allowed.		 */		for (currdesc = currentClassDesc, currclass = currentClass;		     currdesc != null && currdesc.isSerializable();   /*sun.4296963 ibm.11861*/		     currdesc = currdesc.getSuperclass()) {							    /*		     * Search the classes to see if the class of this		     * descriptor appears further up the hierarchy. Until		     * it's found assume its an inserted class.  If it's		     * not found, its the descriptor's class that has been		     * removed.		     */		    Class cc = currdesc.forClass();		    Class cl;		    for (cl = currclass; cl != null; cl = cl.getSuperclass()) {			if (cc == cl) {			    // found a superclass that matches this descriptor			    break;			} else {			    /* Ignore a class that doesn't match.  No			     * action is needed since it is already			     * initialized.			     */			}		    } // end : for (cl = currclass; cl != null; cl = cl.getSuperclass()) 		    /* Test if there is room for this new entry.		     * If not, double the size of the arrays and copy the contents.		     */		    spClass++;		    if (spClass >= classes.length) {			int newlen = classes.length * 2;			Class[] newclasses = new Class[newlen];			ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen];							System.arraycopy(classes, 0,					 newclasses, 0,					 classes.length);			System.arraycopy(classdesc, 0,					 newclassdesc, 0,					 classes.length);									classes = newclasses;			classdesc = newclassdesc;    		    }		    if (cl == null) {			/* Class not found corresponding to this descriptor.			 * Pop off all the extra classes pushed.			 * Push the descriptor and a null class.			 */			classdesc[spClass] = currdesc;			classes[spClass] = null;		    } else {			/* Current class descriptor matches current class.			 * Some classes may have been inserted.			 * Record the match and advance the class, continue			 * with the next descriptor.			 */			classdesc[spClass] = currdesc;			classes[spClass] = cl;			currclass = cl.getSuperclass();		    }		} // end : for (currdesc = currentClassDesc, currclass = currentClass;						/* Allocate a new object.  		 */		try {		    currentObject = (currentClass == null) ?			null : currentClassDesc.newInstance();                    // Store this object and its beginning position                    // since there might be indirections to it while                    // it's been unmarshalled.                    activeRecursionMgr.addObject(offset, currentObject);		} catch (InvocationTargetException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"InvocationTargetException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		} catch (UnsupportedOperationException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"UnsupportedOperationException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		} catch (InstantiationException e) {		    InvalidClassException exc = new InvalidClassException(			currentClass.getName(), 			"InstantiationException accessing no-arg constructor");		    exc.initCause( e ) ;		    throw exc ;		}						Enumeration fvdsList = getOrderedDescriptions(repositoryID, sender).elements();						while((fvdsList.hasMoreElements()) && (spClass > spBase)) {		    FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement();	            // d4365188: backward compatability		    String repIDForFVD = vhandler.getClassName(fvd.id);		    String repIDForClass = vhandler.getClassName(vhandler.getRMIRepositoryID(currentClass));							    while ((spClass > spBase) &&			   (!repIDForFVD.equals(repIDForClass))) {			int pos = findNextClass(repIDForFVD, classes, spClass, spBase);			if (pos != -1) {			    spClass = pos;			    currclass = currentClass = classes[spClass];			    repIDForClass = vhandler.getClassName(vhandler.getRMIRepositoryID(currentClass));			}			else { // Read and throw away one level of the fvdslist                            // This seems to mean that the sender had a superclass that                            // we don't have			    if (fvd.is_custom) {                                readFormatVersion();                                boolean calledDefaultWriteObject = readBoolean();                                if (calledDefaultWriteObject)                                    inputClassFields(null, null, null, fvd.members, sender);                                if (getStreamFormatVersion() == 2) {

⌨️ 快捷键说明

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