1 22 package org.jboss.ejb.plugins; 23 24 import java.io.OutputStream ; 25 import java.io.ObjectOutputStream ; 26 import java.io.IOException ; 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 import javax.ejb.EJBObject ; 33 import javax.ejb.EJBHome ; 34 import javax.ejb.Handle ; 35 import javax.ejb.SessionContext ; 36 import javax.transaction.UserTransaction ; 37 38 39 48 public class SessionObjectOutputStream 49 extends ObjectOutputStream 50 { 51 public SessionObjectOutputStream(OutputStream out) 53 throws IOException 54 { 55 super(out); 56 EnableReplaceObjectAction.enableReplaceObject(this); 57 } 58 59 protected Object replaceObject(Object obj) 61 throws IOException 62 { 63 Object replacement = obj; 64 66 if (obj instanceof EJBObject ) 68 replacement = ((EJBObject )obj).getHandle(); 69 70 else if (obj instanceof EJBHome ) 72 replacement = ((EJBHome )obj).getHomeHandle(); 73 74 else if (obj instanceof SessionContext ) 76 replacement = new StatefulSessionBeanField(StatefulSessionBeanField.SESSION_CONTEXT); 77 78 80 else if (obj instanceof UserTransaction ) 82 replacement = new StatefulSessionBeanField(StatefulSessionBeanField.USER_TRANSACTION); 83 84 else if( obj instanceof Handle ) 85 replacement = new HandleWrapper((Handle )obj); 86 87 else if( (obj instanceof Remote ) && !(obj instanceof RemoteStub ) ) 88 { 89 Remote remote = (Remote ) obj; 90 try 91 { 92 replacement = RemoteObject.toStub(remote); 93 } 94 catch(IOException ignore) 95 { 96 } 98 } 99 100 return replacement; 101 } 102 103 private static class EnableReplaceObjectAction implements PrivilegedAction 104 { 105 SessionObjectOutputStream os; 106 EnableReplaceObjectAction(SessionObjectOutputStream os) 107 { 108 this.os = os; 109 } 110 public Object run() 111 { 112 os.enableReplaceObject(true); 113 return null; 114 } 115 static void enableReplaceObject(SessionObjectOutputStream os) 116 { 117 EnableReplaceObjectAction action = new EnableReplaceObjectAction(os); 118 AccessController.doPrivileged(action); 119 } 120 } 121 } 122 123 | Popular Tags |