Author: oheger
Date: Sun Jul 13 20:04:19 2014
New Revision: 1610293

URL: http://svn.apache.org/r1610293
Log:
Adapted ConfigurationUtils.enableRuntimeExceptions().

An event listener of the new type is now registered to generated runtime
exceptions for errors occurring on property access.

Modified:
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/ConfigurationUtils.java
    
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestConfigurationUtils.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=1610293&r1=1610292&r2=1610293&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
 Sun Jul 13 20:04:19 2014
@@ -442,7 +442,7 @@ public final class ConfigurationUtils
      * on normal property access, e.g. {@code DatabaseConfiguration} or
      * {@code JNDIConfiguration}. Per default such errors are simply
      * logged and then ignored. This implementation will register a special
-     * {@link ConfigurationErrorListener} that throws a runtime
+     * {@link EventListener} that throws a runtime
      * exception (namely a {@code ConfigurationRuntimeException}) on
      * each received error event.
      *
@@ -456,15 +456,17 @@ public final class ConfigurationUtils
             throw new IllegalArgumentException(
                     "Configuration must implement EventSource!");
         }
-        ((EventSource) src).addErrorListener(new ConfigurationErrorListener()
-        {
-            @Override
-            public void configurationError(ConfigurationErrorEvent event)
-            {
-                // Throw a runtime exception
-                throw new ConfigurationRuntimeException(event.getCause());
-            }
-        });
+        ((EventSource) src).addEventListener(ConfigurationErrorEvent.ANY,
+                new EventListener<ConfigurationErrorEvent>()
+                {
+                    @Override
+                    public void onEvent(ConfigurationErrorEvent event)
+                    {
+                        // Throw a runtime exception
+                        throw new ConfigurationRuntimeException(event
+                                .getCause());
+                    }
+                });
     }
 
     /**

Modified: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestConfigurationUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestConfigurationUtils.java?rev=1610293&r1=1610292&r2=1610293&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestConfigurationUtils.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestConfigurationUtils.java
 Sun Jul 13 20:04:19 2014
@@ -33,6 +33,7 @@ import java.util.Map;
 import junitx.framework.ListAssert;
 import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
+import org.apache.commons.configuration.event.ConfigurationErrorEvent;
 import org.apache.commons.configuration.event.ConfigurationErrorListener;
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.EventListener;
@@ -389,8 +390,9 @@ public class TestConfigurationUtils
             protected void addPropertyDirect(String key, Object value)
             {
                 // always simulate an exception
-                fireError(EVENT_ADD_PROPERTY, key, value, new RuntimeException(
-                        "A faked exception!"));
+                fireError(ConfigurationErrorEvent.WRITE,
+                        ConfigurationEvent.ADD_PROPERTY, key, value,
+                        new RuntimeException("A faked exception!"));
             }
         };
         config.clearErrorListeners();


Reply via email to