[jboss-cvs] JBossAS SVN: r66065 - trunk/ejb3/src/main/org/jboss/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 11 22:30:23 EDT 2007


Author: ALRubinger
Date: 2007-10-11 22:30:23 -0400 (Thu, 11 Oct 2007)
New Revision: 66065

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
Log:
EJBTHREE-1062: Fixes for the case in which a single interface exists on bean class and should be inherently exposed as local business interface if not specified as otherwise.  Spec EJB 3.0 - 4.6.6

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-10-12 00:56:27 UTC (rev 66064)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-10-12 02:30:23 UTC (rev 66065)
@@ -77,18 +77,87 @@
    public static Class<?>[] getLocalInterfaces(Container container)
    {
       Local li = (javax.ejb.Local) ((EJBContainer) container).resolveAnnotation(javax.ejb.Local.class);
+      
+      // JIRA EJBTHREE-1062
+      // EJB 3 4.6.6
+      // If no @Local is defined on the bean class, and the bean class implements a single interface, 
+      // this interface is a local business interface unless denoted otherwise
+      if (li == null && container.getBeanClass().getInterfaces().length == 1)
+      {
+         // Obtain the implemented interface
+         Class<?> singleInterface =  container.getBeanClass().getInterfaces()[0];
+         
+         // If not explicitly marked as @Remote
+         if (singleInterface.getAnnotation(Remote.class) == null
+               && container.getBeanClass().getAnnotation(Remote.class) == null)
+         {
+            // Return the implemented interface  
+            return container.getBeanClass().getInterfaces();            
+         }
+      }
 
+      // If @Local is present
       if (li != null)
       {
-         if (li.value().length > 0) return li.value();
+         // If @Local.value is defined
+         if (li.value().length > 0)
+         {
+            // Return the value array defined
+            return li.value();
+         }
 
-         // We have an emtpy @Local annotated bean class
+         // Obtain all business interfaces
+         List<Class<?>> list = getBusinessInterfaces(container.getBeanClass());
+            
+         // If @Local is defined with no value and there are no business interfaces
+         if (list.size() == 0){
+            throw new RuntimeException("Use of empty @Local on bean class and there are no valid business interfaces: " + container.getEjbName());            
+         }
+         // If @Local is defined with no value and there is more than one business interface 
+         else if (list.size() > 0)
+         {
+            // Define list to hold all interfaces implemented directly by bean class that are valid business interfaces
+            List<Class<?>> beanClassBusinessInterfaces = new ArrayList<Class<?>>();
+            // All business interfaces
+            for(Class<?> businessInterface : list)
+            {
+               // All interfaces directly implemented by bean class
+               for(Class<?> beanClassInterface : container.getBeanClass().getInterfaces())
+               {
+                  // If interface directly implemented by bean class is business interface
+                  if(businessInterface.equals(beanClassInterface))
+                  {
+                     // Add to list
+                     beanClassBusinessInterfaces.add(businessInterface);
+                  }
+               }
+            }
+            
+            // If more than one business interface is directly implemented by the bean class
+            if(beanClassBusinessInterfaces.size()>1)
+            {
+               throw new RuntimeException("Use of empty @Local on bean class and there are more than one default interface: " + container.getEjbName());
+            }
+            // JIRA EJBTHREE-1062
+            // EJB 3 4.6.6
+            // If the bean class implements only one business interface, that 
+            //interface is exposed as local business if not denoted as @Remote
+            else
+            {
+               // Obtain the implemented interface
+               Class<?> singleInterface = container.getBeanClass().getInterfaces()[0];
+               // If not explicitly marked as @Remote
+               if (singleInterface.getAnnotation(Remote.class) == null
+                     && container.getBeanClass().getAnnotation(Remote.class) == null)
+               {
+                  // Return the implemented interface  
+                  return beanClassBusinessInterfaces.toArray(new Class<?>[]
+                  {});
+               }
 
-         List list = getBusinessInterfaces(container.getBeanClass());
-         if (list.size() == 0)
-            throw new RuntimeException("Use of empty @Local on bean class and there are no valid business interfaces: " + container.getEjbName());
-         if (list.size() > 1)
-            throw new RuntimeException("Use of empty @Local on bean class and there are more than one default interface: " + container.getEjbName());
+            }
+         }
+         
          Class[] rtn = {(Class) list.get(0)};
          li = new LocalImpl(rtn);
          ((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, li);
@@ -323,7 +392,7 @@
       {
          if (businessInterface.getName().equals(remoteHome.getName()))
          {
-        	 return getHomeJndiName(container);
+             return getHomeJndiName(container);
          }
       }
       Class[] locals = getLocalInterfaces(container);
@@ -339,7 +408,7 @@
       {
          if (businessInterface.getName().equals(localHome.getName()))
          {
-        	 return getLocalHomeJndiName(container);
+             return getLocalHomeJndiName(container);
          }
       }
 
@@ -508,4 +577,4 @@
      
       return clientBindUrl;
    }
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list