cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r504514 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map: DataMap.java EntityResolver.java ObjEntity.java
Date Wed, 07 Feb 2007 11:57:45 GMT
Author: aadamchik
Date: Wed Feb  7 03:57:44 2007
New Revision: 504514

URL: http://svn.apache.org/viewvc?view=rev&rev=504514
Log:
CAY-738: Support for mapping of LifecycleEventCallbacks in the Modeler
fixing a default listener definition in the DataMap 

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?view=diff&rev=504514&r1=504513&r2=504514
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
Wed Feb  7 03:57:44 2007
@@ -25,6 +25,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -120,6 +121,8 @@
     private SortedMap procedureMap;
     private SortedMap queryMap;
 
+    private List defaultEntityListeners;
+
     /**
      * Creates a new unnamed DataMap.
      */
@@ -141,6 +144,7 @@
         dbEntityMap = new TreeMap();
         procedureMap = new TreeMap();
         queryMap = new TreeMap();
+        defaultEntityListeners = new ArrayList(3);
 
         setName(mapName);
         initWithProperties(properties);
@@ -557,6 +561,18 @@
     }
 
     /**
+     * Removes an {@link EntityListener} descriptor with matching class name from entity
+     * listeners and default entity listeners.
+     * 
+     * @since 3.0
+     */
+    public void removeEntityListener(String className) {
+        if (entityListenersMap.remove(className) != null) {
+            removeDefaultEntityListener(className);
+        }
+    }
+
+    /**
      * Adds an embeddable object to the DataMap.
      * 
      * @since 3.0
@@ -698,6 +714,68 @@
         }
 
         return namespace != null ? namespace.getEntityListener(className) : null;
+    }
+
+    /**
+     * Returns an unmodifiable list of default {@link EntityListener} objects. Note that
+     * since the order of listeners is significant a list, not just a generic Collection
+     * is returned.
+     * 
+     * @since 3.0
+     */
+    public List getDefaultEntityListeners() {
+        return Collections.unmodifiableList(defaultEntityListeners);
+    }
+
+    /**
+     * Adds a new EntityListener.
+     * 
+     * @since 3.0
+     * @throws IllegalArgumentException if a listener for the same class name is already
+     *             registered.
+     */
+    public void addDefaultEntityListener(EntityListener listener) {
+        Iterator it = defaultEntityListeners.iterator();
+        while (it.hasNext()) {
+            EntityListener next = (EntityListener) it.next();
+            if (listener.getClassName().equals(next.getClassName())) {
+                throw new IllegalArgumentException("Duplicate default listener for "
+                        + next.getClassName());
+            }
+        }
+
+        defaultEntityListeners.add(listener);
+    }
+
+    /**
+     * Removes a listener matching class name.
+     * 
+     * @since 3.0
+     */
+    public void removeDefaultEntityListener(String className) {
+        Iterator it = defaultEntityListeners.iterator();
+        while (it.hasNext()) {
+            EntityListener next = (EntityListener) it.next();
+            if (className.equals(next.getClassName())) {
+                it.remove();
+                break;
+            }
+        }
+    }
+
+    /**
+     * @since 3.0
+     */
+    public EntityListener getDefaultEntityListener(String className) {
+        Iterator it = defaultEntityListeners.iterator();
+        while (it.hasNext()) {
+            EntityListener next = (EntityListener) it.next();
+            if (className.equals(next.getClassName())) {
+                return next;
+            }
+        }
+
+        return null;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java?view=diff&rev=504514&r1=504513&r2=504514
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
Wed Feb  7 03:57:44 2007
@@ -116,21 +116,25 @@
             }
 
             // load default callbacks
