You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/07/11 22:16:02 UTC

svn commit: r1609790 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ main/java/org/apache/commons/configuration/event/ test/java/org/apache/commons/configuration/builder/

Author: oheger
Date: Fri Jul 11 20:16:01 2014
New Revision: 1609790

URL: http://svn.apache.org/r1609790
Log:
Modified EventSource interface.

New methods for adding and removing event listeners were added based on the
event type. The existing methods were deperecated. This commit breaks the
build because not all adaptations have been made.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/BaseEventSource.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventSource.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderConfigurationWrapperFactory.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java?rev=1609790&r1=1609789&r2=1609790&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java Fri Jul 11 20:16:01 2014
@@ -28,7 +28,10 @@ import java.util.Iterator;
 import org.apache.commons.configuration.event.ConfigurationErrorEvent;
 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.EventSource;
+import org.apache.commons.configuration.event.EventType;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.sync.NoOpSynchronizer;
 import org.apache.commons.configuration.sync.Synchronizer;
@@ -99,6 +102,19 @@ public final class ConfigurationUtils
         {
             return false;
         }
+
+        @Override
+        public <T extends Event> void addEventListener(EventType<T> eventType,
+                EventListener<? super T> listener)
+        {
+        }
+
+        @Override
+        public <T extends Event> boolean removeEventListener(
+                EventType<T> eventType, EventListener<? super T> listener)
+        {
+            return false;
+        }
     };
 
     /** The logger.*/

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/BaseEventSource.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/BaseEventSource.java?rev=1609790&r1=1609789&r2=1609790&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/BaseEventSource.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/BaseEventSource.java Fri Jul 11 20:16:01 2014
@@ -171,6 +171,21 @@ public class BaseEventSource implements 
         return errorListeners.remove(l);
     }
 
+    @Override
+    public <T extends Event> void addEventListener(EventType<T> eventType,
+            EventListener<? super T> listener)
+    {
+        // TODO implementation
+    }
+
+    @Override
+    public <T extends Event> boolean removeEventListener(
+            EventType<T> eventType, EventListener<? super T> listener)
+    {
+        // TODO implementation
+        return false;
+    }
+
     /**
      * Removes all registered error listeners.
      *

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventSource.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventSource.java?rev=1609790&r1=1609789&r2=1609790&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventSource.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventSource.java Fri Jul 11 20:16:01 2014
@@ -36,7 +36,9 @@ public interface EventSource
      * Adds a configuration listener to this object.
      *
      * @param l the listener to add
+     * @deprecated Use {@code addEventListener()}
      */
+    @Deprecated
     void addConfigurationListener(ConfigurationListener l);
 
     /**
@@ -45,7 +47,9 @@ public interface EventSource
      *
      * @param l the listener to be removed
      * @return a flag whether the event listener was found
+     * @deprecated Use {@code removeEventListener()}
      */
+    @Deprecated
     boolean removeConfigurationListener(ConfigurationListener l);
 
     /**
@@ -54,7 +58,9 @@ public interface EventSource
      *
      * @param l the listener to register (must not be <b>null</b>)
      * @since 1.4
+     * @deprecated Use {@code addEventListener()}
      */
+    @Deprecated
     void addErrorListener(ConfigurationErrorListener l);
 
     /**
@@ -64,6 +70,35 @@ public interface EventSource
      * @param l the listener to remove
      * @return a flag whether the listener could be found and removed
      * @since 1.4
+     * @deprecated Use {@code removeEventListener()}
      */
+    @Deprecated
     boolean removeErrorListener(ConfigurationErrorListener l);
+
+    /**
+     * Adds an event listener for the specified event type. This listener is
+     * notified about events of this type and all its sub types.
+     *
+     * @param eventType the event type (must not be <b>null</b>)
+     * @param listener the listener to be registered (must not be <b>null</b>)
+     * @param <T> the type of events processed by this listener
+     * @throws IllegalArgumentException if a required parameter is <b>null</b>
+     */
+    <T extends Event> void addEventListener(EventType<T> eventType,
+            EventListener<? super T> listener);
+
+    /**
+     * Removes the event listener registration for the given event type and
+     * listener. An event listener instance may be registered multiple times for
+     * different event types. Therefore, when removing a listener the event type
+     * of the registration in question has to be specified. The return value
+     * indicates whether a registration was removed. A value of <b>false</b>
+     * means that no such combination of event type and listener was found.
+     *
+     * @param eventType the event type
+     * @param listener the event listener to be removed
+     * @return a flag whether a listener registration was removed
+     */
+    <T extends Event> boolean removeEventListener(EventType<T> eventType,
+            EventListener<? super T> listener);
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderConfigurationWrapperFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderConfigurationWrapperFactory.java?rev=1609790&r1=1609789&r2=1609790&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderConfigurationWrapperFactory.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderConfigurationWrapperFactory.java Fri Jul 11 20:16:01 2014
@@ -19,14 +19,12 @@ package org.apache.commons.configuration
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.apache.commons.configuration.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.builder.BuilderConfigurationWrapperFactory.EventSourceSupport;
-import org.apache.commons.configuration.event.ConfigurationListener;
 import org.apache.commons.configuration.event.EventSource;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
@@ -164,23 +162,24 @@ public class TestBuilderConfigurationWra
     @Test
     public void testEventSourceSupportBuilderOptionalSupported()
     {
-        BuilderWithEventSource builder =
-                EasyMock.createMock(BuilderWithEventSource.class);
-        ConfigurationListener l =
-                EasyMock.createMock(ConfigurationListener.class);
-        builder.addConfigurationListener(l);
-        EasyMock.expect(builder.removeConfigurationListener(l)).andReturn(
-                Boolean.TRUE);
-        EasyMock.replay(builder, l);
-        BuilderConfigurationWrapperFactory factory =
-                new BuilderConfigurationWrapperFactory(
-                        EventSourceSupport.BUILDER_OPTIONAL);
-        EventSource src =
-                (EventSource) factory.createBuilderConfigurationWrapper(
-                        Configuration.class, builder);
-        src.addConfigurationListener(l);
-        assertTrue("Wrong result", src.removeConfigurationListener(l));
-        EasyMock.verify(builder);
+        //TODO enable after code compiles again
+//        BuilderWithEventSource builder =
+//                EasyMock.createMock(BuilderWithEventSource.class);
+//        ConfigurationListener l =
+//                EasyMock.createMock(ConfigurationListener.class);
+//        builder.addConfigurationListener(l);
+//        EasyMock.expect(builder.removeConfigurationListener(l)).andReturn(
+//                Boolean.TRUE);
+//        EasyMock.replay(builder, l);
+//        BuilderConfigurationWrapperFactory factory =
+//                new BuilderConfigurationWrapperFactory(
+//                        EventSourceSupport.BUILDER_OPTIONAL);
+//        EventSource src =
+//                (EventSource) factory.createBuilderConfigurationWrapper(
+//                        Configuration.class, builder);
+//        src.addConfigurationListener(l);
+//        assertTrue("Wrong result", src.removeConfigurationListener(l));
+//        EasyMock.verify(builder);
     }
 
     /**
@@ -232,7 +231,7 @@ public class TestBuilderConfigurationWra
      * A combined interface needed for mock generation.
      */
     private static interface BuilderWithEventSource extends
-            ConfigurationBuilder<Configuration>, EventSource
+            ConfigurationBuilder<Configuration>/*, EventSource*/
     {
     }
 }