1 7 package org.jboss.ejb3.stateless; 8 9 import org.jboss.aop.Advisor; 10 import org.jboss.ejb3.Container; 11 import org.jboss.ejb3.ProxyFactory; 12 import org.jboss.logging.Logger; 13 import org.jboss.naming.Util; 14 15 import javax.naming.Context ; 16 import javax.naming.InitialContext ; 17 18 import java.lang.reflect.Constructor ; 19 import java.lang.reflect.InvocationHandler ; 20 21 27 public abstract class BaseStatelesslProxyFactory implements ProxyFactory 28 { 29 private static final Logger log = Logger.getLogger(BaseStatelesslProxyFactory.class); 30 31 protected Class proxyClass; 32 protected Constructor proxyConstructor; 33 protected Context proxyFactoryContext; 34 protected String jndiName; 35 protected Container container; 36 protected Advisor advisor; 37 38 public void init() throws Exception 39 { 40 initializeJndiName(); 41 Class [] interfaces = getInterfaces(); 42 Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces); 43 final Class [] constructorParams = 44 {InvocationHandler .class}; 45 proxyConstructor = proxyClass.getConstructor(constructorParams); 46 } 47 48 public void start() throws Exception 49 { 50 init(); 51 52 InitialContext ctx = new InitialContext (); 53 Object proxy = createProxy(); 54 Util.rebind(ctx, jndiName, proxy); 55 } 56 57 public void stop() throws Exception 58 { 59 InitialContext ctx = new InitialContext (); 60 Util.unbind(ctx, jndiName); 61 } 62 63 protected abstract Class [] getInterfaces(); 64 65 protected abstract void initializeJndiName(); 66 67 public void setContainer(Container container) 68 { 69 this.container = container; 70 this.advisor = (Advisor) container; 71 } 72 73 } 74 | Popular Tags |