1 22 package org.jboss.invocation; 23 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.io.ObjectOutputStream ; 27 import java.rmi.Remote ; 28 import java.rmi.server.RemoteObject ; 29 import java.rmi.server.RemoteStub ; 30 import java.security.PrivilegedAction ; 31 import java.security.AccessController ; 32 33 42 public class MarshalledValueOutputStream 43 extends ObjectOutputStream 44 { 45 50 public MarshalledValueOutputStream(OutputStream os) throws IOException 51 { 52 super(os); 53 EnableReplaceObjectAction.enableReplaceObject(this); 54 } 55 56 59 protected void annotateClass(Class cl) throws IOException 60 { 61 super.annotateClass(cl); 62 } 63 64 67 protected void annotateProxyClass(Class cl) throws IOException 68 { 69 super.annotateProxyClass(cl); 70 } 71 72 75 protected Object replaceObject(Object obj) throws IOException 76 { 77 if( (obj instanceof Remote ) && !(obj instanceof RemoteStub ) ) 78 { 79 Remote remote = (Remote ) obj; 80 try 81 { 82 obj = RemoteObject.toStub(remote); 83 } 84 catch(IOException ignore) 85 { 86 } 88 } 89 return obj; 90 } 91 92 private static class EnableReplaceObjectAction implements PrivilegedAction 93 { 94 MarshalledValueOutputStream os; 95 EnableReplaceObjectAction(MarshalledValueOutputStream os) 96 { 97 this.os = os; 98 } 99 public Object run() 100 { 101 os.enableReplaceObject(true); 102 return null; 103 } 104 static void enableReplaceObject(MarshalledValueOutputStream os) 105 { 106 EnableReplaceObjectAction action = new EnableReplaceObjectAction(os); 107 AccessController.doPrivileged(action); 108 } 109 } 110 } 111 | Popular Tags |