commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1426618 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/AbstractConfiguration.java test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
Date Fri, 28 Dec 2012 20:25:02 GMT
Author: oheger
Date: Fri Dec 28 20:25:02 2012
New Revision: 1426618

URL: http://svn.apache.org/viewvc?rev=1426618&view=rev
Log:
Added a method for setting the parent ConfigurationInterpolator.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/AbstractConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.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=1426618&r1=1426617&r2=1426618&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
Fri Dec 28 20:25:02 2012
@@ -343,8 +343,9 @@ public abstract class AbstractConfigurat
      *
      * @param lookups a map with new {@code Lookup} objects and their prefixes
      *        (may be <b>null</b>)
+     * @since 2.0
      */
-    public final void setPrefixLookups(Map<String, ? extends Lookup> lookups)
+    public void setPrefixLookups(Map<String, ? extends Lookup> lookups)
     {
         boolean success;
         do
@@ -374,8 +375,9 @@ public abstract class AbstractConfigurat
      *
      * @param lookups the collection with default {@code Lookup} objects to be
      *        added
+     * @since 2.0
      */
-    public final void setDefaultLookups(Collection<? extends Lookup> lookups)
+    public void setDefaultLookups(Collection<? extends Lookup> lookups)
     {
         boolean success;
         do
@@ -399,6 +401,30 @@ public abstract class AbstractConfigurat
     }
 
     /**
+     * Sets the specified {@code ConfigurationInterpolator} as the parent of
+     * this configuration's {@code ConfigurationInterpolator}. If this
+     * configuration does not have a {@code ConfigurationInterpolator}, a new
+     * instance is created. Note: This method is mainly intended to be used for
+     * initializing a configuration when it is created by a builder. Normal
+     * client code can directly update the {@code ConfigurationInterpolator}.
+     *
+     * @param parent the parent {@code ConfigurationInterpolator} to be set
+     * @since 2.0
+     */
+    public void setParentInterpolator(ConfigurationInterpolator parent)
+    {
+        boolean success;
+        do
+        {
+            ConfigurationInterpolator ciOld = getInterpolator();
+            ConfigurationInterpolator ciNew =
+                    (ciOld != null) ? ciOld : new ConfigurationInterpolator();
+            ciNew.setParentInterpolator(parent);
+            success = interpolator.compareAndSet(ciOld, ciNew);
+        } while (!success);
+    }
+
+    /**
      * Creates a default {@code ConfigurationInterpolator} which is initialized
      * with all default {@code Lookup} objects. This method is called by the
      * constructor. It ensures that default interpolation works for every new

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?rev=1426618&r1=1426617&r2=1426618&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java
Fri Dec 28 20:25:02 2012
@@ -32,6 +32,7 @@ import java.util.Map;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.interpol.Lookup;
 import org.easymock.EasyMock;
 import org.junit.Test;
@@ -382,6 +383,43 @@ public class TestAbstractConfigurationBa
     }
 
     /**
+     * Tests whether a parent {@code ConfigurationInterpolator} can be set if
+     * already a {@code ConfigurationInterpolator} is available.
+     */
+    @Test
+    public void testSetParentInterpolatorExistingInterpolator()
+    {
+        ConfigurationInterpolator parent =
+                EasyMock.createMock(ConfigurationInterpolator.class);
+        EasyMock.replay(parent);
+        AbstractConfiguration config =
+                new TestConfigurationImpl(new PropertiesConfiguration());
+        ConfigurationInterpolator ci = config.getInterpolator();
+        config.setParentInterpolator(parent);
+        assertSame("Parent was not set", parent, config.getInterpolator()
+                .getParentInterpolator());
+        assertSame("Interpolator was changed", ci, config.getInterpolator());
+    }
+
+    /**
+     * Tests whether a parent {@code ConfigurationInterpolator} can be set if
+     * currently no {@code ConfigurationInterpolator} is available.
+     */
+    @Test
+    public void testSetParentInterpolatorNoInterpolator()
+    {
+        ConfigurationInterpolator parent =
+                EasyMock.createMock(ConfigurationInterpolator.class);
+        EasyMock.replay(parent);
+        AbstractConfiguration config =
+                new TestConfigurationImpl(new PropertiesConfiguration());
+        config.setInterpolator(null);
+        config.setParentInterpolator(parent);
+        assertSame("Parent was not set", parent, config.getInterpolator()
+                .getParentInterpolator());
+    }
+
+    /**
      * Tests getList() for single non-string values.
      */
     @Test



Mime
View raw message