1 22 package org.jboss.proxy.ejb; 23 24 import java.io.Externalizable ; 25 import java.lang.reflect.Method ; 26 import javax.ejb.EJBHome ; 27 import javax.ejb.EJBObject ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 31 import org.jboss.invocation.Invocation; 32 import org.jboss.invocation.InvocationKey; 33 import org.jboss.invocation.InvocationContext; 34 import org.jboss.proxy.Interceptor; 35 36 43 public abstract class GenericEJBInterceptor 44 extends Interceptor 45 implements Externalizable 46 { 47 48 private static final long serialVersionUID = 3844706474734439975L; 49 50 protected static final Method TO_STRING; 52 protected static final Method HASH_CODE; 53 protected static final Method EQUALS; 54 protected static final Method GET_PRIMARY_KEY; 55 protected static final Method GET_HANDLE; 56 protected static final Method GET_EJB_HOME; 57 protected static final Method IS_IDENTICAL; 58 59 60 static 61 { 62 try 63 { 64 Class [] empty = {}; 66 Class type = Object .class; 67 68 TO_STRING = type.getMethod("toString", empty); 69 HASH_CODE = type.getMethod("hashCode", empty); 70 EQUALS = type.getMethod("equals", new Class [] { type }); 71 72 type = EJBObject .class; 74 75 GET_PRIMARY_KEY = type.getMethod("getPrimaryKey", empty); 76 GET_HANDLE = type.getMethod("getHandle", empty); 77 GET_EJB_HOME = type.getMethod("getEJBHome", empty); 78 IS_IDENTICAL = type.getMethod("isIdentical", new Class [] { type }); 79 } 80 catch (Exception e) 81 { 82 e.printStackTrace(); 83 throw new ExceptionInInitializerError (e); 84 } 85 } 86 87 90 public GenericEJBInterceptor() 91 { 92 } 94 95 protected EJBHome getEJBHome(Invocation invocation) throws NamingException 96 { 97 InvocationContext ctx = invocation.getInvocationContext(); 99 EJBHome home = (EJBHome ) ctx.getValue(InvocationKey.EJB_HOME); 100 if( home == null ) 102 { 103 String jndiName = (String ) ctx.getValue(InvocationKey.JNDI_NAME); 104 InitialContext iniCtx = new InitialContext (); 105 home = (EJBHome ) iniCtx.lookup(jndiName); 106 } 107 return home; 108 } 109 } 110 111 | Popular Tags |