1 22 package org.jboss.proxy.ejb.handle; 23 24 import java.rmi.RemoteException ; 25 import java.rmi.ServerException ; 26 import java.lang.reflect.InvocationHandler ; 27 import java.lang.reflect.Method ; 28 import java.lang.reflect.Proxy ; 29 30 import java.security.AccessControlException ; 31 import java.security.AccessController ; 32 import java.security.PrivilegedAction ; 33 import java.security.Principal ; 34 import java.util.Hashtable ; 35 36 import javax.ejb.EJBHome ; 37 import javax.ejb.Handle ; 38 import javax.ejb.EJBObject ; 39 import javax.naming.InitialContext ; 40 41 import org.jboss.invocation.Invoker; 42 import org.jboss.invocation.Invocation; 43 import org.jboss.invocation.InvocationKey; 44 import org.jboss.invocation.InvocationType; 45 import org.jboss.invocation.InvokerInterceptor; 46 import org.jboss.invocation.PayloadKey; 47 import org.jboss.logging.Logger; 48 import org.jboss.naming.NamingContextFactory; 49 import org.jboss.security.SecurityAssociation; 50 51 59 public class StatefulHandleImpl 60 implements Handle 61 { 62 private static final Logger log = Logger.getLogger(StatefulHandleImpl.class); 63 64 65 static final long serialVersionUID = -6324520755180597156L; 66 67 68 protected static final Method GET_EJB_OBJECT; 69 70 71 private Object invokerID = null; 72 73 76 static 77 { 78 try 79 { 80 GET_EJB_OBJECT = Handle .class.getMethod("getEJBObject", new Class [0]); 81 } 82 catch(Exception e) 83 { 84 e.printStackTrace(); 85 throw new ExceptionInInitializerError (e); 86 } 87 } 88 89 90 public int objectName; 91 public String jndiName; 92 public String invokerProxyBinding; 93 public Invoker invoker; 94 public Object id; 95 96 97 protected Hashtable jndiEnv; 98 99 public StatefulHandleImpl() 100 { 101 102 } 103 104 111 public StatefulHandleImpl( 112 int objectName, 113 String jndiName, 114 Invoker invoker, 115 String invokerProxyBinding, 116 Object id, 117 Object invokerID) 118 { 119 this.jndiName = jndiName; 120 this.id = id; 121 this.jndiEnv = (Hashtable ) NamingContextFactory.lastInitialContextEnv.get(); 122 try 123 { 124 String property = System.getProperty("org.jboss.ejb.sfsb.handle.V327"); 125 if (property != null) 126 { 127 this.invokerProxyBinding = invokerProxyBinding; 128 this.invokerID = invokerID; 129 this.objectName = objectName; 130 this.invoker = invoker; 131 } 132 } 133 catch (AccessControlException ignored) 134 { 135 } 136 137 } 138 139 142 public Object getID() 143 { 144 return id; 145 } 146 147 150 public String getJNDIName() 151 { 152 return jndiName; 153 } 154 155 173 public EJBObject getEJBObject() throws RemoteException 174 { 175 try 176 { 177 InitialContext ic = null; 178 if( jndiEnv != null ) 179 ic = new InitialContext (jndiEnv); 180 else 181 ic = new InitialContext (); 182 183 Proxy proxy = (Proxy ) ic.lookup(jndiName); 184 185 InvocationHandler ih = Proxy.getInvocationHandler(proxy); 187 return (EJBObject ) ih.invoke(proxy, GET_EJB_OBJECT, new Object [] {id}); 188 } 189 catch (RemoteException e) 190 { 191 throw e; 192 } 193 catch (Throwable t) 194 { 195 t.printStackTrace(); 196 throw new RemoteException ("Error during getEJBObject", t); 197 } 198 } 199 } 200 201 | Popular Tags |