[jboss-cvs] JBossAS SVN: r64115 - in trunk/ejb3/src/main/org/jboss/ejb3: interceptor and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 18 07:56:43 EDT 2007


Author: wolfc
Date: 2007-07-18 07:56:43 -0400 (Wed, 18 Jul 2007)
New Revision: 64115

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
   trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
Log:
EJBTHREE-1016: Refactored setting up the business interfaces of a bean

Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -163,6 +163,8 @@
    
    private String partitionName;
    
+   private List<Class<?>> businessInterfaces;
+   
    /**
     * @param name                  Advisor name
     * @param manager               Domain to get interceptor bindings from
@@ -304,6 +306,19 @@
    }
    
    /**
+    * Return all the business interfaces implemented by this bean.
+    * 
+    * Available after the meta data has been processed.
+    * 
+    * @return   an array of business interfaces or empty if no interface is provided
+    */
+   public List<Class<?>> getBusinessInterfaces()
+   {
+      if(businessInterfaces == null) throw new IllegalStateException("businessInterfaces not yet initialized");
+      return businessInterfaces;
+   }
+      
+   /**
     * Returns a String identifier for this bean that is qualified by the
     * deployment, and hence should be unique across deployments. Name is of the 
     * form "ear=foo.ear,jar=foo.jar,name=Bar", where "Bar" is the value 
@@ -331,6 +346,25 @@
    }
 
    /**
+    * Is the method a business method of this container.
+    * 
+    * @param businessMethod     the method in question
+    * @return   true if so, otherwise false
+    */
+   public boolean isBusinessMethod(Method businessMethod)
+   {
+      for(Class<?> businessInterface : getBusinessInterfaces())
+      {
+         for(Method method : businessInterface.getMethods())
+         {
+            if(businessMethod.equals(method))
+               return true;
+         }
+      }
+      return false;
+   }
+   
+   /**
     * EJBContainer has finished with all metadata initialization from XML files and such.
     * this is really a hook to do some processing after XML has been set up and before
     * and processing of dependencies and such.
@@ -413,11 +447,11 @@
             }
          }
          
-         // Do not use getBusinessInterfaces, that one sucks
-         for(Class<?> businessInterface : ProxyFactoryHelper.getLocalInterfaces(this))
+         // once the metadata is setup we can resolve the business interfaces
+         this.businessInterfaces = resolveBusinessInterfaces();
+         
+         for(Class<?> businessInterface : getBusinessInterfaces())
             ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(businessInterface);
-         for(Class<?> businessInterface : ProxyFactoryHelper.getRemoteInterfaces(this))
-            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(businessInterface);
       }
       finally
       {
@@ -445,6 +479,8 @@
       this.assembly = assembly;
    }
 
+   protected abstract List<Class<?>> resolveBusinessInterfaces();
+   
    public InterceptorInfoRepository getInterceptorRepository()
    {
       return interceptorRepository;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -46,7 +46,7 @@
 import org.jboss.logging.Logger;
 
 /**
- * Comment
+ * Delegatee of a SessionContainer for managing proxy factories.
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
@@ -54,16 +54,16 @@
 public class ProxyDeployer
 {
    private static final Logger log = Logger.getLogger(ProxyDeployer.class);
-   private Container container;
-   private Advisor advisor;
+   private SessionContainer container;
    private ArrayList<ProxyFactory> proxyFactories = new ArrayList<ProxyFactory>();
    private RemoteBindings remoteBindings;
    private LocalBinding localBinding;
 
-   public ProxyDeployer(Container container)
+   public ProxyDeployer(SessionContainer container)
    {
+      assert container != null : "container is null";
+      
       this.container = container;
-      this.advisor = (Advisor) container;
    }
 
    public List<ProxyFactory> getProxyFactories() { return proxyFactories; }
@@ -109,23 +109,23 @@
 
    public void initializeLocalBindingMetadata()
    {
-      localBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
+      localBinding = (LocalBinding) container.resolveAnnotation(LocalBinding.class);
       if (localBinding == null)
       {
          if (ProxyFactoryHelper.getLocalInterfaces(container).length > 0)
          {
             localBinding = new LocalBindingImpl(ProxyFactoryHelper.getLocalJndiName(container));
-            advisor.getAnnotations().addClassAnnotation(LocalBinding.class, localBinding);
+            container.getAnnotations().addClassAnnotation(LocalBinding.class, localBinding);
          }
       }
    }
 
    public void initializeRemoteBindingMetadata()
    {
-      remoteBindings = (RemoteBindings) advisor.resolveAnnotation(RemoteBindings.class);
+      remoteBindings = (RemoteBindings) container.resolveAnnotation(RemoteBindings.class);
       if (remoteBindings == null)
       {
-         RemoteBinding binding = (RemoteBinding) advisor.resolveAnnotation(RemoteBinding.class);
+         RemoteBinding binding = (RemoteBinding) container.resolveAnnotation(RemoteBinding.class);
          if (binding == null)
          {
             log.debug("no declared remote bindings for : " + container.getEjbName());
@@ -139,14 +139,14 @@
                factory = getDefaultRemoteProxyFactory();
                RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, factory)};
                remoteBindings = new RemoteBindingsImpl(list);
-               advisor.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
+               container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
             }
          }
          else
          {
             RemoteBinding[] list = {binding};
             remoteBindings = new RemoteBindingsImpl(list);
-            advisor.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
+            container.getAnnotations().addClassAnnotation(RemoteBindings.class, remoteBindings);
          }
       }
    }
@@ -156,7 +156,7 @@
       Class factory;
       if (container instanceof StatefulContainer)
       {
-         if (advisor.resolveAnnotation(Clustered.class) != null)
+         if (container.resolveAnnotation(Clustered.class) != null)
          {
             factory = StatefulClusterProxyFactory.class;
          }
@@ -172,7 +172,7 @@
       }
       else
       {
-         if (advisor.resolveAnnotation(Clustered.class) != null)
+         if (container.resolveAnnotation(Clustered.class) != null)
          {
             factory = StatelessClusterProxyFactory.class;
          }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -55,29 +55,14 @@
 {
    private static final Logger log = Logger.getLogger(ProxyFactoryHelper.class);
 
-   public static Context getProxyFactoryContext(Context ctx)
-           throws NamingException
+   private static String getEndpointInterface(Container container)
    {
-
-      try
-      {
-         return (Context) ctx.lookup("proxyFactory");
-      }
-      catch (NameNotFoundException e)
-      {
-         return ctx.createSubcontext("proxyFactory");
-      }
-   }
-
-   public static String getEndpointInterface(Container container)
-   {
       WebService ws = (javax.jws.WebService) ((EJBContainer) container).resolveAnnotation(javax.jws.WebService.class);
       if (ws != null)
       {
          return ws.endpointInterface();
       }
       return null;
-
    }
 
    /**
@@ -364,7 +349,7 @@
     * @param container
     * @return   the remote interfaces of the container or an empty array
     */
