1 22 package org.jboss.ejb3.stateful; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.InvocationHandler ; 26 import javax.naming.Context ; 27 import javax.naming.Name ; 28 import javax.naming.NamingException ; 29 import javax.naming.RefAddr ; 30 import javax.naming.Reference ; 31 import javax.naming.StringRefAddr ; 32 import org.jboss.ejb3.JndiProxyFactory; 33 import org.jboss.ejb3.ProxyFactory; 34 import org.jboss.logging.Logger; 35 import org.jboss.naming.Util; 36 37 43 public abstract class BaseStatefulProxyFactory extends org.jboss.ejb3.session.BaseSessionProxyFactory implements ProxyFactory 44 { 45 private static final Logger log = Logger.getLogger(BaseStatefulProxyFactory.class); 46 47 protected Class proxyClass; 48 protected Constructor proxyConstructor; 49 protected Context proxyFactoryContext; 50 protected String jndiName; 51 52 public static final String PROXY_FACTORY_NAME = "StatefulProxyFactory"; 53 54 public void init() throws Exception 55 { 56 initializeJndiName(); 57 Class [] interfaces = getInterfaces(); 58 Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces); 59 final Class [] constructorParams = 60 {InvocationHandler .class}; 61 proxyConstructor = proxyClass.getConstructor(constructorParams); 62 } 63 64 public void start() throws Exception 65 { 66 init(); 67 68 Context ctx = container.getInitialContext(); 69 Name name = ctx.getNameParser("").parse(jndiName); 70 ctx = Util.createSubcontext(ctx, name.getPrefix(name.size() - 1)); 71 String atom = name.get(name.size() - 1); 72 RefAddr refAddr = new StringRefAddr (JndiProxyFactory.FACTORY, jndiName + PROXY_FACTORY_NAME); 73 Reference ref = new Reference ("java.lang.Object", refAddr, JndiProxyFactory.class.getName(), null); 74 try 75 { 76 Util.rebind(ctx, atom, ref); 77 } catch (NamingException e) 78 { 79 NamingException namingException = new NamingException ("Could not bind stateful proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom); 80 namingException.setRootCause(e); 81 throw namingException; 82 } 83 } 84 85 public void stop() throws Exception 86 { 87 Util.unbind(container.getInitialContext(), jndiName); 88 } 89 90 protected abstract Class [] getInterfaces(); 91 92 protected abstract void initializeJndiName(); 93 } 94 | Popular Tags |