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 2016/02/14 19:59:53 UTC

svn commit: r1730374 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/builder/combined/ test/java/org/apache/commons/configuration2/builder/combined/

Author: oheger
Date: Sun Feb 14 18:59:53 2016
New Revision: 1730374

URL: http://svn.apache.org/viewvc?rev=1730374&view=rev
Log:
[CONFIGURATION-619] Extended CombinedBuilderParametersImpl.

A new flag was introduced which controls the inheritance of builder
settings to child configurations. If this flag is true (which is the
default value), parameter objects for child configuration builders
are initialized with some of the settings of the parent builder.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderParametersImpl.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderProperties.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedBuilderParametersImpl.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderParametersImpl.java?rev=1730374&r1=1730373&r2=1730374&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderParametersImpl.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderParametersImpl.java Sun Feb 14 18:59:53 2016
@@ -75,6 +75,9 @@ public class CombinedBuilderParametersIm
     /** The base path for configuration sources to be loaded. */
     private String basePath;
 
+    /** A flag whether settings should be inherited by child builders. */
+    private boolean inheritSettings;
+
     /**
      * Creates a new instance of {@code CombinedBuilderParametersImpl}.
      */
@@ -82,6 +85,7 @@ public class CombinedBuilderParametersIm
     {
         providers = new HashMap<String, ConfigurationBuilderProvider>();
         childParameters = new LinkedList<BuilderParameters>();
+        inheritSettings = true;
     }
 
     /**
@@ -124,6 +128,27 @@ public class CombinedBuilderParametersIm
     }
 
     /**
+     * Returns the current value of the flag that controls whether the settings
+     * of the parent combined configuration builder should be inherited by its
+     * child configurations.
+     *
+     * @return the flag whether settings should be inherited by child
+     *         configurations
+     */
+    public boolean isInheritSettings()
+    {
+        return inheritSettings;
+    }
+
+    @Override
+    public CombinedBuilderParametersImpl setInheritSettings(
+            boolean inheritSettings)
+    {
+        this.inheritSettings = inheritSettings;
+        return this;
+    }
+
+    /**
      * Returns the {@code ConfigurationBuilder} object for obtaining the
      * definition configuration.
      *

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderProperties.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderProperties.java?rev=1730374&r1=1730373&r2=1730374&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderProperties.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/builder/combined/CombinedBuilderProperties.java Sun Feb 14 18:59:53 2016
@@ -45,6 +45,19 @@ import org.apache.commons.configuration2
 public interface CombinedBuilderProperties<T>
 {
     /**
+     * Sets a flag whether the child configurations created by a
+     * {@code CombinedConfigurationBuilder} should inherit the settings defined
+     * for the builder. This is typically useful because for configurations
+     * coming from homogeneous sources often similar conventions are used.
+     * Therefore, this flag is <b>true</b> per default.
+     *
+     * @param f the flag whether settings should be inherited by child
+     *        configurations
+     * @return a reference to this object for method chaining
+     */
+    T setInheritSettings(boolean f);
+
+    /**
      * Sets the {@code ConfigurationBuilder} for the definition configuration.
      * This is the configuration which contains the configuration sources that
      * form the combined configuration.

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedBuilderParametersImpl.java?rev=1730374&r1=1730373&r2=1730374&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedBuilderParametersImpl.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedBuilderParametersImpl.java Sun Feb 14 18:59:53 2016
@@ -17,6 +17,7 @@
 package org.apache.commons.configuration2.builder.combined;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
@@ -98,6 +99,19 @@ public class TestCombinedBuilderParamete
     }
 
     /**
+     * Tests whether the flag that controls settings inheritance can be set.
+     */
+    @Test
+    public void testSetInheritSettings()
+    {
+        CombinedBuilderParametersImpl params =
+                new CombinedBuilderParametersImpl();
+        assertTrue("Wrong initial value", params.isInheritSettings());
+        assertSame("Wrong result", params, params.setInheritSettings(false));
+        assertFalse("Property not set", params.isInheritSettings());
+    }
+
+    /**
      * Tests whether the definition builder can be set.
      */
     @Test
@@ -318,9 +332,11 @@ public class TestCombinedBuilderParamete
         BeanHelper.setProperty(params, "basePath", "testPath");
         BeanHelper.setProperty(params, "definitionBuilderParameters",
                 defparams);
+        BeanHelper.setProperty(params, "inheritSettings", false);
         assertEquals("Wrong path", "testPath", params.getBasePath());
         assertSame("Wrong def parameters", defparams,
                 params.getDefinitionBuilderParameters());
+        assertFalse("Wrong inherit flag", params.isInheritSettings());
     }
 
     /**