commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r419689 - in /jakarta/commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/ java/org/apache/commons/configuration/event/ test/org/apache/commons/configuration/
Date Thu, 06 Jul 2006 20:26:51 GMT
Author: oheger
Date: Thu Jul  6 13:26:51 2006
New Revision: 419689

URL: http://svn.apache.org/viewvc?rev=419689&view=rev
Log:
Dealing with event listeners when cloning configurations

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/event/EventSource.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java?rev=419689&r1=419688&r2=419689&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
Thu Jul  6 13:26:51 2006
@@ -166,7 +166,8 @@
         try
         {
             BaseConfiguration copy = (BaseConfiguration) super.clone();
-            copy.store = (Map) ((LinkedMap) store).clone();
+            copy.store = (Map) ConfigurationUtils.clone(store);
+            copy.clearConfigurationListeners();
             return copy;
         }
         catch (CloneNotSupportedException cex)

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=419689&r1=419688&r2=419689&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
Thu Jul  6 13:26:51 2006
@@ -648,7 +648,8 @@
 
     /**
      * Creates a copy of this object. This new configuration object will contain
-     * copies of all nodes in the same structure.
+     * copies of all nodes in the same structure. Registered event listeners
+     * won't be cloned; so they are not registered at the returned copy.
      *
      * @return the copy
      * @since 1.2
@@ -664,6 +665,7 @@
             CloneVisitor v = new CloneVisitor();
             getRootNode().visit(v);
             copy.setRootNode(v.getClone());
+            copy.clearConfigurationListeners();
 
             return copy;
         }

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/event/EventSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/event/EventSource.java?rev=419689&r1=419688&r2=419689&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/event/EventSource.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/event/EventSource.java
Thu Jul  6 13:26:51 2006
@@ -69,7 +69,7 @@
      */
     public EventSource()
     {
-        listeners = new LinkedList();
+        clearConfigurationListeners();
     }
 
     /**
@@ -118,6 +118,14 @@
         {
             return Collections.unmodifiableCollection(listeners);
         }
+    }
+
+    /**
+     * Removes all registered configuration listeners.
+     */
+    public void clearConfigurationListeners()
+    {
+        listeners = new LinkedList();
     }
 
     /**

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java?rev=419689&r1=419688&r2=419689&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
Thu Jul  6 13:26:51 2006
@@ -26,6 +26,9 @@
 import java.util.Properties;
 import java.util.StringTokenizer;
 
+import org.apache.commons.configuration.event.ConfigurationEvent;
+import org.apache.commons.configuration.event.ConfigurationListener;
+
 import junit.framework.TestCase;
 import junitx.framework.ListAssert;
 import junitx.framework.ObjectAssert;
@@ -762,6 +765,14 @@
      */
     public void testCloneModify()
     {
+        ConfigurationListener l = new ConfigurationListener()
+        {
+            public void configurationChanged(ConfigurationEvent event)
+            {
+                // just a dummy
+            }
+        };
+        config.addConfigurationListener(l);
         config.addProperty("original", Boolean.TRUE);
         BaseConfiguration config2 = (BaseConfiguration) config.clone();
 
@@ -770,5 +781,8 @@
         config2.setProperty("original", Boolean.FALSE);
         assertTrue("Wrong value of original property", config
                 .getBoolean("original"));
+
+        assertEquals("Event listener was copied", 0, config2
+                .getConfigurationListeners().size());
     }
 }

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=419689&r1=419688&r2=419689&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Thu Jul  6 13:26:51 2006
@@ -25,6 +25,8 @@
 
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.configuration.HierarchicalConfiguration.Node;
+import org.apache.commons.configuration.event.ConfigurationEvent;
+import org.apache.commons.configuration.event.ConfigurationListener;
 import org.apache.commons.configuration.tree.DefaultConfigurationNode;
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.ExpressionEngine;
@@ -485,6 +487,25 @@
                 assertEquals(fields[i][j], copy.getString("tables.table(" + i + ").fields.field("
+ j + ").name"));
             }
         }
+    }
+
+    /**
+     * Tests whether registered event handlers are handled correctly when a
+     * configuration is cloned. They should not be registered at the clone.
+     */
+    public void testCloneWithEventListeners()
+    {
+        config.addConfigurationListener(new ConfigurationListener()
+        {
+            public void configurationChanged(ConfigurationEvent event)
+            {
+                // just a dummy
+            }
+        });
+        HierarchicalConfiguration copy = (HierarchicalConfiguration) config
+                .clone();
+        assertTrue("Event listener registered at clone", copy
+                .getConfigurationListeners().isEmpty());
     }
 
     public void testAddNodes()



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message