commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1609801 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/CombinedConfiguration.java test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
Date Fri, 11 Jul 2014 20:23:02 GMT
Author: oheger
Date: Fri Jul 11 20:23:02 2014
New Revision: 1609801

URL: http://svn.apache.org/r1609801
Log:
Reworked CombinedConfiguration regarding event handling.

The new methods for registering event handlers and firing events are now used.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java?rev=1609801&r1=1609800&r2=1609801&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/CombinedConfiguration.java
Fri Jul 11 20:23:02 2014
@@ -28,8 +28,9 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.EventListener;
 import org.apache.commons.configuration.event.EventSource;
+import org.apache.commons.configuration.event.EventType;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.sync.LockMode;
 import org.apache.commons.configuration.tree.DefaultConfigurationKey;
@@ -181,13 +182,17 @@ import org.apache.commons.configuration.
  * @version $Id$
  */
 public class CombinedConfiguration extends BaseHierarchicalConfiguration implements
-        ConfigurationListener, Cloneable
+        EventListener<ConfigurationEvent>, Cloneable
 {
     /**
-     * Constant for the invalidate event that is fired when the internal node
-     * structure becomes invalid.
+     * Constant for the event type fired when the internal node structure of a
+     * combined configuration becomes invalid.
+     *
+     * @since 2.0
      */
-    public static final int EVENT_COMBINED_INVALIDATE = 40;
+    public static final EventType<ConfigurationEvent> COMBINED_INVALIDATE =
+            new EventType<ConfigurationEvent>(ConfigurationEvent.ANY,
+                    "COMBINED_INVALIDATE");
 
     /**
      * The serial version ID.
@@ -641,7 +646,7 @@ public class CombinedConfiguration exten
      * @param event the update event
      */
     @Override
-    public void configurationChanged(ConfigurationEvent event)
+    public void onEvent(ConfigurationEvent event)
     {
         if (event.isBeforeUpdate())
         {
@@ -868,7 +873,7 @@ public class CombinedConfiguration exten
     private void invalidateInternal()
     {
         upToDate = false;
-        fireEvent(EVENT_COMBINED_INVALIDATE, null, null, false);
+        fireEvent(COMBINED_INVALIDATE, null, null, false);
     }
 
     /**
@@ -954,7 +959,8 @@ public class CombinedConfiguration exten
     {
         if (configuration instanceof EventSource)
         {
-            ((EventSource) configuration).addConfigurationListener(this);
+            ((EventSource) configuration).addEventListener(
+                    ConfigurationEvent.ANY, this);
         }
     }
 
@@ -968,7 +974,8 @@ public class CombinedConfiguration exten
     {
         if (configuration instanceof EventSource)
         {
-            ((EventSource) configuration).removeConfigurationListener(this);
+            ((EventSource) configuration).removeEventListener(
+                    ConfigurationEvent.ANY, this);
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java?rev=1609801&r1=1609800&r2=1609801&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestCombinedConfiguration.java
Fri Jul 11 20:23:02 2014
@@ -39,7 +39,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.commons.configuration.SynchronizerTestImpl.Methods;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.EventListener;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.io.FileHandler;
@@ -98,7 +98,7 @@ public class TestCombinedConfiguration
     {
         config = new CombinedConfiguration();
         listener = new CombinedListener();
-        config.addConfigurationListener(listener);
+        config.addEventListener(ConfigurationEvent.ANY, listener);
     }
 
     /**
@@ -200,7 +200,8 @@ public class TestCombinedConfiguration
      */
     private void checkAddConfig(AbstractConfiguration c)
     {
-        Collection<ConfigurationListener> listeners = c.getConfigurationListeners();
+        Collection<EventListener<? super ConfigurationEvent>> listeners =
+                c.getEventListeners(ConfigurationEvent.ANY);
         assertEquals("Wrong number of configuration listeners", 1, listeners
                 .size());
         assertTrue("Combined config is no listener", listeners.contains(config));
@@ -334,8 +335,8 @@ public class TestCombinedConfiguration
      */
     private void checkRemoveConfig(AbstractConfiguration c)
     {
-        assertTrue("Listener was not removed", c.getConfigurationListeners()
-                .isEmpty());
+        assertTrue("Listener was not removed",
+                c.getEventListeners(ConfigurationEvent.ANY).isEmpty());
         assertEquals("Wrong number of contained configs", 0, config
                 .getNumberOfConfigurations());
         assertTrue("Name was not removed", config.getConfigurationNames()
@@ -398,8 +399,11 @@ public class TestCombinedConfiguration
                 .getNodeCombiner());
         assertEquals("Wrong number of names", config.getConfigurationNames()
                 .size(), cc2.getConfigurationNames().size());
-        assertTrue("Found duplicate event listeners", Collections.disjoint(cc2
-                .getConfigurationListeners(), config.getConfigurationListeners()));
+        assertTrue(
+                "Found duplicate event listeners",
+                Collections.disjoint(
+                        cc2.getEventListeners(ConfigurationEvent.ANY),
+                        config.getEventListeners(ConfigurationEvent.ANY)));
 
         StrictConfigurationComparator comp = new StrictConfigurationComparator();
         for (int i = 0; i < config.getNumberOfConfigurations(); i++)
@@ -462,7 +466,8 @@ public class TestCombinedConfiguration
         config.addConfiguration(child);
 
         config.clear();
-        for (ConfigurationListener listener : child.getConfigurationListeners())
+        for (EventListener<?> listener : child
+                .getEventListeners(ConfigurationEvent.ANY))
         {
             assertNotEquals("Still registered", config, listener);
         }
@@ -630,11 +635,11 @@ public class TestCombinedConfiguration
     public void testInvalidateEventBeforeAndAfterChange()
     {
         ConfigurationEvent event =
-                new ConfigurationEvent(config, 0, null, null, true);
-        config.configurationChanged(event);
+                new ConfigurationEvent(config, ConfigurationEvent.ANY, null, null, true);
+        config.onEvent(event);
         assertEquals("No invalidate event fired", 1, listener.invalidateEvents);
-        event = new ConfigurationEvent(config, 0, null, null, false);
-        config.configurationChanged(event);
+        event = new ConfigurationEvent(config, ConfigurationEvent.ANY, null, null, false);
+        config.onEvent(event);
         assertEquals("Another invalidate event fired", 1,
                 listener.invalidateEvents);
     }
@@ -1114,16 +1119,16 @@ public class TestCombinedConfiguration
      * Test event listener class for checking if the expected invalidate events
      * are fired.
      */
-    private static class CombinedListener implements ConfigurationListener
+    private static class CombinedListener implements EventListener<ConfigurationEvent>
     {
         int invalidateEvents;
 
         int otherEvents;
 
         @Override
-        public void configurationChanged(ConfigurationEvent event)
+        public void onEvent(ConfigurationEvent event)
         {
-            if (event.getType() == CombinedConfiguration.EVENT_COMBINED_INVALIDATE)
+            if (event.getEventType() == CombinedConfiguration.COMBINED_INVALIDATE)
             {
                 invalidateEvents++;
             }



Mime
View raw message