commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1435346 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/
Date Fri, 18 Jan 2013 21:14:39 GMT
Author: oheger
Date: Fri Jan 18 21:14:39 2013
New Revision: 1435346

URL: http://svn.apache.org/viewvc?rev=1435346&view=rev
Log:
Extracted a method for accessing managed builders.
Parameter objects for managed builders are now cloned before they are applied.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java?rev=1435346&r1=1435345&r2=1435346&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
Fri Jan 18 21:14:39 2013
@@ -23,13 +23,13 @@ import java.util.concurrent.ConcurrentMa
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.commons.configuration.FileBasedConfiguration;
 import org.apache.commons.configuration.builder.BasicBuilderParameters;
 import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
 import org.apache.commons.configuration.builder.BuilderListener;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilder;
-import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
 import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
 import org.apache.commons.configuration.event.ConfigurationErrorListener;
 import org.apache.commons.configuration.event.ConfigurationListener;
@@ -155,6 +155,24 @@ public class MultiFileConfigurationBuild
     @Override
     public T getConfiguration() throws ConfigurationException
     {
+        return getManagedBuilder().getConfiguration();
+    }
+
+    /**
+     * Returns the managed {@code FileBasedConfigurationBuilder} for the current
+     * file name pattern. It is determined based on the evaluation of the file
+     * name pattern using the configured {@code ConfigurationInterpolator}. If
+     * this is the first access to this configuration file, the builder is
+     * created.
+     *
+     * @return the configuration builder for the configuration corresponding to
+     *         the current evaluation of the file name pattern
+     * @throws ConfigurationException if the builder cannot be determined (e.g.
+     *         due to missing initialization parameters)
+     */
+    public FileBasedConfigurationBuilder<T> getManagedBuilder()
+            throws ConfigurationException
+    {
         Map<String, Object> params = getParameters();
         MultiFileBuilderParametersImpl multiParams =
                 MultiFileBuilderParametersImpl.fromParameters(params, true);
@@ -183,8 +201,7 @@ public class MultiFileConfigurationBuild
                 builder = newBuilder;
             }
         }
-
-        return builder.getConfiguration();
+        return builder;
     }
 
     /**
@@ -363,14 +380,11 @@ public class MultiFileConfigurationBuild
                 multiParams.getManagedBuilderParameters();
         if (managedBuilderParameters != null)
         {
-            newParams.putAll(managedBuilderParameters.getParameters());
-        }
-
-        // ensure that file-based parameters are available
-        if (FileBasedBuilderParametersImpl.fromParameters(newParams) == null)
-        {
-            newParams.putAll(new FileBasedBuilderParametersImpl()
-                    .getParameters());
+            // clone parameters as they are applied to multiple builders
+            BuilderParameters copy =
+                    (BuilderParameters) ConfigurationUtils
+                            .cloneIfPossible(managedBuilderParameters);
+            newParams.putAll(copy.getParameters());
         }
         return newParams;
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java?rev=1435346&r1=1435345&r2=1435346&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
Fri Jan 18 21:14:39 2013
@@ -426,4 +426,25 @@ public class TestMultiFileConfigurationB
         managedBuilders.iterator().next().resetResult();
         EasyMock.verify(listener);
     }
+
+    /**
+     * Tests whether initialization parameters of managed builders are cloned
+     * before they are applied.
+     */
+    @Test
+    public void testGetManagedBuilderClonedParameters()
+            throws ConfigurationException
+    {
+        MultiFileConfigurationBuilder<XMLConfiguration> builder =
+                createTestBuilder(new XMLBuilderParametersImpl());
+        switchToConfig(1);
+        FileBasedConfigurationBuilder<XMLConfiguration> managedBuilder1 =
+                builder.getManagedBuilder();
+        switchToConfig(2);
+        FileBasedConfigurationBuilder<XMLConfiguration> managedBuilder2 =
+                builder.getManagedBuilder();
+        assertNotSame("Managed parameters not cloned",
+                managedBuilder1.getFileHandler(),
+                managedBuilder2.getFileHandler());
+    }
 }



Mime
View raw message