[jboss-cvs] JBossAS SVN: r66586 - branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 30 18:43:44 EDT 2007


Author: ALRubinger
Date: 2007-10-30 18:43:43 -0400 (Tue, 30 Oct 2007)
New Revision: 66586

Modified:
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
Log:
[EJBTHREE-1062] Merged fix w/ Branch_4_2

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-10-30 22:43:22 UTC (rev 66585)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-10-30 22:43:43 UTC (rev 66586)
@@ -88,34 +88,105 @@
 
    public static Class<?>[] getLocalInterfaces(Container container)
    {
-      Local li = (javax.ejb.Local) ((EJBContainer) container).resolveAnnotation(javax.ejb.Local.class);
+      // Obtain @Local
+      Local localAnnotation = (Local)((EJBContainer) container).resolveAnnotation(javax.ejb.Local.class);
 
-      if (li != null)
+      // Obtain @Remote
+      Remote remoteAnnotation = (Remote)((EJBContainer) container).resolveAnnotation(Remote.class);
+
+      // Obtain all business interfaces
+      List<Class<?>> businessInterfaces = getBusinessInterfaces(container.getBeanClass());
+
+      // 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 (localAnnotation == null && container.getBeanClass().getInterfaces().length == 1)
       {
-         if (li.value().length > 0) return li.value();
+         // Obtain the implemented interface
+         Class<?> singleInterface =  container.getBeanClass().getInterfaces()[0];
+         
+         // If not explicitly marked as @Remote, and is a valid business interface
+         if (remoteAnnotation==null
+               && businessInterfaces.contains(singleInterface))
+         {
+            // Return the implemented interface  
+            return container.getBeanClass().getInterfaces();            
+         }
+      }
 
-         // We have an emtpy @Local annotated bean class
+      // If @Local is present
+      if (localAnnotation != null)
+      {
+         // If @Local.value is defined
+         if (localAnnotation.value().length > 0)
+         {
+            // Return the value array defined
+            return localAnnotation.value();
+         }
+  
+         // If @Local is defined with no value and there are no business interfaces
+         if (businessInterfaces.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 (businessInterfaces.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 : businessInterfaces)
+            {
+               // 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
+            {
+               // If not explicitly marked as @Remote
+               if (remoteAnnotation == 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);
+            }
+         }
+         
+         Class[] rtn = {(Class) businessInterfaces.get(0)};
+         localAnnotation = new LocalImpl(rtn);
+         ((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, localAnnotation);
          return rtn;
       }
 
       Class beanClass = container.getBeanClass();
       String endpoint = getEndpointInterface(container);
-      Class[] ri = getRemoteInterfaces(container);
+      Class[] remoteInterfaces = getRemoteInterfaces(container);
 
-      if (li == null && ri == null && endpoint == null && (beanClass.getInterfaces() == null || beanClass.getInterfaces().length == 0))
+      if (localAnnotation == null && (remoteInterfaces != null && remoteInterfaces.length == 0) && endpoint == null
+            && (beanClass.getInterfaces() == null || beanClass.getInterfaces().length == 0))
          throw new RuntimeException("bean class has no local, webservice, or remote interfaces defined and does not implement at least one business interface: " + container.getEjbName());
 
       // introspect implemented interfaces.
-      if (li == null)
+      if (localAnnotation == null)
       {
          List<Class<?>> intfs = getBusinessInterfaces(beanClass);
          ArrayList<Class> locals = new ArrayList<Class>();
@@ -128,22 +199,22 @@
          }
          if (locals.size() > 0)
          {
-            li = new LocalImpl(locals.toArray(new Class[]{}));
-            ((Advisor) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, li);
+            localAnnotation = new LocalImpl(locals.toArray(new Class[]{}));
+            ((Advisor) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, localAnnotation);
             //return li.value(); ALR Removed (EJBTHREE-751)
          }
       }
       // no @Local interfaces implemented
-      if (li == null)
+      if (localAnnotation == null)
       {
          // search for default
          List<Class<?>> interfaces = getBusinessInterfaces(beanClass);
          if (interfaces.size() != 1) return null; // indeterminate
 
          Class intf = interfaces.get(0);
-         if (ri != null)
+         if (remoteInterfaces != null)
          {
-            for (Class rintf : ri)
+            for (Class rintf : remoteInterfaces)
             {
                if (intf.getName().equals(rintf.getName()))
                {
@@ -154,19 +225,19 @@
          if (intf.getName().equals(endpoint)) return null;
 
          Class[] rtn = {intf};
-         li = new LocalImpl(rtn);
-         ((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, li);
+         localAnnotation = new LocalImpl(rtn);
+         ((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Local.class, localAnnotation);
          return rtn;
       }
       
 
       // Check to ensure @Local and @Remote are not defined on the same interface
       // JIRA EJBTHREE-751
-      if(ri != null)
+      if (remoteInterfaces != null)
       {
-         for (Class remoteInterface : ri)
+         for (Class<?> remoteInterface : remoteInterfaces)
          {
-            for (Class localInterface : li.value())
+            for (Class<?> localInterface : localAnnotation.value())
             {
                if (localInterface.equals(remoteInterface))
                {
@@ -177,7 +248,7 @@
          }
       }
       
-      return li.value();
+      return localAnnotation.value();
    }
 
    /**
@@ -522,4 +593,4 @@
       
       return clientBindUrl;
    }
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list