-            Iterator listeners = entityListenerCache.values().iterator();
-            while (listeners.hasNext()) {
-                EntityListener listener = (EntityListener) listeners.next();
+            Iterator maps = this.maps.iterator();
+            while (maps.hasNext()) {
+                DataMap map = (DataMap) maps.next();
+                Iterator listeners = map.getDefaultEntityListeners().iterator();
+                while (listeners.hasNext()) {
+                    EntityListener listener = (EntityListener) listeners.next();
 
-                Object listenerInstance = createListener(listener);
+                    Object listenerInstance = createListener(listener);
 
-                Iterator callbacks = listener.getCallbackMethods().iterator();
-                while (callbacks.hasNext()) {
-                    CallbackMethod method = (CallbackMethod) callbacks.next();
-                    Iterator callbackEvents = method.getCallbackEvents().iterator();
-                    while (callbackEvents.hasNext()) {
-                        Integer event = (Integer) callbackEvents.next();
-                        lifecycleEventCallbacks[event.intValue()].addDefaultListener(
-                                listenerInstance,
-                                method.getName());
+                    Iterator callbacks = listener.getCallbackMethods().iterator();
+                    while (callbacks.hasNext()) {
+                        CallbackMethod method = (CallbackMethod) callbacks.next();
+                        Iterator callbackEvents = method.getCallbackEvents().iterator();
+                        while (callbackEvents.hasNext()) {
+                            Integer event = (Integer) callbackEvents.next();
+                            lifecycleEventCallbacks[event.intValue()].addDefaultListener(
+                                    listenerInstance,
+                                    method.getName());
+                        }
                     }
                 }
             }
@@ -142,7 +146,7 @@
                 Class entityClass = entity.getJavaClass();
 
                 // external listeners go first, entity's own callbacks go next
-                Iterator entityListeners = entity.getListeners().iterator();
+                Iterator entityListeners = entity.getEntityListeners().iterator();
                 while (entityListeners.hasNext()) {
                     EntityListener listener = (EntityListener) entityListeners.next();
 
@@ -495,7 +499,11 @@
             }
 
             // index listeners
-            entityListenerCache.putAll(map.getEntityListenersMap());
+            Iterator listeners = map.getEntityListeners().iterator();
+            while (listeners.hasNext()) {
+                EntityListener listener = (EntityListener) listeners.next();
+                entityListenerCache.put(listener.getClassName(), listener);
+            }
         }
 
         // restart the map iterator to index inheritance

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?view=diff&rev=504514&r1=504513&r2=504514
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Wed Feb  7 03:57:44 2007
@@ -81,7 +81,7 @@
     protected String clientClassName;
     protected String clientSuperClassName;
 
-    protected List listeners;
+    protected List entityListeners;
     protected SortedMap callbackMethods;
     protected boolean excludingDefaultListeners;
     protected boolean excludingSuperclassListeners;
@@ -94,7 +94,7 @@
         setName(name);
         this.lockType = LOCK_TYPE_NONE;
         this.callbackMethods = new TreeMap();
-        this.listeners = new ArrayList(2);
+        this.entityListeners = new ArrayList(2);
     }
 
     /**
@@ -238,8 +238,8 @@
      * 
      * @since 3.0
      */
-    public List getListeners() {
-        return Collections.unmodifiableList(listeners);
+    public List getEntityListeners() {
+        return Collections.unmodifiableList(entityListeners);
     }
 
     /**
@@ -249,8 +249,8 @@
      * @throws IllegalArgumentException if a listener for the same class name is already
      *             registered.
      */
-    public void addListener(EntityListener listener) {
-        Iterator it = listeners.iterator();
+    public void addEntityListener(EntityListener listener) {
+        Iterator it = entityListeners.iterator();
         while (it.hasNext()) {
             EntityListener next = (EntityListener) it.next();
             if (listener.getClassName().equals(next.getClassName())) {
@@ -259,7 +259,7 @@
             }
         }
 
-        listeners.add(listener);
+        entityListeners.add(listener);
     }
 
     /**
@@ -267,8 +267,8 @@
      * 
      * @since 3.0
      */
-    public void removeListener(String className) {
-        Iterator it = listeners.iterator();
+    public void removeEntityListener(String className) {
+        Iterator it = entityListeners.iterator();
         while (it.hasNext()) {
             EntityListener next = (EntityListener) it.next();
             if (className.equals(next.getClassName())) {
@@ -276,6 +276,21 @@
                 break;
             }
         }
+    }
+    
+    /**
+     * @since 3.0
+     */
+    public EntityListener getEntityListener(String className) {
+        Iterator it = entityListeners.iterator();
+        while (it.hasNext()) {
+            EntityListener next = (EntityListener) it.next();
+            if (className.equals(next.getClassName())) {
+                return next;
+            }
+        }
+        
+        return null;
     }
 
     /**



Mime
View raw message