📄 remoteobject.java
字号:
* * <p>Following is the data that must be written by the * <code>writeExternal</code> method and read by the * <code>readExternal</code> method of <code>RemoteRef</code> * implementation classes that correspond to the each of the * defined external ref type names: * * <p>For <code>"UnicastRef"</code>: * * <ul> * * <li>the hostname of the referenced remote object, * written by {@link java.io.ObjectOutput#writeUTF(String)} * * <li>the port of the referenced remote object, * written by {@link java.io.ObjectOutput#writeInt(int)} * * <li>the data written as a result of calling * {link java.rmi.server.ObjID#write(java.io.ObjectOutput)} * on the <code>ObjID</code> instance contained in the reference * * <li>the boolean value <code>false</code>, * written by {@link java.io.ObjectOutput#writeBoolean(boolean)} * * </ul> * * <p>For <code>"UnicastRef2"</code> with a * <code>null</code> client socket factory: * * <ul> * * <li>the byte value <code>0x00</code> * (indicating <code>null</code> client socket factory), * written by {@link java.io.ObjectOutput#writeByte(int)} * * <li>the hostname of the referenced remote object, * written by {@link java.io.ObjectOutput#writeUTF(String)} * * <li>the port of the referenced remote object, * written by {@link java.io.ObjectOutput#writeInt(int)} * * <li>the data written as a result of calling * {link java.rmi.server.ObjID#write(java.io.ObjectOutput)} * on the <code>ObjID</code> instance contained in the reference * * <li>the boolean value <code>false</code>, * written by {@link java.io.ObjectOutput#writeBoolean(boolean)} * * </ul> * * <p>For <code>"UnicastRef2"</code> with a * non-<code>null</code> client socket factory: * * <ul> * * <li>the byte value <code>0x01</code> * (indicating non-<code>null</code> client socket factory), * written by {@link java.io.ObjectOutput#writeByte(int)} * * <li>the hostname of the referenced remote object, * written by {@link java.io.ObjectOutput#writeUTF(String)} * * <li>the port of the referenced remote object, * written by {@link java.io.ObjectOutput#writeInt(int)} * * <li>a client socket factory (object of type * <code>java.rmi.server.RMIClientSocketFactory</code>), * written by passing it to an invocation of * <code>writeObject</code> on the stream instance * * <li>the data written as a result of calling * {link java.rmi.server.ObjID#write(java.io.ObjectOutput)} * on the <code>ObjID</code> instance contained in the reference * * <li>the boolean value <code>false</code>, * written by {@link java.io.ObjectOutput#writeBoolean(boolean)} * * </ul> * * <p>For <code>"ActivatableRef"</code> with a * <code>null</code> nested remote reference: * * <ul> * * <li>an instance of * <code>java.rmi.activation.ActivationID</code>, * written by passing it to an invocation of * <code>writeObject</code> on the stream instance * * <li>a zero-length string (<code>""</code>), * written by {@link java.io.ObjectOutput#writeUTF(String)} * * </ul> * * <p>For <code>"ActivatableRef"</code> with a * non-<code>null</code> nested remote reference: * * <ul> * * <li>an instance of * <code>java.rmi.activation.ActivationID</code>, * written by passing it to an invocation of * <code>writeObject</code> on the stream instance * * <li>the external ref type name of the nested remote reference, * which must be <code>"UnicastRef2"</code>, * written by {@link java.io.ObjectOutput#writeUTF(String)} * * <li>the external form of the nested remote reference, * written by invoking its <code>writeExternal</code> method * with the stream instance * (see the description of the external form for * <code>"UnicastRef2"</code> above) * * </ul> * * <p>For <code>"UnicastServerRef"</code>, * <code>"UnicastServerRef2"</code>, and * <code>"ActivatableServerRef"</code>, no data is written by the * <code>writeExternal</code> method or read by the * <code>readExternal</code> method. */ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException, java.lang.ClassNotFoundException { if (ref == null) { throw new java.rmi.MarshalException("Invalid remote object"); } else { String refClassName = ref.getRefClass(out); if (refClassName == null || refClassName.length() == 0) { /* * No reference class name specified, so serialize * remote reference. */ out.writeUTF(""); out.writeObject(ref); } else { /* * Built-in reference class specified, so delegate * to reference to write out its external form. */ out.writeUTF(refClassName); ref.writeExternal(out); } } } /** * <code>readObject</code> for custom serialization. * * <p>This method reads this object's serialized form for this class * as follows: * * <p>The <code>readUTF</code> method is invoked on <code>in</code> * to read the external ref type name for the <code>RemoteRef</code> * instance to be filled in to this object's <code>ref</code> field. * If the string returned by <code>readUTF</code> has length zero, * the <code>readObject</code> method is invoked on <code>in</code>, * and than the value returned by <code>readObject</code> is cast to * <code>RemoteRef</code> and this object's <code>ref</code> field is * set to that value. * Otherwise, this object's <code>ref</code> field is set to a * <code>RemoteRef</code> instance that is created of an * implementation-specific class corresponding to the external ref * type name returned by <code>readUTF</code>, and then * the <code>readExternal</code> method is invoked on * this object's <code>ref</code> field. * * <p>If the external ref type name is * <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>, * <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>, * <code>"ActivatableRef"</code>, or * <code>"ActivatableServerRef"</code>, a corresponding * implementation-specific class must be found, and its * <code>readExternal</code> method must read the serial data * for that external ref type name as specified to be written * in the <b>serialData</b> documentation for this class. * If the external ref type name is any other string (of non-zero * length), a <code>ClassNotFoundException</code> will be thrown, * unless the implementation provides an implementation-specific * class corresponding to that external ref type name, in which * case this object's <code>ref</code> field will be set to an * instance of that implementation-specific class. */ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { try { String refClassName = in.readUTF(); if (refClassName == null || refClassName.length() == 0) { /* * No reference class name specified, so construct * remote reference from its serialized form. */ ref = (RemoteRef) in.readObject(); } else { /* * Built-in reference class specified, so delegate * to reference to initialize its fields from its * external form. */ Class refClass = Class.forName(RemoteRef.packagePrefix + "." + refClassName); ref = (RemoteRef) refClass.newInstance(); ref.readExternal(in); } } catch (InstantiationException e) { throw new UnmarshalException("Unable to create remote reference", e); } catch (IllegalAccessException e) { throw new UnmarshalException("Illegal access creating remote reference"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -