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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 7 15:56:46 EST 2007


Author: wolfc
Date: 2007-12-07 15:56:45 -0500 (Fri, 07 Dec 2007)
New Revision: 68055

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java
Log:
EJBTHREE-1127: Fixed finding create methods on home interfaces

Modified: trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-07 19:05:13 UTC (rev 68054)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2007-12-07 20:56:45 UTC (rev 68055)
@@ -23,8 +23,6 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -52,6 +50,7 @@
 import org.jboss.ejb3.jndipolicy.DefaultJndiBindingPolicy;
 import org.jboss.ejb3.jndipolicy.Ejb3DeploymentSummary;
 import org.jboss.ejb3.jndipolicy.impl.PackagingBasedJndiBindingPolicy;
+import org.jboss.ejb3.lang.ClassHelper;
 import org.jboss.ejb3.remoting.RemoteProxyFactory;
 import org.jboss.ejb3.service.ServiceContainer;
 import org.jboss.ejb3.session.SessionContainer;
@@ -694,19 +693,16 @@
       // Ensure we've been passed a Home or LocalHome interface
       assert (EJBHome.class.isAssignableFrom(homeInterface) || EJBLocalHome.class.isAssignableFrom(homeInterface));
 
-      Method createMethod = null;
-      try
+      // 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");
+      if(createMethods.size() == 0)
       {
-         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();
+      return createMethods.get(0).getReturnType();
    }
 
    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-07 19:05:13 UTC (rev 68054)
+++ trunk/ejb3/src/main/org/jboss/ejb3/lang/ClassHelper.java	2007-12-07 20:56:45 UTC (rev 68055)
@@ -22,7 +22,9 @@
 package org.jboss.ejb3.lang;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Usefull methods for classes.
@@ -78,10 +80,26 @@
    }
    
    /**
+    * Find all methods with a specific name on a class and it's super classes
+    * regardless of parameter signature.
+    * 
+    * @param cls            the class to scan
+    * @param methodName     the name of the methods to find
+    * @return               a list of methods found, or empty
+    */
+   public static List<Method> getAllMethodsByName(Class<?> cls, String methodName)
+   {
+      List<Method> methods = new ArrayList<Method>();
+      populateWithMethodsByName(methods, cls, methodName);
+      return methods;
+   }
+   
+   /**
     * Returns the <code>Method</code> with the given attributes of either this class
     * or one of it's super classes.
     * 
     * TODO: return type specifics are not considered
+    * FIXME: rename method (it must return all modifiers)
     * 
     * @param cls            class to scan
     * @param methodName     the name of the method
@@ -100,4 +118,19 @@
       
       return result;
    }
+   
+   private static void populateWithMethodsByName(List<Method> methods, Class<?> cls, String methodName)
+   {
+      // Top of the world
+      if(cls == null)
+         return;
+      
+      for(Method method : cls.getDeclaredMethods())
+      {
+         if(method.getName().equals(methodName))
+            methods.add(method);
+      }
+      
+      populateWithMethodsByName(methods, cls.getSuperclass(), methodName);
+   }
 }




More information about the jboss-cvs-commits mailing list