Author: oheger
Date: Sat Oct 30 19:15:30 2010
New Revision: 1029166

URL: http://svn.apache.org/viewvc?rev=1029166&view=rev
Log:
[CONFIGURATION-410] Added a refresh() method to 
AbstractHierarchicalFileConfiguration.

Modified:
    
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
    
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java?rev=1029166&r1=1029165&r2=1029166&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractHierarchicalFileConfiguration.java
 Sat Oct 30 19:15:30 2010
@@ -27,12 +27,12 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.configuration.event.ConfigurationErrorEvent;
+import org.apache.commons.configuration.event.ConfigurationErrorListener;
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
-import org.apache.commons.configuration.event.ConfigurationErrorListener;
-import org.apache.commons.configuration.event.ConfigurationErrorEvent;
-import org.apache.commons.configuration.reloading.ReloadingStrategy;
 import org.apache.commons.configuration.reloading.Reloadable;
+import org.apache.commons.configuration.reloading.ReloadingStrategy;
 
 /**
  * <p>Base class for implementing file based hierarchical configurations.</p>
@@ -316,6 +316,21 @@ implements FileConfiguration, Configurat
         }
     }
 
+    /**
+     * Reloads the associated configuration file. This method first clears the
+     * content of this configuration, then the associated configuration file is
+     * loaded again. Updates on this configuration which have not yet been 
saved
+     * are lost. Calling this method is like invoking <code>reload()</code>
+     * without checking the reloading strategy.
+     *
+     * @throws ConfigurationException if an error occurs
+     * @since 1.7
+     */
+    public void refresh() throws ConfigurationException
+    {
+        delegate.refresh();
+    }
+
     public String getEncoding()
     {
         return delegate.getEncoding();

Modified: 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1029166&r1=1029165&r2=1029166&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
 Sat Oct 30 19:15:30 2010
@@ -679,6 +679,35 @@ public class TestXMLConfiguration extend
     }
 
     /**
+     * Tests the refresh() method.
+     */
+    public void testRefresh() throws ConfigurationException
+    {
+        conf.setProperty("element", "anotherValue");
+        conf.refresh();
+        assertEquals("Wrong property after refresh", "value",
+                conf.getString("element"));
+    }
+
+    /**
+     * Tries to call refresh() when the configuration is not associated with a
+     * file.
+     */
+    public void testRefreshNoFile() throws ConfigurationException
+    {
+        conf = new XMLConfiguration();
+        try
+        {
+            conf.refresh();
+            fail("Could refresh a configuration without a file!");
+        }
+        catch (ConfigurationException cex)
+        {
+            // ok
+        }
+    }
+
+    /**
      * Tests access to tag names with delimiter characters.
      */
     public void testComplexNames()


Reply via email to