commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1612664 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Date Tue, 22 Jul 2014 19:58:28 GMT
Author: oheger
Date: Tue Jul 22 19:58:27 2014
New Revision: 1612664

URL: http://svn.apache.org/r1612664
Log:
BasicConfigurationBuilder now support the EventListenerProvider interface.

If a parameters object passed to the configure() method implements this
interface, the listeners it contains are added to the configuration builder.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1612664&r1=1612663&r2=1612664&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
Tue Jul 22 19:58:27 2014
@@ -262,6 +262,7 @@ public class BasicConfigurationBuilder<T
         for (BuilderParameters p : params)
         {
             newParams.putAll(p.getParameters());
+            handleEventListenerProviders(p);
         }
 
         return setParameters(newParams);
@@ -663,6 +664,22 @@ public class BasicConfigurationBuilder<T
     }
 
     /**
+     * Checks whether the specified parameters object implements the
+     * {@code EventListenerProvider} interface. If so, the event listeners it
+     * provides are added to this builder.
+     *
+     * @param params the parameters object
+     */
+    private void handleEventListenerProviders(BuilderParameters params)
+    {
+        if (params instanceof EventListenerProvider)
+        {
+            configListeners.addAll(((EventListenerProvider) params)
+                    .getListeners());
+        }
+    }
+
+    /**
      * Checks whether the class of the result configuration is compatible with
      * this builder's result class. This is done to ensure that only objects of
      * the expected result class are created.

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java?rev=1612664&r1=1612663&r2=1612664&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Tue Jul 22 19:58:27 2014
@@ -48,6 +48,8 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ErrorListenerTestImpl;
 import org.apache.commons.configuration.event.EventListener;
+import org.apache.commons.configuration.event.EventListenerRegistrationData;
+import org.apache.commons.configuration.event.EventListenerTestImpl;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.reloading.ReloadingController;
@@ -434,6 +436,33 @@ public class TestBasicConfigurationBuild
     }
 
     /**
+     * Tests whether configuration listeners can be defined via the configure()
+     * method.
+     */
+    @Test
+    public void testEventListenerConfiguration() throws ConfigurationException
+    {
+        EventListenerTestImpl listener1 = new EventListenerTestImpl(null);
+        EventListenerRegistrationData<ConfigurationErrorEvent> regData =
+                new EventListenerRegistrationData<ConfigurationErrorEvent>(
+                        ConfigurationErrorEvent.WRITE,
+                        new ErrorListenerTestImpl(null));
+        BasicConfigurationBuilder<PropertiesConfiguration> builder =
+                new BasicConfigurationBuilder<PropertiesConfiguration>(
+                        PropertiesConfiguration.class)
+                        .configure(new EventListenerParameters()
+                                .addEventListener(ConfigurationEvent.ANY,
+                                        listener1).addEventListener(regData));
+        PropertiesConfiguration config = builder.getConfiguration();
+        assertTrue("Configuration listener not found", config
+                .getEventListeners(ConfigurationEvent.ANY).contains(listener1));
+        assertTrue(
+                "Error listener not found",
+                config.getEventListeners(regData.getEventType()).contains(
+                        regData.getListener()));
+    }
+
+    /**
      * Tests whether parameters starting with a reserved prefix are filtered out
      * before result objects are initialized.
      */



Mime
View raw message