FileDocCategorySizeDatePackage
BaseStatelessProxyFactory.javaAPI DocJBoss 4.2.18374Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.stateless

BaseStatelessProxyFactory

public abstract class BaseStatelessProxyFactory extends org.jboss.ejb3.session.BaseSessionProxyFactory implements org.jboss.ejb3.ProxyFactory
Comment
author
Bill Burke
version
$Revision: 62714 $

Fields Summary
private static final Logger
log
protected Context
proxyFactoryContext
protected String
jndiName
private ProxyFactory
proxyFactory
private Class
proxyClass
private Constructor
proxyConstructor
Constructors Summary
Methods Summary
protected voidbindProxy(java.lang.Object proxy)

      try
      {
         log.debug("Binding proxy for " + container.getEjbName() + " in JNDI at " + jndiName);
         Util.rebind(container.getInitialContext(), jndiName, proxy);
      } catch (NamingException e)
      {
         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
         namingException.setRootCause(e);
         throw namingException;
      }
   
protected java.lang.ObjectconstructProxy(java.lang.reflect.InvocationHandler handler)
Hide the fact that I'm now using javassist.

param
handler a JDK proxy InvocationHandler
return
a true proxy

      try
      {
         /* plain jdk */
         Object args[] = { handler };
         Object proxy = proxyConstructor.newInstance(args);
         
         /* javassist */
         /*
         MethodHandler realHandler = new MethodHandlerAdapter(handler);
//         ProxyObject proxy = (ProxyObject) proxyConstructor.newInstance((Object[]) null);
//         proxy.setHandler(realHandler);
         JavassistProxy proxy = (JavassistProxy) proxyConstructor.newInstance((Object[]) null);
         proxy.setMethodHandler(realHandler);
         JavassistProxy.pokeInterfaces(proxy, getInterfaces());
         */
         
         /* cglib */
         /*
         Object args[] = { new CGLibInvocationHandlerAdapter(handler) };
         Object proxy = proxyConstructor.newInstance(args);
         */
         
         return proxy;
      }
      catch (IllegalArgumentException e)
      {
         throw new RuntimeException(e);
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);
      }
      catch (InvocationTargetException e)
      {
         throw new RuntimeException(e.getTargetException());
      }
   
public final java.lang.ObjectcreateProxy(java.lang.Object id)

      assert id == null : "stateless bean must not have an id";
      return createProxy();
   
protected abstract java.lang.Class[]getInterfaces()

public voidinit()

      initializeJndiName();
      Class[] interfaces = getInterfaces();
      
      /* plain jdk */
      Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
      final Class[] constructorParams =
              {InvocationHandler.class};
      proxyConstructor = proxyClass.getConstructor(constructorParams);
      
      /* javassist */
      /*
      proxyFactory = new javassist.util.proxy.ProxyFactory()
      {
         @Override
         protected ClassLoader getClassLoader()
         {
            return container.getBeanClass().getClassLoader();
         }
      };
      proxyFactory.setInterfaces(interfaces);
      proxyFactory.setSuperclass(JavassistProxy.class);
      proxyClass = proxyFactory.createClass();
      proxyConstructor = proxyClass.getConstructor((Class[]) null);
      */
      
      /* cglib */
      /*
      proxyClass = net.sf.cglib.proxy.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
      final Class[] constructorParams = {net.sf.cglib.proxy.InvocationHandler.class};
      proxyConstructor = proxyClass.getConstructor(constructorParams);
      */
   
protected abstract voidinitializeJndiName()

public voidsetContainer(org.jboss.ejb3.Container container)

      this.container = container;
      this.advisor = (Advisor) container;
   
public voidstart()

      init();

      Object proxy = createProxy();
      //describeClass(proxy.getClass());
      bindProxy(proxy);
   
public voidstop()

      Util.unbind(container.getInitialContext(), jndiName);