Author: oheger
Date: Fri Dec 28 20:25:44 2012
New Revision: 1426620

URL: http://svn.apache.org/viewvc?rev=1426620&view=rev
Log:
BasicBuilderParameters now support a property for the parent 
ConfigurationInterpolator.

Modified:
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java
    
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java
    
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java

Modified: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java?rev=1426620&r1=1426619&r2=1426620&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java
 (original)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java
 Fri Dec 28 20:25:44 2012
@@ -71,6 +71,9 @@ public class BasicBuilderParameters impl
     /** The key for the <em>defaultLookups</em> property. */
     private static final String PROP_DEFAULT_LOOKUPS = "defaultLookups";
 
+    /** The key for the <em>parentInterpolator</em> property. */
+    private static final String PROP_PARENT_INTERPOLATOR = 
"parentInterpolator";
+
     /** The map for storing the current property values. */
     private final Map<String, Object> properties;
 
@@ -96,6 +99,7 @@ public class BasicBuilderParameters impl
             // A custom ConfigurationInterpolator overrides lookups
             result.remove(PROP_PREFIX_LOOKUPS);
             result.remove(PROP_DEFAULT_LOOKUPS);
+            result.remove(PROP_PARENT_INTERPOLATOR);
         }
         return result;
     }
@@ -208,6 +212,16 @@ public class BasicBuilderParameters impl
     }
 
     /**
+     * {@inheritDoc} This implementation stores the passed in
+     * {@code ConfigurationInterpolator} object in the internal parameters map.
+     */
+    public BasicBuilderParameters setParentInterpolator(
+            ConfigurationInterpolator parent)
+    {
+        return setProperty(PROP_PARENT_INTERPOLATOR, parent);
+    }
+
+    /**
      * Merges this object with the given parameters object. This method adds 
all
      * property values defined by the passed in parameters object to the
      * internal storage which are not already in. So properties already defined
@@ -238,15 +252,23 @@ public class BasicBuilderParameters impl
 
     /**
      * Sets a property for this parameters object. Properties are stored in an
-     * internal map. With this method a new entry can be added to this map. It
-     * can be used by sub classes which also store properties in a map.
+     * internal map. With this method a new entry can be added to this map. If
+     * the value is <b>null</b>, the key is removed from the internal map. This
+     * method can be used by sub classes which also store properties in a map.
      *
      * @param key the key of the property
      * @param value the value of the property
      */
     protected void storeProperty(String key, Object value)
     {
-        properties.put(key, value);
+        if (value == null)
+        {
+            properties.remove(key);
+        }
+        else
+        {
+            properties.put(key, value);
+        }
     }
 
     /**

Modified: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java?rev=1426620&r1=1426619&r2=1426620&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java
 (original)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java
 Fri Dec 28 20:25:44 2012
@@ -128,4 +128,16 @@ public interface BasicBuilderProperties<
      * @see ConfigurationInterpolator#addDefaultLookups(Collection)
      */
     T setDefaultLookups(Collection<? extends Lookup> lookups);
+
+    /**
+     * Sets the parent {@code ConfigurationInterpolator} for this
+     * configuration's {@code ConfigurationInterpolator}. Setting a parent
+     * {@code ConfigurationInterpolator} can be used for defining a default
+     * behavior for variables which cannot be resolved.
+     *
+     * @param parent the new parent {@code ConfigurationInterpolator}
+     * @return a reference to this object for method chaining
+     * @see 
ConfigurationInterpolator#setParentInterpolator(ConfigurationInterpolator)
+     */
+    T setParentInterpolator(ConfigurationInterpolator parent);
 }

Modified: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java?rev=1426620&r1=1426619&r2=1426620&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java
 Fri Dec 28 20:25:44 2012
@@ -195,6 +195,20 @@ public class TestBasicBuilderParameters
     }
 
     /**
+     * Tests whether a parent {@code ConfigurationInterpolator} can be set.
+     */
+    @Test
+    public void testSetParentInterpolator()
+    {
+        ConfigurationInterpolator parent =
+                EasyMock.createMock(ConfigurationInterpolator.class);
+        EasyMock.replay(parent);
+        assertSame("Wrong result", params, 
params.setParentInterpolator(parent));
+        assertSame("Wrong parent", parent,
+                params.getParameters().get("parentInterpolator"));
+    }
+
+    /**
      * Tests whether a custom {@code ConfigurationInterpolator} overrides
      * settings for custom lookups.
      */
@@ -203,14 +217,19 @@ public class TestBasicBuilderParameters
     {
         Lookup look1 = EasyMock.createMock(Lookup.class);
         Lookup look2 = EasyMock.createMock(Lookup.class);
+        ConfigurationInterpolator parent =
+                EasyMock.createMock(ConfigurationInterpolator.class);
         ConfigurationInterpolator ci =
                 EasyMock.createMock(ConfigurationInterpolator.class);
         params.setDefaultLookups(Collections.singleton(look1));
         params.setPrefixLookups(Collections.singletonMap("test", look2));
         params.setInterpolator(ci);
+        params.setParentInterpolator(parent);
         Map<String, Object> map = params.getParameters();
         assertFalse("Got prefix lookups", map.containsKey("prefixLookups"));
         assertFalse("Got default lookups", map.containsKey("defaultLookups"));
+        assertFalse("Got a parent interpolator",
+                map.containsKey("parentInterpolator"));
     }
 
     /**


Reply via email to