You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by xu...@apache.org on 2011/06/20 05:11:53 UTC

svn commit: r1137487 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic: InterceptorBindingBuilder.java MethodInfoUtil.java

Author: xuhaihong
Date: Mon Jun 20 03:11:53 2011
New Revision: 1137487

URL: http://svn.apache.org/viewvc?rev=1137487&view=rev
Log:
The method comparing logic in InterceptorBindingBuilder could not handler array type correctly, turn to use the existed MethodInfoUtils

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfoUtil.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java?rev=1137487&r1=1137486&r2=1137487&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java Mon Jun 20 03:11:53 2011
@@ -71,7 +71,7 @@ public class InterceptorBindingBuilder {
         }
 
         for (InterceptorInfo info : ejbJarInfo.interceptors) {
-            Class clazz = null;
+            Class<?> clazz = null;
             try {
                 clazz = Class.forName(info.clazz, true, cl);
             } catch (ClassNotFoundException e) {
@@ -93,7 +93,7 @@ public class InterceptorBindingBuilder {
     }
 
     public void build(BeanContext beanContext, EnterpriseBeanInfo beanInfo) {
-        Class clazz = beanContext.getBeanClass();
+        Class<?> clazz = beanContext.getBeanClass();
 
         InterceptorData beanAsInterceptor = new InterceptorData(clazz);
         
@@ -249,35 +249,7 @@ public class InterceptorBindingBuilder {
         if (level == Level.CLASS) return true;
 
         NamedMethodInfo methodInfo = info.method;
-
-        if (!methodInfo.methodName.equals(method.getName())) return false;
-
-        // do we have parameters?
-        List<String> params = methodInfo.methodParams;
-        if (params == null) return true;
-
-        // do we have the same number of parameters?
-        if (params.size() != method.getParameterTypes().length) return false;
-
-        // match parameters names
-        Class<?>[] parameterTypes = method.getParameterTypes();
-
-        for (int i = 0; i < parameterTypes.length; i++) {
-
-            Class<?> parameterType = parameterTypes[i];
-            String methodParam = params.get(i);
-
-            try {
-                Class param = Classes.forName(methodParam, parameterType.getClassLoader());
-                if (!param.equals(parameterType)) {
-                    return false;
-                }
-            } catch (ClassNotFoundException e) {
-                return false;
-            }
-        }
-
-        return true;
+        return MethodInfoUtil.matches(method, methodInfo);
     }
 
 
@@ -295,7 +267,7 @@ public class InterceptorBindingBuilder {
      * @param callbackInfos the raw CallbackInfo objects
      * @param callbacks the collection where the created methods will be placed
      */
-    private void toMethods(Class clazz, List<CallbackInfo> callbackInfos, Set<Method> callbacks) {
+    private void toMethods(Class<?> clazz, List<CallbackInfo> callbackInfos, Set<Method> callbacks) {
         List<Method> methods = new ArrayList<Method>();
 
         for (CallbackInfo callbackInfo : callbackInfos) {
@@ -310,7 +282,7 @@ public class InterceptorBindingBuilder {
                     // check for a private method on the declared class
 
                     // find declared class
-                    Class c = clazz;
+                    Class<?> c = clazz;
                     while (c != null && !c.getName().equals(callbackInfo.className)) c = c.getSuperclass();
 
                     // get callback method
@@ -353,7 +325,7 @@ public class InterceptorBindingBuilder {
      * @param callbackInfos
      * @param callbacks
      */
-    private void toCallback(Class clazz, List<CallbackInfo> callbackInfos, Set<Method> callbacks, Class... parameterTypes) {
+    private void toCallback(Class<?> clazz, List<CallbackInfo> callbackInfos, Set<Method> callbacks, Class<?>... parameterTypes) {
         List<Method> methods = new ArrayList<Method>();
 
         for (CallbackInfo callbackInfo : callbackInfos) {
@@ -367,7 +339,7 @@ public class InterceptorBindingBuilder {
                     // check for a private method on the declared class
 
                     // find declared class
-                    Class c = clazz;
+                    Class<?> c = clazz;
                     while (c != null && !c.getName().equals(callbackInfo.className)) c = c.getSuperclass();
 
                     // get callback method
@@ -406,7 +378,7 @@ public class InterceptorBindingBuilder {
      * @return
      * @throws NoSuchMethodException if the method is not found in this class or any of its parent classes
      */
-    private Method getMethod(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException {
+    private Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
         NoSuchMethodException original = null;
         while (clazz != null){
             try {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfoUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfoUtil.java?rev=1137487&r1=1137486&r2=1137487&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfoUtil.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfoUtil.java Mon Jun 20 03:11:53 2011
@@ -500,13 +500,20 @@ public class MethodInfoUtil {
     }
 
     public static boolean matches(Method method, MethodInfo methodInfo) {
+        return matches(method, methodInfo.methodName, methodInfo.methodParams);
+    }
+
+    public static boolean matches(Method method, NamedMethodInfo methodInfo) {
+        return matches(method, methodInfo.methodName, methodInfo.methodParams);
+    }
+
+    public static boolean matches(Method method, String methodName, List<String> methodParams) {
 
-        if (!methodInfo.methodName.equals(method.getName())) {
+        if (!methodName.equals(method.getName())) {
             return false;
         }
 
         // do we have parameters?
-        List<String> methodParams = methodInfo.methodParams;
         if (methodParams == null) {
             return true;
         }