commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r437816 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/PropertiesConfiguration.java src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java xdocs/changes.xml
Date Mon, 28 Aug 2006 20:28:26 GMT
Author: oheger
Date: Mon Aug 28 13:28:25 2006
New Revision: 437816

URL: http://svn.apache.org/viewvc?rev=437816&view=rev
Log:
Fix for CONFIGURATION-222: PropertiesConfiguration.save() does not work any more when the
configuration was created in memory. Thanks to Gabriele Garuglieri for the patch.

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=437816&r1=437815&r2=437816&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Mon Aug 28 13:28:25 2006
@@ -208,6 +208,7 @@
      */
     public PropertiesConfiguration()
     {
+        layout = createLayout();
         setIncludesAllowed(false);
     }
 
@@ -340,7 +341,20 @@
      */
     public synchronized void setLayout(PropertiesConfigurationLayout layout)
     {
-        this.layout = layout;
+        // only one layout must exist
+        if (this.layout != null)
+        {
+            removeConfigurationListener(this.layout);
+        }
+
+        if (layout == null)
+        {
+            this.layout = createLayout();
+        }
+        else
+        {
+            this.layout = layout;
+        }
     }
 
     /**

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=437816&r1=437815&r2=437816&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Mon Aug 28 13:28:25 2006
@@ -158,6 +158,45 @@
         checkConfig.save();
     }
 
+    public void testInMemoryCreatedSave() throws Exception
+    {
+        // remove the file previously saved if necessary
+        if (testSavePropertiesFile.exists())
+        {
+            assertTrue(testSavePropertiesFile.delete());
+        }
+
+        PropertiesConfiguration pc = new PropertiesConfiguration();
+        // add an array of strings to the configuration
+        pc.addProperty("string", "value1");
+        List list = new ArrayList();
+        for (int i = 1; i < 5; i++)
+        {
+            list.add("value" + i);
+        }
+        pc.addProperty("array", list);
+
+        // save the configuration
+        String filename = testSavePropertiesFile.getAbsolutePath();
+        pc.save(filename);
+
+        assertTrue("The saved file doesn't exist", testSavePropertiesFile.exists());
+
+        // read the configuration and compare the properties
+        PropertiesConfiguration checkConfig = new PropertiesConfiguration(filename);
+        for (Iterator i = pc.getKeys(); i.hasNext();)
+        {
+            String key = (String) i.next();
+            assertTrue("The saved configuration doesn't contain the key '" + key + "'",
+                    checkConfig.containsKey(key));
+            assertEquals("Value of the '" + key + "' property", 
+                    pc.getProperty(key), checkConfig.getProperty(key));
+        }
+
+        // Save it again, verifing a save with a filename works.
+        checkConfig.save();
+    }
+
     public void testSaveMissingFilename()
     {
         PropertiesConfiguration pc = new PropertiesConfiguration();

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=437816&r1=437815&r2=437816&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Aug 28 13:28:25 2006
@@ -23,6 +23,13 @@
   <body>
 
     <release version="1.3-rc2" date="in SVN">
+      <action dev="oheger" type="update" issue="CONFIGURATION-222" due-to="Gabriele Garuglieri">
+        The new PropertiesConfigurationLayout class broke the save() operation
+        of PropertiesConfiguration when an instance was newly created and
+        populated in memory. This is fixed now by ensuring that a layout object
+        is immediately created and registered as event listener at the
+        configuration.
+      </action>
       <action dev="oheger" type="add" issue="CONFIGURATION-221" due-to="Rainer Jung">
         ConfigurationFactory now supports variables in its configuration
         definition files. These variables are resolved using system properties



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message