commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r225835 - in /jakarta/commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/AbstractFileConfiguration.java test/org/apache/commons/configuration/TestFileConfiguration.java
Date Thu, 28 Jul 2005 18:13:41 GMT
Author: oheger
Date: Thu Jul 28 11:13:27 2005
New Revision: 225835

URL: http://svn.apache.org/viewcvs?rev=225835&view=rev
Log:
Changed AbstractFileConfiguration.save() to throw an exception if no file name has been set.
JavaDoc updates.

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java?rev=225835&r1=225834&r2=225835&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Thu Jul 28 11:13:27 2005
@@ -180,11 +180,12 @@
     }
 
     /**
-     * Locate the specified file and load the configuration.
+     * Locate the specified file and load the configuration. This does not
+     * change the source of the configuration (i.e. the internally maintained file name).
+     * Use one of the setter methods for this purpose.
      *
-     * @param fileName the name of the file loaded
-     *
-     * @throws ConfigurationException
+     * @param fileName the name of the file to be loaded
+     * @throws ConfigurationException if an error occurs
      */
     public void load(String fileName) throws ConfigurationException
     {
@@ -209,11 +210,12 @@
     }
 
     /**
-     * Load the configuration from the specified file.
-     *
-     * @param file the loaded file
+     * Load the configuration from the specified file. This does not change
+     * the source of the configuration (i.e. the internally maintained file
+     * name). Use one of the setter methods for this purpose.
      *
-     * @throws ConfigurationException
+     * @param file the file to load
+     * @throws ConfigurationException if an error occurs
      */
     public void load(File file) throws ConfigurationException
     {
@@ -232,11 +234,12 @@
     }
 
     /**
-     * Load the configuration from the specified URL.
-     *
-     * @param url the URL of the file loaded
+     * Load the configuration from the specified URL. This does not change the
+     * source of the configuration (i.e. the internally maintained file name).
+     * Use on of the setter methods for this purpose.
      *
-     * @throws ConfigurationException
+     * @param url the URL of the file to be loaded
+     * @throws ConfigurationException if an error occurs
      */
     public void load(URL url) throws ConfigurationException
     {
@@ -329,12 +332,19 @@
     }
 
     /**
-     * Save the configuration.
+     * Save the configuration. Before this method can be called a valid file
+     * name must have been set.
      *
-     * @throws ConfigurationException
+     * @throws ConfigurationException if an error occurs or no file name has
+     * been set yet
      */
     public void save() throws ConfigurationException
     {
+        if (getFileName() == null)
+        {
+            throw new ConfigurationException("No file name has been set!");
+        }
+        
         if (sourceURL != null)
         {
             save(sourceURL);

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java?rev=225835&r1=225834&r2=225835&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
Thu Jul 28 11:13:27 2005
@@ -369,4 +369,48 @@
         config.load();
         assertEquals(file, config.getFile());
     }
+    
+    /**
+     * Tests to invoke save() without explicitely setting a file name. This
+     * will cause an exception.
+     */
+    public void testSaveWithoutFileName() throws Exception
+    {
+        FileConfiguration config = new PropertiesConfiguration();
+        File file = new File("conf/test.properties");
+        config.load(file);
+        try
+        {
+            config.save();
+            fail("Could save config without setting a file name!");
+        }
+        catch(ConfigurationException cex)
+        {
+            //ok
+        }
+        
+        config = new PropertiesConfiguration();
+        config.load("conf/test.properties");
+        try
+        {
+            config.save();
+            fail("Could save config without setting a file name!");
+        }
+        catch(ConfigurationException cex)
+        {
+            //ok
+        }
+        
+        config = new PropertiesConfiguration();
+        config.load(file.toURL());
+        try
+        {
+            config.save();
+            fail("Could save config without setting a file name!");
+        }
+        catch(ConfigurationException cex)
+        {
+            //ok
+        }
+    }
 }



---------------------------------------------------------------------
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