commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1433642 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
Date Tue, 15 Jan 2013 20:56:02 GMT
Author: oheger
Date: Tue Jan 15 20:56:02 2013
New Revision: 1433642

URL: http://svn.apache.org/viewvc?rev=1433642&view=rev
Log:
Improved handling of file-based parameters in FileBasedConfigurationBuilder.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java?rev=1433642&r1=1433641&r2=1433642&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/FileBasedConfigurationBuilder.java
Tue Jan 15 20:56:02 2013
@@ -169,13 +169,24 @@ public class FileBasedConfigurationBuild
     }
 
     /**
-     * Obtains the {@code FileHandler} from this builder's parameters.
+     * Obtains the {@code FileHandler} from this builder's parameters. If no
+     * {@code FileBasedBuilderParametersImpl} object is found in this builder's
+     * parameters, a new one is created now and stored. This makes it possible
+     * to change the location of the associated file even if no parameters
+     * object was provided.
      *
      * @return the {@code FileHandler} from initialization parameters
      */
     private FileHandler fetchFileHandlerFromParameters()
     {
-        return FileBasedBuilderParametersImpl.fromParameters(getParameters(), true)
-                .getFileHandler();
+        FileBasedBuilderParametersImpl fileParams =
+                FileBasedBuilderParametersImpl.fromParameters(getParameters(),
+                        false);
+        if (fileParams == null)
+        {
+            fileParams = new FileBasedBuilderParametersImpl();
+            addParameters(fileParams.getParameters());
+        }
+        return fileParams.getFileHandler();
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java?rev=1433642&r1=1433641&r2=1433642&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestFileBasedConfigurationBuilder.java
Tue Jan 15 20:56:02 2013
@@ -218,4 +218,20 @@ public class TestFileBasedConfigurationB
                         PropertiesConfiguration.class, null, true);
         assertTrue("Flag not set", builder.isAllowFailOnInit());
     }
+
+    /**
+     * Tests whether a file handler can be accessed and manipulated even if no
+     * file-based parameters are part of the initialization parameters.
+     */
+    @Test
+    public void testSetLocationNoFileHandler() throws ConfigurationException
+    {
+        File file = createTestFile(1);
+        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
+                new FileBasedConfigurationBuilder<PropertiesConfiguration>(
+                        PropertiesConfiguration.class);
+        builder.getFileHandler().setFile(file);
+        PropertiesConfiguration config = builder.getConfiguration();
+        assertFalse("No data was loaded", config.isEmpty());
+    }
 }



Mime
View raw message