openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r443509 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/event/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/main/resources/org/apache/openjpa/event/ openjpa-persistence/src/main/jav...
Date Thu, 14 Sep 2006 23:06:13 GMT
Author: mprudhom
Date: Thu Sep 14 16:06:11 2006
New Revision: 443509

URL: http://svn.apache.org/viewvc?view=rev&rev=443509
Log:
Allow callback methods to accept the Entity subclass of the type they are listening on, rather
than forcing them to all take an argument of type java.lang.Object (section 3.5.1)

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BeanLifecycleCallbacks.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/MethodLifecycleCallbacks.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BeanLifecycleCallbacks.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BeanLifecycleCallbacks.java?view=diff&rev=443509&r1=443508&r2=443509
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BeanLifecycleCallbacks.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BeanLifecycleCallbacks.java
Thu Sep 14 16:06:11 2006
@@ -38,9 +38,10 @@
      *
      * @arg whether another argunent is expected such as AfterDetach
      */
-    public BeanLifecycleCallbacks(Class cls, String method, boolean arg) {
+    public BeanLifecycleCallbacks(Class cls, String method, boolean arg,
+        Class type) {
         this(cls, getMethod(cls, method, arg ? new Class[]{ Object.class,
-            Object.class } : new Class[]{ Object.class }), arg);
+            type } : new Class[]{ type }), arg);
     }
 
     /**

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=443509&r1=443508&r2=443509
==============================================================================
--- 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 Sep 14 16:06:11 2006
@@ -16,6 +16,7 @@
 package org.apache.openjpa.event;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
 
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.UserException;
@@ -92,7 +93,14 @@
      */
     protected static Method getMethod(Class cls, String method, Class[] args) {
         try {
-            return cls.getMethod(method, args);
+            Method[] methods = cls.getMethods();
+            for (int i = 0; i < methods.length; i++) {
+                if (!method.equals(methods[i].getName()))
+                    continue;
+
+                if (isAssignable(methods[i].getParameterTypes(), args))
+                    return methods[i];
+            }
         } catch (Throwable t) {
             try {
                 // try again with the declared methods, which will
@@ -103,8 +111,32 @@
                 return m;
             } catch (Throwable t2) {
                 throw new UserException(_loc.get("method-notfound",
-                    cls.getName(), method), t);
+                    cls.getName(), method,
+                        args == null ? null : Arrays.asList(args)), t);
             }
 		}
+
+        throw new UserException(_loc.get("method-notfound",
+            cls.getName(), method,
+                args == null ? null : Arrays.asList(args)));
 	}
+
+    /** 
+     * Returns true if all parameters in the from array are assignable
+     * from the corresponding parameters of the to array. 
+     */
+    private static boolean isAssignable(Class[] from, Class[] to) {
+        if (from == null)
+            return to == null;
+
+        if (from.length != to.length)
+            return false;
+
+        for (int i = 0; i < from.length; i++) {
+            if (from[i] == null || !from[i].isAssignableFrom(to[i]))
+                return false;
+        }
+
+        return true;
+    } 
 }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java?view=diff&rev=443509&r1=443508&r2=443509
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
Thu Sep 14 16:06:11 2006
@@ -205,7 +205,7 @@
             return true;
         try {
             Method meth = iface.getDeclaredMethod("is" + StringUtils.capitalize
-                (fmd.getName()), null);
+                (fmd.getName()), (Class[]) null);
             return meth == null;
         } catch (NoSuchMethodException e) {}
         return true;

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties?view=diff&rev=443509&r1=443508&r2=443509
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/event/localizer.properties
Thu Sep 14 16:06:11 2006
@@ -75,4 +75,5 @@
 tcp-wrong-version-error: Received packet from "{0}" with invalid version \
 	number. Check if a prior release of OpenJPA is being used on this host.
 bean-constructor: Could not instantiate class {0}.
-method-notfound: Method "{1}" not found in class "{0}".
+method-notfound: Method "{1}" with arguments of type: {2} \
+    not found in class "{0}".

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?view=diff&rev=443509&r1=443508&r2=443509
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Thu Sep 14 16:06:11 2006
@@ -1528,6 +1528,11 @@
             return false;
         boolean system = currentElement() == null;
 
+        Class type = currentElement() == null ? null :
+            ((ClassMetaData) currentElement()).getDescribedType();
+        if (type == null)
+            type = Object.class;
+
         if (_callbacks == null) {
             _callbacks = (Collection<LifecycleCallbacks>[])
                 new Collection[LifecycleEvent.ALL_EVENTS.length];
@@ -1538,7 +1543,7 @@
         LifecycleCallbacks adapter;
         if (_listener != null)
             adapter = new BeanLifecycleCallbacks(_listener,
-                attrs.getValue("method-name"), false);
+                attrs.getValue("method-name"), false, type);
         else
             adapter = new MethodLifecycleCallbacks(_cls,
                 attrs.getValue("method-name"), false);



Mime
View raw message