-   public static Class[] getRemoteInterfaces(Container container)
+   public static Class<?>[] getRemoteInterfaces(Container container)
    {
       Remote ri = (Remote) ((Advisor) container).resolveAnnotation(Remote.class);
       if (ri == null)
@@ -372,7 +357,7 @@
          Class beanClass = container.getBeanClass();
          Class[] intfs = beanClass.getInterfaces();
          ArrayList<Class> remotes = new ArrayList<Class>();
-         for (Class clazz : intfs)
+         for (Class<?> clazz : intfs)
          {
             if (clazz.isAnnotationPresent(Remote.class))
             {

Modified: trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -22,23 +22,25 @@
 package org.jboss.ejb3;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBObject;
 import javax.ejb.Handle;
 import javax.ejb.LocalHome;
 import javax.ejb.RemoteHome;
+
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.Dispatcher;
 import org.jboss.aop.MethodInfo;
-import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aspects.asynch.FutureHolder;
-import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.remoting.IsLocalInterceptor;
 import org.jboss.ejb3.stateful.StatefulContainerInvocation;
@@ -115,6 +117,14 @@
       proxyDeployer.initializeLocalBindingMetadata();
    }
 
+   protected List<Class<?>> resolveBusinessInterfaces()
+   {
+      List<Class<?>> list = new ArrayList<Class<?>>();
+      list.addAll(Arrays.asList(ProxyFactoryHelper.getLocalInterfaces(this)));
+      list.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteInterfaces(this)));
+      return list;
+   }
+   
    public void start() throws Exception
    {
       super.start();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -95,7 +95,7 @@
          try
          {
             Method method = ((MethodJoinpoint) jp).getMethod();
-            if (isBusinessMethod(container, method))
+            if (container.isBusinessMethod(method))
             {
                InterceptorInfo[] infos = container.getInterceptorRepository().getBusinessInterceptors(container, method);
                Method[] beanAroundInvoke = container.getInterceptorRepository().getBeanClassAroundInvokes(container);
@@ -115,88 +115,4 @@
    {
       throw new RuntimeException("NOT ALLOWED");
    }
-
-   private boolean isBusinessMethod(EJBContainer container, Method method)
-   {
-      long hash = MethodHashing.calculateHash(method);
-      ArrayList<Class> businessInterfaces = getBusinessInterfaces(container);
-      for (Class businessInterface : businessInterfaces)
-      {
-         for (Method interfaceMethod : businessInterface.getMethods())
-         {
-            if (MethodHashing.calculateHash(interfaceMethod) == hash)
-            {
-               return true;
-            }
-         }
-      }
-
-      return false;
-   }
-
-   private ArrayList<Class> getBusinessInterfaces(EJBContainer container)
-   {
-      ArrayList<Class> interfaces = new ArrayList<Class>();
-      if (container instanceof ConsumerContainer)
-      {
-         Producers producers = (Producers) container.resolveAnnotation(Producers.class);
-         if (producers != null)
-         {
-            for (Producer producer : producers.value())
-            {
-               interfaces.add(producer.producer());
-            }
-         }
-
-         Producer producer = (Producer) container.resolveAnnotation(Producer.class);
-         if (producer != null)
-         {
-            interfaces.add(producer.producer());
-         }
-
-         for (Class implIf : container.getBeanClass().getInterfaces())
-         {
-            if (implIf.getAnnotation(Producer.class) != null)
-            {
-               interfaces.add(implIf);
-            }
-         }
-      }
-      else if (container instanceof MDB)
-      {
-         interfaces.add(((MDB)container).getMessagingType());
-      }
-      else
-      {
-         Class[] remotes = ProxyFactoryHelper.getRemoteInterfaces(container);
-         Class[] locals = ProxyFactoryHelper.getLocalInterfaces(container);
-         interfaces.addAll(Arrays.asList(remotes));
-         interfaces.addAll(Arrays.asList(locals));
-
-         if (container instanceof ServiceContainer)
-         {
-            Management man = (Management) container.resolveAnnotation(Management.class);
-            if (man != null)
-            {
-               Class iface = man.value();
-               if (iface != null)
-               {
-                  interfaces.add(iface);
-               }
-            }
-
-            Class[] implIfaces = container.getBeanClass().getInterfaces();
-            for (Class iface : implIfaces)
-            {
-               if (iface.getAnnotation(Management.class) != null)
-               {
-                  interfaces.add(iface);
-               }
-            }
-         }
-      }
-
-      return interfaces;
-   }
-
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -49,6 +49,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -140,7 +141,7 @@
    
    public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
    {     
-      if (info.getAdvisedMethod().equals(getOnMessage()))
+      if (info.getMethod().equals(getOnMessage()))
       {
          ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
          pushEnc();
@@ -198,7 +199,42 @@
       return result;
    }
 
+   protected List<Class<?>> resolveBusinessInterfaces()
+   {
+      Class[] classInterfaces = getBeanClass().getInterfaces();
+      if (classInterfaces.length == 0) throw new RuntimeException("Bean class must implement at least one interface: " + getBeanClass().getName());
+      if (classInterfaces.length == 1)
+      {
+         List<Class<?>> list = new ArrayList<Class<?>>();
+         list.add(classInterfaces[0]);
+         return list;
+      }
+      List<Class<?>> interfaces = new ArrayList<Class<?>>();
+      Producers producers = (Producers) resolveAnnotation(Producers.class);
+      if (producers != null)
+      {
+         for (Producer producer : producers.value())
+         {
+            interfaces.add(producer.producer());
+         }
+      }
 
+      Producer producer = (Producer) resolveAnnotation(Producer.class);
+      if (producer != null)
+      {
+         interfaces.add(producer.producer());
+      }
+
+      for (Class<?> implIf : getBeanClass().getInterfaces())
+      {
+         if (implIf.getAnnotation(Producer.class) != null)
+         {
+            interfaces.add(implIf);
+         }
+      }
+      return interfaces;
+   }
+   
    /**
     * Initialize the container invoker. Sets up a connection, a server session
     * pool and a connection consumer for the configured destination.
@@ -215,54 +251,12 @@
       registerProducers();
    }
 
-   public Class[] getProducerInterfaces(Container container1)
-   {
-      Class beanClass = container1.getBeanClass();
-      Class[] interfaces = beanClass.getInterfaces();
-      if (interfaces.length == 0) throw new RuntimeException("Bean class must implement at least one interface: " + beanClass.getName());
-      if (interfaces.length == 1)
-      {
-         return interfaces;
-      }
-      ArrayList localInterfaces = new ArrayList();
-      for (int i = 0; i < interfaces.length; i++)
-      {
-         if (interfaces[i].isAnnotationPresent(Producer.class))
-         {
-            localInterfaces.add(interfaces[i]);
-         }
-      }
-      Producer annotation = (Producer)resolveAnnotation(Producer.class);
-      if (annotation != null)
-      {
-         Class producer = annotation.producer();
-         if (producer != null)
-            localInterfaces.add(producer);
-      }
-      
-      Producers producersAnnotation = (Producers)resolveAnnotation(Producers.class);
-      if (producersAnnotation != null)
-      {
-         for (Producer producerAnnotation : producersAnnotation.value())
-         {
-            Class producer = producerAnnotation.producer();
-            if (producer != null)
-               localInterfaces.add(producer);
-         }
-      }
-      
-      if (localInterfaces.size() == 0) return null;
-      interfaces = (Class[]) localInterfaces.toArray(new Class[localInterfaces.size()]);
-      return interfaces;
-   }
-
    protected void registerProducers() throws Exception
    {
       Destination dest = (Destination) getInitialContext().lookup(getDestination());
-      Class[] producers = getProducerInterfaces(this);
       MessageProperties props = (MessageProperties) resolveAnnotation(MessageProperties.class);
       if (props == null) props = new MessagePropertiesImpl();
-      for (Class producer : producers)
+      for (Class<?> producer : getBusinessInterfaces())
       {
          log.debug("Producer: " + producer.getName());
          ProducerFactory producerFactory = null;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -76,7 +76,7 @@
       super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
    }
    
-   public Class getMessagingType()
+   public Class<?> getMessagingType()
    {
       if (messagingType == null)
       {
@@ -121,6 +121,13 @@
       return result;
    }
    
+   protected List<Class<?>> resolveBusinessInterfaces()
+   {
+      List<Class<?>> list = new ArrayList<Class<?>>();
+      list.add(getMessagingType());
+      return list;
+   }
+   
    public void start() throws Exception
    {
       super.start();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-07-18 11:54:34 UTC (rev 64114)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2007-07-18 11:56:43 UTC (rev 64115)
@@ -63,6 +63,7 @@
 import javax.management.ReflectionException;
 import java.lang.reflect.Method;
 import java.util.Hashtable;
+import java.util.List;
 
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
@@ -137,7 +138,30 @@
       invokeOptionalMethod("create");
    }
 
+   protected List<Class<?>> resolveBusinessInterfaces()
+   {
+      List<Class<?>> interfaces = super.resolveBusinessInterfaces();
+      Management man = (Management) resolveAnnotation(Management.class);
+      if (man != null)
+      {
+         Class iface = man.value();
+         if (iface != null)
+         {
+            interfaces.add(iface);
+         }
+      }
 
+      Class[] implIfaces = getBeanClass().getInterfaces();
+      for (Class<?> iface : implIfaces)
+      {
+         if (iface.getAnnotation(Management.class) != null)
+         {
+            interfaces.add(iface);
+         }
+      }
+      return interfaces;
+   }
+   
    public void start() throws Exception
    {
       super.start();




More information about the jboss-cvs-commits mailing list