commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1452122 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/ main/java/org/apache/commons/configuration/web/ test/java/org/apache/commons/configuration/
Date Sun, 03 Mar 2013 21:17:22 GMT
Author: oheger
Date: Sun Mar  3 21:17:21 2013
New Revision: 1452122

URL: http://svn.apache.org/r1452122
Log:
[CONFIGURATION-527] Made AbstractConfiguration.clearPropertyDirect() abstract.
This caused some adaptations of other configuration classes.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/JNDIConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/web/BaseWebConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/NonCloneableConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -616,15 +616,11 @@ public abstract class AbstractConfigurat
     /**
      * Removes the specified property from this configuration. This method is
      * called by {@code clearProperty()} after it has done some
-     * preparations. It should be overridden in sub classes. This base
-     * implementation is just left empty.
+     * preparations. It must be overridden in sub classes.
      *
      * @param key the key to be removed
      */
-    protected void clearPropertyDirect(String key)
-    {
-        // override in sub classes
-    }
+    protected abstract void clearPropertyDirect(String key);
 
     public void clear()
     {

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -843,17 +843,14 @@ public class BaseHierarchicalConfigurati
      * @param key the key of the property to be removed
      */
     @Override
-    public void clearProperty(String key)
+    protected void clearPropertyDirect(String key)
     {
-        fireEvent(EVENT_CLEAR_PROPERTY, key, null, true);
         List<ConfigurationNode> nodes = fetchNodeList(key);
 
         for (ConfigurationNode node : nodes)
         {
             clearNode(node);
         }
-
-        fireEvent(EVENT_CLEAR_PROPERTY, key, null, false);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -164,6 +164,19 @@ public class DataConfiguration extends A
     }
 
     @Override
+    protected void clearPropertyDirect(String key)
+    {
+        if (configuration instanceof AbstractConfiguration)
+        {
+            ((AbstractConfiguration) configuration).clearPropertyDirect(key);
+        }
+        else
+        {
+            configuration.clearProperty(key);
+        }
+    }
+
+    @Override
     public void setProperty(String key, Object value)
     {
         configuration.setProperty(key, value);

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/JNDIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/JNDIConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/JNDIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/JNDIConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -332,7 +332,7 @@ public class JNDIConfiguration extends A
      * @param key the key of the property to remove
      */
     @Override
-    public void clearProperty(String key)
+    protected void clearPropertyDirect(String key)
     {
         clearedProperties.add(key);
     }

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/web/BaseWebConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/web/BaseWebConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/web/BaseWebConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/web/BaseWebConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -71,7 +71,7 @@ abstract class BaseWebConfiguration exte
      * allowed
      */
     @Override
-    public void clearProperty(String key)
+    protected void clearPropertyDirect(String key)
     {
         throw new UnsupportedOperationException("Read only configuration");
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/NonCloneableConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/NonCloneableConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/NonCloneableConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/NonCloneableConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -67,4 +67,9 @@ public class NonCloneableConfiguration e
     {
         return null;
     }
+
+    @Override
+    protected void clearPropertyDirect(String key)
+    {
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java?rev=1452122&r1=1452121&r2=1452122&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDataConfiguration.java
Sun Mar  3 21:17:21 2013
@@ -42,6 +42,7 @@ import java.util.NoSuchElementException;
 import junitx.framework.ArrayAssert;
 import junitx.framework.ListAssert;
 
+import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -2399,4 +2400,44 @@ public class TestDataConfiguration
         conf.addProperty(key, value);
         assertEquals("Wrong result", value, conf.get(String.class, key));
     }
+
+    /**
+     * Tests whether properties can be cleared.
+     */
+    @Test
+    public void testClearProperty()
+    {
+        String key = "test.property";
+        conf.addProperty(key, "someValue");
+        conf.clearProperty(key);
+        assertFalse("Property still found", conf.containsKey(key));
+    }
+
+    /**
+     * Tests the implementation of clearPropertyDirect().
+     */
+    @Test
+    public void testClearPropertyDirect()
+    {
+        String key = "test.property";
+        conf.addProperty(key, "someValue");
+        conf.clearPropertyDirect(key);
+        assertFalse("Property still found", conf.containsKey(key));
+    }
+
+    /**
+     * Tests clearPropertyDirect() if the wrapped configuration does not extend
+     * AbstractConfiguration.
+     */
+    @Test
+    public void testClearPropertyDirectNoAbstractConf()
+    {
+        Configuration wrapped = EasyMock.createMock(Configuration.class);
+        String key = "test.property";
+        wrapped.clearProperty(key);
+        EasyMock.replay(wrapped);
+        conf = new DataConfiguration(wrapped);
+        conf.clearPropertyDirect(key);
+        EasyMock.verify(wrapped);
+    }
 }



Mime
View raw message