cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r448632 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/intercept/ test/java/org/apache/cayenne/intercept/
Date Thu, 21 Sep 2006 18:56:44 GMT
Author: aadamchik
Date: Thu Sep 21 11:56:43 2006
New Revision: 448632

URL: http://svn.apache.org/viewvc?view=rev&rev=448632
Log:
CAY-660 - refactoring listener registration API to take a listener object instead of listener
class. Otherwise it is impossible to property initialize listeners (e.g. inject services)

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ListenerCallback.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ListenerCallbackTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/CallbackMap.java
Thu Sep 21 11:56:43 2006
@@ -48,13 +48,12 @@
         addCallback(entityClass, new EntityCallback(entityClass, methodName));
     }
 
-    Object addCallback(Class objectClass, String methodName, Class entityClass) {
+    void addCallback(Object listener, String methodName, Class entityClass) {
         ListenerCallback callback = new ListenerCallback(
-                objectClass,
+                listener,
                 methodName,
                 entityClass);
         addCallback(entityClass, callback);
-        return callback.getListener();
     }
 
     private void addCallback(Class entityClass, Closure callback) {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptor.java
Thu Sep 21 11:56:43 2006
@@ -102,14 +102,9 @@
         empty = false;
     }
 
-    public Object addPreUpdateCallback(
-            Class objectClass,
-            String methodName,
-            Class entityClass) {
-
-        Object callback = preUpdate.addCallback(objectClass, methodName, entityClass);
+    public void addPreUpdateCallback(Object listener, String methodName, Class entityClass)
{
+        preUpdate.addCallback(listener, methodName, entityClass);
         empty = false;
-        return callback;
     }
 
     public void addPostPersistCallback(Class entityClass, String methodName) {
@@ -117,13 +112,12 @@
         empty = false;
     }
 
-    public Object addPostPersistCallback(
-            Class objectClass,
+    public void addPostPersistCallback(
+            Object listener,
             String methodName,
             Class entityClass) {
-        Object callback = postPersist.addCallback(objectClass, methodName, entityClass);
+        postPersist.addCallback(listener, methodName, entityClass);
         empty = false;
-        return callback;
     }
 
     public void addPostRemoveCallback(Class entityClass, String methodName) {
@@ -131,13 +125,12 @@
         empty = false;
     }
 
-    public Object addPostRemoveCallback(
-            Class objectClass,
+    public void addPostRemoveCallback(
+            Object listener,
             String methodName,
             Class entityClass) {
-        Object callback = postRemove.addCallback(objectClass, methodName, entityClass);
+        postRemove.addCallback(listener, methodName, entityClass);
         empty = false;
-        return callback;
     }
 
     public void addPostUpdateCallback(Class entityClass, String methodName) {
@@ -145,13 +138,12 @@
         empty = false;
     }
 
-    public Object addPostUpdateCallback(
-            Class objectClass,
+    public void addPostUpdateCallback(
+            Object listener,
             String methodName,
             Class entityClass) {
-        Object callback = postUpdate.addCallback(objectClass, methodName, entityClass);
+        postUpdate.addCallback(listener, methodName, entityClass);
         empty = false;
-        return callback;
     }
 
     public void addPostLoadCallback(Class entityClass, String methodName) {
@@ -159,14 +151,9 @@
         empty = false;
     }
 
-    public Object addPostLoadCallback(
-            Class objectClass,
-            String methodName,
-            Class entityClass) {
-
-        Object callback = postLoad.addCallback(objectClass, methodName, entityClass);
+    public void addPostLoadCallback(Object listener, String methodName, Class entityClass)
{
+        postLoad.addCallback(listener, methodName, entityClass);
         empty = false;
-        return callback;
     }
 
     class CommitState implements GraphChangeHandler {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ListenerCallback.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ListenerCallback.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ListenerCallback.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ListenerCallback.java
Thu Sep 21 11:56:43 2006
@@ -38,26 +38,18 @@
     private Method callbackMethod;
     private Object listener;
 
-    ListenerCallback(Class objectClass, String methodName, Class entityType)
+    ListenerCallback(Object listener, String methodName, Class entityType)
             throws IllegalArgumentException {
-        this.callbackMethod = findMethod(objectClass, methodName, entityType);
-        try {
-            this.listener = objectClass.newInstance();
-        }
-        catch (Exception e) {
-            throw new IllegalArgumentException(
-                    "Error instantiating callback listener class "
-                            + objectClass.getName()
-                            + ": "
-                            + e.getMessage());
+
+        if (listener == null) {
+            throw new IllegalArgumentException("Null listener");
         }
-    }
-    
-    Object getListener() {
-        return listener;
+
+        this.callbackMethod = findMethod(listener.getClass(), methodName, entityType);
+        this.listener = listener;
     }
 
-     public void execute(Object object) {
+    public void execute(Object object) {
         try {
             callbackMethod.invoke(listener, new Object[] {
                 object

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptor.java
Thu Sep 21 11:56:43 2006
@@ -69,23 +69,20 @@
         prePersist.addCallback(entityClass, methodName);
     }
 
-    public Object addPrePersistCallback(
-            Class objectClass,
+    public void addPrePersistCallback(
+            Object listener,
             String methodName,
             Class entityClass) {
-        return prePersist.addCallback(objectClass, methodName, entityClass);
+
+        prePersist.addCallback(listener, methodName, entityClass);
     }
 
     public void addPreRemoveCallback(Class entityClass, String methodName) {
         preRemove.addCallback(entityClass, methodName);
     }
 
-    public Object addPreRemoveCallback(
-            Class objectClass,
-            String methodName,
-            Class entityClass) {
-
-        return preRemove.addCallback(objectClass, methodName, entityClass);
+    public void addPreRemoveCallback(Object listener, String methodName, Class entityClass)
{
+        preRemove.addCallback(listener, methodName, entityClass);
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/DataChannelCallbackInterceptorTst.java
Thu Sep 21 11:56:43 2006
@@ -51,11 +51,8 @@
         a1.resetCallbackFlags();
         assertFalse(a1.isPreUpdated());
 
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPreUpdateCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPreUpdateCallback(listener2, "publicCallback", Artist.class);
 
         a1.setArtistName("AA");
         context.commitChanges();
@@ -89,11 +86,8 @@
         a1.resetCallbackFlags();
         assertFalse(a1.isPostUpdated());
 
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPostUpdateCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPostUpdateCallback(listener2, "publicCallback", Artist.class);
 
         a1.setArtistName("AA");
         context.commitChanges();
@@ -115,11 +109,8 @@
         context.commitChanges();
 
         i.addPostRemoveCallback(Artist.class, "postRemoveCallback");
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPostRemoveCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPostRemoveCallback(listener2, "publicCallback", Artist.class);
 
         context.deleteObject(a1);
         context.commitChanges();
@@ -142,11 +133,8 @@
         assertFalse(a1.isPostPersisted());
 
         i.addPostPersistCallback(Artist.class, "postPersistCallback");
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPostPersistCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPostPersistCallback(listener2, "publicCallback", Artist.class);
 
         Artist a2 = (Artist) context.newObject(Artist.class);
         a2.setArtistName("XX");

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ListenerCallbackTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ListenerCallbackTst.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ListenerCallbackTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ListenerCallbackTst.java
Thu Sep 21 11:56:43 2006
@@ -24,8 +24,9 @@
 
     public void testPublicCallbackMethod() {
 
+        MockCallingBackListener listener = new MockCallingBackListener();
         ListenerCallback callback = new ListenerCallback(
-                MockCallingBackListener.class,
+                listener,
                 "publicCallback",
                 Object.class);
 
@@ -38,8 +39,6 @@
         assertFalse(e.privateCallbackInvoked);
         assertFalse(e.defaultCallbackInvoked);
 
-        MockCallingBackListener listener = (MockCallingBackListener) callback
-                .getListener();
         assertSame(e, listener.publicCalledbackEntity);
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java?view=diff&rev=448632&r1=448631&r2=448632
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/intercept/ObjectContextCallbackInterceptorTst.java
Thu Sep 21 11:56:43 2006
@@ -43,11 +43,8 @@
         assertNotNull(a2);
         assertTrue(a2.isPrePersisted());
 
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPrePersistCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPrePersistCallback(listener2, "publicCallback", Artist.class);
 
         Artist a3 = (Artist) i.newObject(Artist.class);
         assertNotNull(a3);
@@ -82,11 +79,8 @@
         assertFalse(a2.isPrePersisted());
         assertTrue(a2.isPreRemoved());
 
-        MockCallingBackListener listener2 = (MockCallingBackListener) i
-                .addPreRemoveCallback(
-                        MockCallingBackListener.class,
-                        "publicCallback",
-                        Artist.class);
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        i.addPreRemoveCallback(listener2, "publicCallback", Artist.class);
 
         Artist a3 = (Artist) i.newObject(Artist.class);
         a3.setArtistName("XX");



Mime
View raw message