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 2013/08/24 21:52:23 UTC

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

Author: oheger
Date: Sat Aug 24 19:52:22 2013
New Revision: 1517190

URL: http://svn.apache.org/r1517190
Log:
Removed obsolete resolveContainerStore() method.

This method is now replaced by the functionality of the ConversionHandler to
deal with complex objects like collections or arrays. It lies in the
responsibility of this handler to extract the value to be converted to a
single object.

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/DynamicCombinedConfiguration.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseConfiguration.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=1517190&r1=1517189&r2=1517190&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 Sat Aug 24 19:52:22 2013
@@ -17,7 +17,6 @@
 
 package org.apache.commons.configuration;
 
-import java.lang.reflect.Array;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -1436,33 +1435,6 @@ public abstract class AbstractConfigurat
     }
 
     /**
-     * Returns an object from the store described by the key. If the value is a
-     * Collection object, replace it with the first object in the collection.
-     *
-     * @param key The property key.
-     *
-     * @return value Value, transparently resolving a possible collection dependency.
-     */
-    protected Object resolveContainerStore(String key)
-    {
-        Object value = getProperty(key);
-        if (value != null)
-        {
-            if (value instanceof Collection)
-            {
-                Collection<?> collection = (Collection<?>) value;
-                value = collection.isEmpty() ? null : collection.iterator().next();
-            }
-            else if (value.getClass().isArray() && Array.getLength(value) > 0)
-            {
-                value = Array.get(value, 0);
-            }
-        }
-
-        return value;
-    }
-
-    /**
      * Checks whether the specified object is a scalar value. This method is
      * called by {@code getList()} and {@code getStringArray()} if the
      * property requested is not a string, a list, or an array. If it returns

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java?rev=1517190&r1=1517189&r2=1517190&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DynamicCombinedConfiguration.java Sat Aug 24 19:52:22 2013
@@ -68,18 +68,6 @@ import org.apache.commons.logging.LogFac
 public class DynamicCombinedConfiguration extends CombinedConfiguration
 {
     /**
-     * Prevent recursion while resolving unprefixed properties.
-     */
-    private static ThreadLocal<Boolean> recursive = new ThreadLocal<Boolean>()
-    {
-        @Override
-        protected synchronized Boolean initialValue()
-        {
-            return Boolean.FALSE;
-        }
-    };
-
-    /**
      * Stores the current configuration for each involved thread. This value is
      * set at the beginning of an operation and removed at the end.
      */
@@ -860,29 +848,6 @@ public class DynamicCombinedConfiguratio
         }
     }
 
-    /*
-     * Don't allow resolveContainerStore to be called recursively.
-     * @param key The key to resolve.
-     * @return The value of the key.
-     */
-    @Override
-    protected Object resolveContainerStore(String key)
-    {
-        if (recursive.get().booleanValue())
-        {
-            return null;
-        }
-        recursive.set(Boolean.TRUE);
-        try
-        {
-            return super.resolveContainerStore(key);
-        }
-        finally
-        {
-            recursive.set(Boolean.FALSE);
-        }
-    }
-
     /**
      * {@inheritDoc} This implementation ensures that the current configuration
      * is initialized. The lock counter is increased.

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java?rev=1517190&r1=1517189&r2=1517190&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/PatternSubtreeConfigurationWrapper.java Sat Aug 24 19:52:22 2013
@@ -46,18 +46,6 @@ import org.apache.commons.configuration.
 public class PatternSubtreeConfigurationWrapper extends BaseHierarchicalConfiguration
     implements FileBasedConfiguration
 {
-    /**
-     * Prevent recursion while resolving unprefixed properties.
-     */
-    private static ThreadLocal<Boolean> recursive = new ThreadLocal<Boolean>()
-    {
-        @Override
-        protected synchronized Boolean initialValue()
-        {
-            return Boolean.FALSE;
-        }
-    };
-
     /** The wrapped configuration */
     private final HierarchicalConfiguration config;
 
@@ -468,24 +456,6 @@ public class PatternSubtreeConfiguration
         return getConfig().getErrorListeners();
     }
 
-    @Override
-    protected Object resolveContainerStore(String key)
-    {
-        if (recursive.get().booleanValue())
-        {
-            return null;
-        }
-        recursive.set(Boolean.TRUE);
-        try
-        {
-            return super.resolveContainerStore(key);
-        }
-        finally
-        {
-            recursive.set(Boolean.FALSE);
-        }
-    }
-
     private BaseHierarchicalConfiguration getConfig()
     {
         return config.configurationAt(makePath());

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseConfiguration.java?rev=1517190&r1=1517189&r2=1517190&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestBaseConfiguration.java Sat Aug 24 19:52:22 2013
@@ -29,12 +29,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Properties;
-import java.util.Set;
 import java.util.StringTokenizer;
 
 import junitx.framework.ListAssert;
@@ -667,55 +665,6 @@ public class TestBaseConfiguration
         assertEquals("long value", 0xFFFFFFFFFFFFFFFFL, config.getBigInteger("number").longValue());
     }
 
-    @Test
-    public void testResolveContainerStore()
-    {
-        AbstractConfiguration config = new BaseConfiguration();
-
-        // array of objects
-        config.addPropertyDirect("array", new String[] { "foo", "bar" });
-
-        assertEquals("first element of the 'array' property", "foo", config.resolveContainerStore("array"));
-
-        // list of objects
-        List<Object> list = new ArrayList<Object>();
-        list.add("foo");
-        list.add("bar");
-        config.addPropertyDirect("list", list);
-
-        assertEquals("first element of the 'list' property", "foo", config.resolveContainerStore("list"));
-
-        // set of objects
-        Set<Object> set = new LinkedHashSet<Object>();
-        set.add("foo");
-        set.add("bar");
-        config.addPropertyDirect("set", set);
-
-        assertEquals("first element of the 'set' property", "foo", config.resolveContainerStore("set"));
-
-        // arrays of primitives
-        config.addPropertyDirect("array.boolean", new boolean[] { true, false });
-        assertEquals("first element of the 'array.boolean' property", true, config.getBoolean("array.boolean"));
-
-        config.addPropertyDirect("array.byte", new byte[] { 1, 2 });
-        assertEquals("first element of the 'array.byte' property", 1, config.getByte("array.byte"));
-
-        config.addPropertyDirect("array.short", new short[] { 1, 2 });
-        assertEquals("first element of the 'array.short' property", 1, config.getShort("array.short"));
-
-        config.addPropertyDirect("array.int", new int[] { 1, 2 });
-        assertEquals("first element of the 'array.int' property", 1, config.getInt("array.int"));
-
-        config.addPropertyDirect("array.long", new long[] { 1, 2 });
-        assertEquals("first element of the 'array.long' property", 1, config.getLong("array.long"));
-
-        config.addPropertyDirect("array.float", new float[] { 1, 2 });
-        assertEquals("first element of the 'array.float' property", 1, config.getFloat("array.float"), 0);
-
-        config.addPropertyDirect("array.double", new double[] { 1, 2 });
-        assertEquals("first element of the 'array.double' property", 1, config.getDouble("array.double"), 0);
-    }
-
     /**
      * Tests if conversion between number types is possible.
      */