1 22 package org.jboss.ejb3.service; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.InvocationHandler ; 26 import javax.naming.Context ; 27 import javax.naming.NamingException ; 28 29 import org.jboss.aop.Advisor; 30 import org.jboss.ejb3.Container; 31 import org.jboss.ejb3.ProxyFactory; 32 import org.jboss.naming.Util; 33 34 38 public abstract class BaseServiceProxyFactory implements ProxyFactory 39 { 40 41 protected Class proxyClass; 42 protected Constructor proxyConstructor; 43 protected Context proxyFactoryContext; 44 protected String jndiName; 45 protected Container container; 46 protected Advisor advisor; 47 48 public Object createHomeProxy() 49 { 50 throw new UnsupportedOperationException ("service can't have a home interface"); 51 } 52 53 public Object createProxy(Object id) 54 { 55 if(id != null) 56 throw new IllegalArgumentException ("service proxy must not have an id"); 57 return createProxy(); 58 } 59 60 public void start() throws Exception 61 { 62 initializeJndiName(); 63 Class [] interfaces = getInterfaces(); 64 Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces); 65 final Class [] constructorParams = 66 {InvocationHandler .class}; 67 proxyConstructor = proxyClass.getConstructor(constructorParams); 68 69 try 70 { 71 Util.rebind(container.getInitialContext(), jndiName, createProxy()); 72 } catch (NamingException e) 73 { 74 NamingException namingException = new NamingException ("Could not bind service proxy factory for EJB container with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName); 75 namingException.setRootCause(e); 76 throw namingException; 77 } 78 } 79 80 public void stop() throws Exception 81 { 82 Util.unbind(container.getInitialContext(), jndiName); 83 } 84 85 protected abstract Class [] getInterfaces(); 86 87 protected abstract void initializeJndiName(); 88 89 public void setContainer(Container container) 90 { 91 this.container = container; 92 this.advisor = (Advisor) container; 93 } 94 95 } 96 | Popular Tags |