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/22 22:00:03 UTC
svn commit: r1612666 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/
main/java/org/apache/commons/configuration/builder/combined/
test/java/org/apache/commons/configuration/builder/
Author: oheger
Date: Tue Jul 22 20:00:03 2014
New Revision: 1612666
URL: http://svn.apache.org/r1612666
Log:
ConfigurationBuilder now extends the EventSource interface.
This caused some adaptations in BasicConfigurationBuilder and derived classes.
BuilderConfigurationWrapperFactory had to be slightly modified again.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderConfigurationWrapperFactory.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ConfigurationBuilder.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilderProvider.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/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1612666&r1=1612665&r2=1612666&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 20:00:03 2014
@@ -343,14 +343,14 @@ public class BasicConfigurationBuilder<T
* <b>null</b>
*/
@Override
- public final <E extends ConfigurationBuilderEvent> void addEventListener(
+ public final <E extends Event> void addEventListener(
EventType<E> eventType, EventListener<? super E> listener)
{
eventListeners.addEventListener(eventType, listener);
}
@Override
- public final <E extends ConfigurationBuilderEvent> boolean removeEventListener(
+ public final <E extends Event> boolean removeEventListener(
EventType<E> eventType, EventListener<? super E> listener)
{
return eventListeners.removeEventListener(eventType, listener);
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderConfigurationWrapperFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderConfigurationWrapperFactory.java?rev=1612666&r1=1612665&r2=1612666&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderConfigurationWrapperFactory.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderConfigurationWrapperFactory.java Tue Jul 22 20:00:03 2014
@@ -215,14 +215,19 @@ public class BuilderConfigurationWrapper
* {@code removeConfigurationListener()}, to which the methods of the
* {@code EventSource} interface are mapped. This is the case for all
* builder implementations derived from
- * {@code BasicConfigurationBuilder}.
+ * {@code BasicConfigurationBuilder}. If these methods are not
+ * available, an exception is thrown.
*/
BUILDER,
/**
* {@code EventSource} support is implemented by delegating to the
- * associated {@code ConfigurationBuilder} object if it supports this
- * interface. Otherwise, a dummy implementation is used.
+ * associated {@code ConfigurationBuilder} object like for the type
+ * {@code BUILDER}. However, if the builder does not define the methods
+ * {@code addConfigurationListener()} and
+ * {@code removeConfigurationListener()}, the builder is used as event
+ * source itself (i.e. the methods {@code addEventListener()} or
+ * {@code removeEventListener()} are called.
*/
BUILDER_OPTIONAL
}
@@ -339,11 +344,11 @@ public class BuilderConfigurationWrapper
methodToInvoke = findBuilderMethod(method);
if (methodToInvoke == null)
{
- target =
- ConfigurationUtils
- .asEventSource(
- builder,
- EventSourceSupport.BUILDER_OPTIONAL == eventSourceSupport);
+ if (EventSourceSupport.BUILDER == eventSourceSupport)
+ {
+ throw new ConfigurationRuntimeException(
+ "Could not delegate event source operation to builder!");
+ }
methodToInvoke = method;
}
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ConfigurationBuilder.java?rev=1612666&r1=1612665&r2=1612666&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ConfigurationBuilder.java Tue Jul 22 20:00:03 2014
@@ -17,8 +17,7 @@
package org.apache.commons.configuration.builder;
import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.event.EventListener;
-import org.apache.commons.configuration.event.EventType;
+import org.apache.commons.configuration.event.EventSource;
import org.apache.commons.configuration.ex.ConfigurationException;
/**
@@ -38,7 +37,7 @@ import org.apache.commons.configuration.
* @param <T> the concrete type of the {@code Configuration} class produced by
* this builder
*/
-public interface ConfigurationBuilder<T extends Configuration>
+public interface ConfigurationBuilder<T extends Configuration> extends EventSource
{
/**
* Returns the configuration provided by this builder. An implementation has
@@ -49,23 +48,4 @@ public interface ConfigurationBuilder<T
* @throws ConfigurationException if an error occurs
*/
T getConfiguration() throws ConfigurationException;
-
- /**
- * Adds an event listener for the given event type to this builder.
- *
- * @param eventType the event type (must not be <b>null</b>)
- * @param listener the listener to be registered (must not be <b>null</b>)
- * @throws IllegalArgumentException if a required parameter is <b>null</b>
- */
- <E extends ConfigurationBuilderEvent> void addEventListener(
- EventType<E> eventType, EventListener<? super E> listener);
-
- /**
- * Removes the specified {@code EventListener} from this builder.
- *
- * @param eventType the event type
- * @param listener the listener to be removed
- */
- <E extends ConfigurationBuilderEvent> boolean removeEventListener(
- EventType<E> eventType, EventListener<? super E> listener);
}
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilderProvider.java?rev=1612666&r1=1612665&r2=1612666&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilderProvider.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilderProvider.java Tue Jul 22 20:00:03 2014
@@ -24,7 +24,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.builder.BuilderConfigurationWrapperFactory;
import org.apache.commons.configuration.builder.BuilderConfigurationWrapperFactory.EventSourceSupport;
import org.apache.commons.configuration.builder.ConfigurationBuilder;
-import org.apache.commons.configuration.builder.ConfigurationBuilderEvent;
+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;
@@ -183,14 +183,14 @@ public class MultiFileConfigurationBuild
}
@Override
- public <T extends ConfigurationBuilderEvent> void addEventListener(
+ public <T extends Event> void addEventListener(
EventType<T> eventType, EventListener<? super T> listener)
{
builder.addEventListener(eventType, listener);
}
@Override
- public <T extends ConfigurationBuilderEvent> boolean removeEventListener(
+ public <T extends Event> boolean removeEventListener(
EventType<T> eventType, EventListener<? super T> listener)
{
return builder.removeEventListener(eventType, 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=1612666&r1=1612665&r2=1612666&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 Tue Jul 22 20:00:03 2014
@@ -206,8 +206,10 @@ public class TestBuilderConfigurationWra
{
BaseHierarchicalConfiguration conf =
new BaseHierarchicalConfiguration();
+ EventListener<ConfigurationEvent> listener = new EventListenerTestImpl(null);
ConfigurationBuilder<BaseHierarchicalConfiguration> builder =
createBuilderMock(conf);
+ builder.addEventListener(ConfigurationEvent.ANY, listener);
EasyMock.replay(builder);
BuilderConfigurationWrapperFactory factory =
new BuilderConfigurationWrapperFactory(
@@ -215,7 +217,9 @@ public class TestBuilderConfigurationWra
EventSource src =
(EventSource) factory.createBuilderConfigurationWrapper(
HierarchicalConfiguration.class, builder);
- src.addEventListener(ConfigurationEvent.ANY, null);
+
+ src.addEventListener(ConfigurationEvent.ANY, listener);
+ EasyMock.verify(builder);
}
/**