openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r504970 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java
Date Thu, 08 Feb 2007 17:21:20 GMT
Author: kwsutter
Date: Thu Feb  8 09:21:19 2007
New Revision: 504970

URL: http://svn.apache.org/viewvc?view=rev&rev=504970
Log:
OPENJPA-133.  Change the processing of the getMethod() method to properly recognize non-public
callback methods, along with validating the parameter types.

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java?view=diff&rev=504970&r1=504969&r2=504970
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java
Thu Feb  8 09:21:19 2007
@@ -96,8 +96,9 @@
      * the proper exception on error.
      */
     protected static Method getMethod(Class cls, String method, Class[] args) {
-        try {
-            Method[] methods = cls.getMethods();
+        Class currentClass = cls;
+        do {
+            Method[] methods = currentClass.getDeclaredMethods();
             for (int i = 0; i < methods.length; i++) {
                 if (!method.equals(methods[i].getName()))
                     continue;
@@ -105,23 +106,11 @@
                 if (isAssignable(methods[i].getParameterTypes(), args))
                     return methods[i];
             }
+        } while ((currentClass = currentClass.getSuperclass()) != null);
 
-            return cls.getMethod(method, args);
-
-        } catch (Throwable t) {
-            try {
-                // try again with the declared methods, which will
-                // check private and protected methods
-                Method m = cls.getDeclaredMethod(method, args);
-                if (!m.isAccessible())
-                    m.setAccessible(true);
-                return m;
-            } catch (Throwable t2) {
-                throw new UserException(_loc.get("method-notfound",
-                    cls.getName(), method,
-                        args == null ? null : Arrays.asList(args)), t);
-            }
-		}
+        // if we get here, no suitable method was found
+        throw new UserException(_loc.get("method-notfound", cls.getName(),
+                method, args == null ? null : Arrays.asList(args)));
 	}
 
     /** 



Mime
View raw message