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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 4 23:37:35 EST 2007


Author: ALRubinger
Date: 2007-12-04 23:37:35 -0500 (Tue, 04 Dec 2007)
New Revision: 67925

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
Log:
[EJBTHREE-1127] Fixes to look for Remote/Local interfaces as return type of Remote/Local Home create method

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -21,11 +21,14 @@
  */
 package org.jboss.ejb3;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
 import javax.ejb.EJBLocalObject;
 import javax.ejb.EJBObject;
 import javax.ejb.Local;
@@ -171,9 +174,23 @@
       Class<?> beanClass = container.getBeanClass();
       String endpoint = getEndpointInterface(container);
       Class<?>[] remoteInterfaces = getRemoteAndBusinessRemoteInterfaces(container);
+      
+      // EJBTHREE-1127
+      // Determine remote interface from return value of "create" in Local Home
+      LocalHome localHomeAnnotation = ((EJBContainer)container).getAnnotation(LocalHome.class);
+      if(localHomeAnnotation!=null)
+      {
+         localAnnotation = new LocalImpl(new Class<?>[]
+         {ProxyFactoryHelper.getTypeFromCreateMethod(localHomeAnnotation.value())});
+      }
 
-      if (localAnnotation == 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());
+      if (localAnnotation == null && remoteInterfaces.length == 0 && endpoint == null
+            && (beanClass.getInterfaces() == null || beanClass.getInterfaces().length == 0))
+         throw new RuntimeException(
+               "Bean Class "
+                     + beanClass.getName()
+                     + " has no local, webservice, or remote interfaces defined and does not implement at least one business interface: "
+                     + container.getEjbName());
 
       // introspect implemented interfaces.
       if (localAnnotation == null)
