[jboss-cvs] JBossAS SVN: r68152 - in trunk/ejb3/src/main/org/jboss/ejb3: lang and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 11 16:49:37 EST 2007


Author: ALRubinger
Date: 2007-12-11 16:49:36 -0500 (Tue, 11 Dec 2007)
New Revision: 68152

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
Log:
[EJBTHREE-1155] Return all types of "create<METHOD>" methods as valid Remote/Local interfaces.  Allow "create" to be used as a prefix for Home create methods.

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-11 21:48:16 UTC (rev 68151)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-11 21:49:36 UTC (rev 68152)
@@ -112,7 +112,7 @@
       // Determine local interface from return value of "create" in Local Home
       if(localHomeAnnotation!=null)
       {
-         localAndBusinessLocalInterfaces.add(ProxyFactoryHelper.getTypeFromCreateMethod(localHomeAnnotation.value()));
+         localAndBusinessLocalInterfaces.addAll(ProxyFactoryHelper.getReturnTypesFromCreateMethods(localHomeAnnotation.value()));
       }
       
       // For each of the business interfaces implemented by the bean class
@@ -607,7 +607,7 @@
       if (remoteHomeAnnotation != null)
       {
          remoteAndRemoteBusinessInterfaces
-               .add(ProxyFactoryHelper.getTypeFromCreateMethod(remoteHomeAnnotation.value()));
+               .addAll(ProxyFactoryHelper.getReturnTypesFromCreateMethods(remoteHomeAnnotation.value()));
       }
 
       // If @Remote is not defined
@@ -682,27 +682,41 @@
    
    
    /**
-    * Obtains the return type of the "create" method for the specified home interface
+    * Obtains the return types declared by the "create" methods for the specified home interface
     *  
     * @param homeInterface
     * @return
-    * @throws NoSuchMethodException
     */
-   private static Class<?> getTypeFromCreateMethod(Class<?> homeInterface)
+   private static Set<Class<?>> getReturnTypesFromCreateMethods(Class<?> homeInterface)
    {
-      // Ensure we've been passed a Home or LocalHome interface
+      // Ensure we've been passed a Home or LocalHome interface (Developers only)
       assert (EJBHome.class.isAssignableFrom(homeInterface) || EJBLocalHome.class.isAssignableFrom(homeInterface));
+      
+      if(!EJBHome.class.isAssignableFrom(homeInterface) && !EJBLocalHome.class.isAssignableFrom(homeInterface)){
+         throw new RuntimeException("Declared EJB 2.1 Home Interface " + homeInterface.getName() + " does not extend "
+               + EJBHome.class.getName() + " or " + EJBLocalHome.class.getName()
+               + " as required by EJB 3.0 Core Specification 4.6.8 and 4.6.10");
+      }
 
-      // TODO: check all create methods
-      // For now we pick the first create we find and use it's return type
-      List<Method> createMethods = ClassHelper.getAllMethodsByName(homeInterface, "create");
+      // Initialize
+      Set<Class<?>> types = new HashSet<Class<?>>();
+      
+      // Obtain all "create<METHOD>" methods
+      List<Method> createMethods = ClassHelper.getAllMethodsByPrefix(homeInterface, "create");
       if(createMethods.size() == 0)
       {
-         throw new RuntimeException("EJB3.0 Specification Violation (4.6.8 Bullet 5): EJB2.1 Home Interface "
-               + homeInterface + " does not declare a \'create\' method");
+         throw new RuntimeException("EJB 3.0 Core Specification Violation (4.6.8 Bullet 5): EJB2.1 Home Interface "
+               + homeInterface + " does not declare a \'create<METHOD>\' method");
       }
+      
+      // Add all return types
+      for(Method method : createMethods)
+      {
+         types.add(method.getReturnType());
+      }
 
-      return createMethods.get(0).getReturnType();
+      // Return
+      return types;
    }
 
    public static String getClientBindUrl(RemoteBinding binding) throws Exception

Modified: trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java	2007-12-11 21:48:16 UTC (rev 68151)
+++ trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java	2007-12-11 21:49:36 UTC (rev 68152)
@@ -30,7 +30,7 @@
  * Usefull methods for classes.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class ClassHelper
 {
@@ -95,6 +95,21 @@
    }
    
    /**
+    * Find all methods starting with the specified prefix on the specified
+    * class
+    * 
+    * @param clazz
+    * @param methodNamePrefix
+    * @return
+    */
+   public static List<Method> getAllMethodsByPrefix(Class<?> clazz, String methodNamePrefix)
+   {
+      List<Method> methods = new ArrayList<Method>();
+      ClassHelper.populateWithMethodsByPrefix(methods, clazz, methodNamePrefix);
+      return methods;
+   }
+   
+   /**
     * Returns the <code>Method</code> with the given attributes of either this class
     * or one of it's super classes.
     * 
@@ -133,4 +148,22 @@
       
       populateWithMethodsByName(methods, cls.getSuperclass(), methodName);
    }
+   
+   private static void populateWithMethodsByPrefix(List<Method> methods, Class<?> clazz, String methodNamePrefix)
+   {
+      // Exit Condition
+      if (clazz == null)
+      {
+         return;
+      }
+
+      // For all declared methods
+      for (Method method : clazz.getDeclaredMethods())
+      {
+         if (method.getName().startsWith(methodNamePrefix))
+            methods.add(method);
+      }
+
+      populateWithMethodsByPrefix(methods, clazz.getSuperclass(), methodNamePrefix);
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-12-11 21:48:16 UTC (rev 68151)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2007-12-11 21:49:36 UTC (rev 68152)
@@ -629,9 +629,9 @@
            throws Exception
    {
       Method unadvisedMethod = info.getUnadvisedMethod();
-      if (unadvisedMethod.getName().equals("create"))
+      if (unadvisedMethod.getName().startsWith("create"))
       {
-         Class[] initParameterTypes =
+         Class<?>[] initParameterTypes =
                  {};
          Object[] initParameterValues =
                  {};
@@ -675,13 +675,13 @@
    
    public Object createRemoteProxy(Object id, RemoteBinding binding) throws Exception
    {
-//      RemoteBinding binding = null;
-//      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
-//      if (bindings != null)
-//         binding = bindings.value()[0];
-//      else
-//         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
-      
+      //      RemoteBinding binding = null;
+      //      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
+      //      if (bindings != null)
+      //         binding = bindings.value()[0];
+      //      else
+      //         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
+
       StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory(this, binding);
       factory.init();
 
@@ -700,7 +700,7 @@
                                                  StatefulRemoteInvocation statefulInvocation) throws Throwable
    {
       Method unadvisedMethod = info.getUnadvisedMethod();
-      if (unadvisedMethod.getName().equals("create"))
+      if (unadvisedMethod.getName().startsWith("create"))
       {
          Class[] initParameterTypes =
                  {};




More information about the jboss-cvs-commits mailing list