iiopinputstream.java
来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 1,852 行 · 第 1/5 页
JAVA
1,852 行
((ValueInputStream)getOrbStream()).start_value(); ((ValueInputStream)getOrbStream()).end_value(); } // WARNING: If stream format version is 1 and there's // optional data, we'll get some form of exception down // the line or data corruption. } else { inputClassFields(null, currentClass, null, fvd.members, sender); } if (fvdsList.hasMoreElements()){ fvd = (FullValueDescription)fvdsList.nextElement(); repIDForFVD = vhandler.getClassName(fvd.id); } else return currentObject; } } currdesc = currentClassDesc = ObjectStreamClass.lookup(currentClass); if (!repIDForClass.equals("java.lang.Object")) { // If the sender used custom marshaling, then it should have put // the two bytes on the wire indicating stream format version // and whether or not the writeObject method called // defaultWriteObject/writeFields. ReadObjectState oldState = readObjectState; setState(DEFAULT_STATE); try { if (fvd.is_custom) { // Read format version readFormatVersion(); // Read defaultWriteObject indicator boolean calledDefaultWriteObject = readBoolean(); readObjectState.beginUnmarshalCustomValue(this, calledDefaultWriteObject, (currentClassDesc.readObjectMethod != null)); } boolean usedReadObject = false; // Always use readObject if it exists, and fall back to default // unmarshaling if it doesn't. try { if (!fvd.is_custom && currentClassDesc.hasReadObject()) setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED); // See the definition of defaultReadObjectFVDMembers // for more information. This concerns making sure // we use the remote FVD's members in defaultReadObject. defaultReadObjectFVDMembers = fvd.members; usedReadObject = invokeObjectReader(currentClassDesc, currentObject, currentClass); } finally { defaultReadObjectFVDMembers = null; } // Note that the !usedReadObject !calledDefaultWriteObject // case is handled by the beginUnmarshalCustomValue method // of the default state if (!usedReadObject || readObjectState == IN_READ_OBJECT_DEFAULTS_SENT) inputClassFields(currentObject, currentClass, currdesc, fvd.members, sender); if (fvd.is_custom) readObjectState.endUnmarshalCustomValue(this); } finally { setState(oldState); } currclass = currentClass = classes[--spClass]; } else { // The remaining hierarchy of the local class does not match the sender's FVD. // So, use remaining FVDs to read data off wire. If any remaining FVDs indicate // custom marshaling, throw MARSHAL error. inputClassFields(null, currentClass, null, fvd.members, sender); while (fvdsList.hasMoreElements()){ fvd = (FullValueDescription)fvdsList.nextElement(); if (fvd.is_custom) skipCustomUsingFVD(fvd.members, sender); else inputClassFields(null, currentClass, null, fvd.members, sender); } } } // end : while(fvdsList.hasMoreElements()) while (fvdsList.hasMoreElements()){ FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement(); if (fvd.is_custom) skipCustomUsingFVD(fvd.members, sender); else throwAwayData(fvd.members, sender); } } return currentObject; } finally { // Make sure we exit at the same stack level as when we started. spClass = spBase; // 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); } } /** * 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. * * 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 skipObjectUsingFVD(String repositoryID, com.sun.org.omg.SendingContext.CodeBase sender) throws IOException, ClassNotFoundException { Enumeration fvdsList = getOrderedDescriptions(repositoryID, sender).elements(); while(fvdsList.hasMoreElements()) { FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement(); String repIDForFVD = vhandler.getClassName(fvd.id); if (!repIDForFVD.equals("java.lang.Object")) { if (fvd.is_custom) { readFormatVersion(); boolean calledDefaultWriteObject = readBoolean(); if (calledDefaultWriteObject) inputClassFields(null, null, null, fvd.members, sender); if (getStreamFormatVersion() == 2) { ((ValueInputStream)getOrbStream()).start_value(); ((ValueInputStream)getOrbStream()).end_value(); } // WARNING: If stream format version is 1 and there's // optional data, we'll get some form of exception down // the line. } else { // Use default marshaling inputClassFields(null, null, null, fvd.members, sender); } } } // end : while(fvdsList.hasMoreElements()) return null; } /////////////////// private int findNextClass(String classname, Class classes[], int _spClass, int _spBase){ for (int i = _spClass; i > _spBase; i--){ if (classname.equals(classes[i].getName())) { return i; } } return -1; } /* * Invoke the readObject method if present. Assumes that in the case of custom * marshaling, the format version and defaultWriteObject indicator were already * removed. */ private boolean invokeObjectReader(ObjectStreamClass osc, Object obj, Class aclass) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException { if (osc.readObjectMethod == null) { return false; } try { osc.readObjectMethod.invoke( obj, readObjectArgList ) ; return true; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ClassNotFoundException) throw (ClassNotFoundException)t; else if (t instanceof IOException) throw (IOException)t; else if (t instanceof RuntimeException) throw (RuntimeException) t; else if (t instanceof Error) throw (Error) t; else // XXX I18N, logging needed. throw new Error("internal error"); } catch (IllegalAccessException e) { return false; } } /* * Reset the stream to be just like it was after the constructor. */ private void resetStream() throws IOException { if (classes == null) classes = new Class[20]; else { for (int i = 0; i < classes.length; i++) classes[i] = null; } if (classdesc == null) classdesc = new ObjectStreamClass[20]; else { for (int i = 0; i < classdesc.length; i++) classdesc[i] = null; } spClass = 0; if (callbacks != null) callbacks.setSize(0); // discard any pending callbacks } /** * Factored out of inputClassFields This reads a primitive value and sets it * in the field of o described by the ObjectStreamField field. * * Note that reflection cannot be used here, because reflection cannot be used * to set final fields. */ private void inputPrimitiveField(Object o, Class cl, ObjectStreamField field) throws InvalidClassException, IOException { try { switch (field.getTypeCode()) { case 'B': byte byteValue = orbStream.read_octet(); bridge.putByte( o, field.getFieldID(), byteValue ) ; //reflective code: field.getField().setByte( o, byteValue ) ; break; case 'Z': boolean booleanValue = orbStream.read_boolean(); bridge.putBoolean( o, field.getFieldID(), booleanValue ) ; //reflective code: field.getField().setBoolean( o, booleanValue ) ; break; case 'C': char charValue = orbStream.read_wchar(); bridge.putChar( o, field.getFieldID(), charValue ) ; //reflective code: field.getField().setChar( o, charValue ) ; break; case 'S': short shortValue = orbStream.read_short(); bridge.putShort( o, field.getFieldID(), shortValue ) ; //reflective code: field.getField().setShort( o, shortValue ) ; break; case 'I': int intValue = orbStream.read_long(); bridge.putInt( o, field.getFieldID(), intValue ) ; //reflective code: field.getField().setInt( o, intValue ) ; break; case 'J': long longValue = orbStream.read_longlong(); bridge.putLong( o, field.getFieldID(), longValue ) ; //reflective code: field.getField().setLong( o, longValue ) ; break; case 'F' : float floatValue = orbStream.read_float(); bridge.putFloat( o, field.getFieldID(), floatValue ) ; //reflective code: field.getField().setFloat( o, floatValue ) ; break; case 'D' : double doubleValue = orbStream.read_double(); bridge.putDouble( o, field.getFieldID(), doubleValue ) ; //reflective code: field.getField().setDouble( o, doubleValue ) ; break; default: // XXX I18N, logging needed. throw new InvalidClassException(cl.getName()); } } catch (IllegalArgumentException e) { /* This case should never happen. If the field types are not the same, InvalidClassException is raised when matching the local class to the serialized ObjectStreamClass. */ ClassCastException cce = new ClassCastException("Assigning instance of class " + field.getType().getName() + " to field " + currentClassDesc.getName() + '#' + field.getField().getName()); cce.initCause( e ) ; throw cce ; } } private Object inputObjectField(org.omg.CORBA.ValueMember field, com.sun.org.omg.SendingContext.CodeBase sender) throws IndirectionException, ClassNotFoundException, IOException, StreamCorruptedException { Object objectValue = null; Class type = null; String id = field.id; try { type = vhandler.getClassFromType(id); } catch(ClassNotFoundException cnfe) { // Make sure type = null type = null; } String signature = null; if (type != null) signature = ValueUtility.getSignature(field); if (signature != null && (signature.equals("Ljava/lang/Object;") || signature.equals("Ljava/io/Serializable;") || signature.equals("Ljava/io/Externalizable;"))) { objectValue = javax.rmi.CORBA.Util.readAny(orbStream); } else { // Decide what method call to make based on the type. If // it is a type for which we need to load a stub, convert // the type to the correct stub type. // // NOTE : Since FullValueDescription does not allow us // to ask whether something is an interface we do not // have the ability to optimize this check. int callType = ValueHandlerImpl.kValueType; if (!vhandler.isSequence(id)) { if (field.type.kind().value() == kRemoteTypeCode.kind().value()) { // RMI Object reference... callType = ValueHandlerImpl.kRemoteType; } else { // REVISIT. If we don't have the local class, // we shoul
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?