@@ -582,12 +599,15 @@
     */
    public static Class<?>[] getRemoteAndBusinessRemoteInterfaces(Container container)
    {
+      // Initialize
       Remote ri = (Remote) ((Advisor) container).resolveAnnotation(Remote.class);
+      RemoteHome remoteHomeAnnotation = ((EJBContainer)container).getAnnotation(RemoteHome.class);
+      
       if (ri == null)
       {
          Class<?> beanClass = container.getBeanClass();
          Class<?>[] intfs = ProxyFactoryHelper.getBusinessInterfaces(beanClass).toArray(new Class[]{});
-         ArrayList<Class<?>> remotes = new ArrayList<Class<?>>();
+         Set<Class<?>> remotes = new HashSet<Class<?>>();
          for (Class<?> clazz : intfs)
          {
             if (clazz.isAnnotationPresent(Remote.class))
@@ -595,6 +615,14 @@
                remotes.add(clazz);
             }
          }
+         
+         // EJBTHREE-1127
+         // Determine remote interface from return value of "create" in Remote Home
+         if(remoteHomeAnnotation!=null)
+         {
+            remotes.add(ProxyFactoryHelper.getTypeFromCreateMethod(remoteHomeAnnotation.value()));
+         }
+         
          if (remotes.size() > 0)
          {
             intfs = remotes.toArray(new Class[remotes.size()]);
@@ -609,23 +637,52 @@
       if (ri.value().length > 0) return ri.value();
 
       // Obtain business interfaces
-      Set<Class<?>> set = getBusinessInterfaces(container.getBeanClass());
+      Set<Class<?>> remoteBusinessInterfaces = getBusinessInterfaces(container.getBeanClass());
 
       // We have an emtpy @Remote annotated bean class
-      if (set.size() == 0)
+      if (remoteBusinessInterfaces.size() == 0)
          throw new RuntimeException("Use of empty @Remote on bean " + container.getEjbName()
                + " and there are no valid business interfaces");
       // More than one default interface
-      if (set.size() > 1)
+      if (remoteBusinessInterfaces.size() > 1)
          throw new RuntimeException("Use of empty @Remote on bean " + container.getEjbName()
-               + " with more than one default interface " + set);
+               + " with more than one default interface " + remoteBusinessInterfaces);
+      // Only one default interface
       Class<?>[] rtn =
-      {(Class<?>) set.iterator().next()};
+      {(Class<?>) remoteBusinessInterfaces.iterator().next()};
       ri = new RemoteImpl(rtn);
       ((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Remote.class, ri);
       return rtn;
    }
+   
+   
+   /**
+    * Obtains the return type of the "create" method for the specified home interface
+    *  
+    * @param homeInterface
+    * @return
+    * @throws NoSuchMethodException
+    */
+   private static Class<?> getTypeFromCreateMethod(Class<?> homeInterface)
+   {
+      // Ensure we've been passed a Home or LocalHome interface
+      assert (EJBHome.class.isAssignableFrom(homeInterface) || EJBLocalHome.class.isAssignableFrom(homeInterface));
 
+      Method createMethod = null;
+      try
+      {
+         createMethod = homeInterface.getMethod("create", new Class<?>[]
+         {});
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         throw new RuntimeException("EJB3.0 Specification Violation (4.6.8 Bullet 5): EJB2.1 Home Interface "
+               + homeInterface + " does not declare a \'create\' method");
+      }
+
+      return createMethod.getReturnType();
+   }
+
    public static String getClientBindUrl(RemoteBinding binding) throws Exception
    {
       String clientBindUrl = binding.clientBindUrl();

Modified: trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.session;
 
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
 import javax.ejb.EJBLocalObject;
 import javax.ejb.EJBMetaData;
 import javax.ejb.EJBObject;
@@ -118,17 +120,17 @@
     * @param localOrRemoteInterfaces
     * @throws RuntimeException
     */
-   protected void ensureEjb21ViewComplete(Object home,Class<?>[] localOrRemoteInterfaces) throws RuntimeException
+   protected void ensureEjb21ViewComplete(Class<?> home,Class<?>[] localOrRemoteInterfaces) throws RuntimeException
    {
-//      // Ensure specified home is EJBHome or EJBLocalHome
-//      assert(home instanceof EJBHome || home instanceof EJBLocalHome);
-//      
-//      // Ensure all interfaces passed are either EJBObject or EJBLocalObject
-//      for(Class<?> localOrRemoteInterface : localOrRemoteInterfaces)
-//      {
-//         assert (EJBObject.class.isAssignableFrom(localOrRemoteInterface) || EJBLocalObject.class
-//               .isAssignableFrom(localOrRemoteInterface));
-//      }
+      // Ensure specified home is EJBHome or EJBLocalHome
+      assert (home == null || (EJBHome.class.isAssignableFrom(home) || EJBLocalHome.class.isAssignableFrom(home)));
+
+      // Ensure all interfaces passed are either EJBObject or EJBLocalObject
+      for (Class<?> localOrRemoteInterface : localOrRemoteInterfaces)
+      {
+         assert (EJBObject.class.isAssignableFrom(localOrRemoteInterface) || EJBLocalObject.class
+               .isAssignableFrom(localOrRemoteInterface));
+      }
       
       // If home is defined and there are no local/remote interfaces
       if (home != null && localOrRemoteInterfaces.length == 0)

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -64,7 +64,8 @@
       localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(container)));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(localHome, ProxyFactoryHelper.getLocalInterfaces(container));
+      this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
+            .getLocalInterfaces(container));
 
       // Add JBossProxy
       localInterfaces.add(JBossProxy.class);

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -86,7 +86,8 @@
       remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container)));
 
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome, ProxyFactoryHelper.getRemoteInterfaces(container));
+      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+            .getRemoteInterfaces(container));
 
       // Add JBossProxy
       remoteInterfaces.add(JBossProxy.class);

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -66,7 +66,8 @@
       localInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(container)));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(localHome, ProxyFactoryHelper.getLocalInterfaces(container));
+      this.ensureEjb21ViewComplete(localHome == null ? null : localHome.value(), ProxyFactoryHelper
+            .getLocalInterfaces(container));
 
       // Ensure local interfaces defined
       if (localInterfaces.size() > 0)

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-12-05 04:33:55 UTC (rev 67924)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2007-12-05 04:37:35 UTC (rev 67925)
@@ -77,7 +77,8 @@
       remoteInterfaces.addAll(Arrays.asList(ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container)));
       
       // Ensure that if EJB 2.1 Components are defined, they're complete
-      this.ensureEjb21ViewComplete(remoteHome, ProxyFactoryHelper.getRemoteInterfaces(container));
+      this.ensureEjb21ViewComplete(remoteHome == null ? null : remoteHome.value(), ProxyFactoryHelper
+            .getRemoteInterfaces(container));
 
       // Ensure remote interfaces defined
       if (remoteInterfaces.size() > 0)




More information about the jboss-cvs-commits mailing list