commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1609809 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/
Date Fri, 11 Jul 2014 20:27:41 GMT
Author: oheger
Date: Fri Jul 11 20:27:41 2014
New Revision: 1609809

URL: http://svn.apache.org/r1609809
Log:
Reworked handling of event listeners in MultiFileConfigurationBuilder.

The methods for registering event listeners of the new type are now overridden.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java?rev=1609809&r1=1609808&r2=1609809&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
Fri Jul 11 20:27:41 2014
@@ -29,9 +29,9 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilderEvent;
 import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
-import org.apache.commons.configuration.event.ConfigurationErrorListener;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.Event;
 import org.apache.commons.configuration.event.EventListener;
+import org.apache.commons.configuration.event.EventType;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.interpol.InterpolatorSpecification;
@@ -230,13 +230,13 @@ public class MultiFileConfigurationBuild
      * at managed configuration builders.
      */
     @Override
-    public synchronized BasicConfigurationBuilder<T> addConfigurationListener(
-            ConfigurationListener l)
+    public synchronized <E extends Event> BasicConfigurationBuilder<T> addConfigurationListener(
+            EventType<E> eventType, EventListener<? super E> l)
     {
-        super.addConfigurationListener(l);
+        super.addConfigurationListener(eventType, l);
         for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
         {
-            b.addConfigurationListener(l);
+            b.addConfigurationListener(eventType, l);
         }
         return this;
     }
@@ -246,45 +246,13 @@ public class MultiFileConfigurationBuild
      * removed from managed configuration builders.
      */
     @Override
-    public synchronized BasicConfigurationBuilder<T> removeConfigurationListener(
-            ConfigurationListener l)
+    public synchronized <E extends Event> BasicConfigurationBuilder<T> removeConfigurationListener(
+            EventType<E> eventType, EventListener<? super E> l)
     {
-        super.removeConfigurationListener(l);
+        super.removeConfigurationListener(eventType, l);
         for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
         {
-            b.removeConfigurationListener(l);
-        }
-        return this;
-    }
-
-    /**
-     * {@inheritDoc} This implementation ensures that the listener is also added
-     * at managed configuration builders.
-     */
-    @Override
-    public synchronized BasicConfigurationBuilder<T> addErrorListener(
-            ConfigurationErrorListener l)
-    {
-        super.addErrorListener(l);
-        for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
-        {
-            b.addErrorListener(l);
-        }
-        return this;
-    }
-
-    /**
-     * {@inheritDoc} This implementation ensures that the listener is also
-     * removed from managed configuration builders.
-     */
-    @Override
-    public synchronized BasicConfigurationBuilder<T> removeErrorListener(
-            ConfigurationErrorListener l)
-    {
-        super.removeErrorListener(l);
-        for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
-        {
-            b.removeErrorListener(l);
+            b.removeConfigurationListener(eventType, l);
         }
         return this;
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java?rev=1609809&r1=1609808&r2=1609809&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
Fri Jul 11 20:27:41 2014
@@ -40,8 +40,9 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
 import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
-import org.apache.commons.configuration.event.ConfigurationErrorListener;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.event.ConfigurationEvent;
+import org.apache.commons.configuration.event.Event;
+import org.apache.commons.configuration.event.EventListener;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.interpol.DefaultLookups;
@@ -255,59 +256,31 @@ public class TestMultiFileConfigurationB
     @Test
     public void testAddConfigurationListener() throws ConfigurationException
     {
-        ConfigurationListener l1 =
-                EasyMock.createMock(ConfigurationListener.class);
-        ConfigurationListener l2 =
-                EasyMock.createMock(ConfigurationListener.class);
+        @SuppressWarnings("unchecked")
+        EventListener<ConfigurationEvent> l1 =
+                EasyMock.createMock(EventListener.class);
+        @SuppressWarnings("unchecked")
+        EventListener<Event> l2 =
+                EasyMock.createMock(EventListener.class);
         EasyMock.replay(l1, l2);
         MultiFileConfigurationBuilder<XMLConfiguration> builder =
                 createTestBuilder(null);
         assertSame("Wrong result", builder,
-                builder.addConfigurationListener(l1));
+                builder.addConfigurationListener(ConfigurationEvent.ANY, l1));
         switchToConfig(1);
         XMLConfiguration config = builder.getConfiguration();
-        assertTrue("Listener not added", config.getConfigurationListeners()
+        assertTrue("Listener not added", config.getEventListeners(ConfigurationEvent.ANY)
                 .contains(l1));
-        builder.addConfigurationListener(l2);
-        assertTrue("Listener 2 not added", config.getConfigurationListeners()
+        builder.addConfigurationListener(Event.ANY, l2);
+        assertTrue("Listener 2 not added", config.getEventListeners(Event.ANY)
                 .contains(l2));
-        builder.removeConfigurationListener(l2);
-        assertFalse("Listener not removed", config.getConfigurationListeners()
+        builder.removeConfigurationListener(Event.ANY, l2);
+        assertFalse("Listener not removed", config.getEventListeners(Event.ANY)
                 .contains(l2));
         switchToConfig(2);
         XMLConfiguration config2 = builder.getConfiguration();
         assertFalse("Listener not globally removed", config2
-                .getConfigurationListeners().contains(l2));
-    }
-
-    /**
-     * Tests whether error listeners are handled correctly.
-     */
-    @Test
-    public void testAddErrorListener() throws ConfigurationException
-    {
-        ConfigurationErrorListener l1 =
-                EasyMock.createMock(ConfigurationErrorListener.class);
-        ConfigurationErrorListener l2 =
-                EasyMock.createMock(ConfigurationErrorListener.class);
-        EasyMock.replay(l1, l2);
-        MultiFileConfigurationBuilder<XMLConfiguration> builder =
-                createTestBuilder(null);
-        assertSame("Wrong result", builder, builder.addErrorListener(l1));
-        switchToConfig(1);
-        XMLConfiguration config = builder.getConfiguration();
-        assertTrue("Listener not added", config.getErrorListeners()
-                .contains(l1));
-        builder.addErrorListener(l2);
-        assertTrue("Listener 2 not added",
-                config.getErrorListeners().contains(l2));
-        builder.removeErrorListener(l2);
-        assertFalse("Listener not removed", config.getErrorListeners()
-                .contains(l2));
-        switchToConfig(2);
-        XMLConfiguration config2 = builder.getConfiguration();
-        assertFalse("Listener not globally removed", config2
-                .getErrorListeners().contains(l2));
+                .getEventListeners(Event.ANY).contains(l2));
     }
 
     /**



Mime
View raw message