commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/xdocs changes.xml
Date Mon, 18 Oct 2004 11:12:09 GMT
ebourg      2004/10/18 04:12:09

  Modified:    configuration/src/java/org/apache/commons/configuration
                        AbstractFileConfiguration.java
                        FileConfiguration.java
                        HierarchicalXMLConfiguration.java
                        XMLConfiguration.java
               configuration/xdocs changes.xml
  Log:
  Moved the auto save logic from XMLConfiguration to AbstractFileConfiguration
  
  Revision  Changes    Path
  1.5       +43 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
  
  Index: AbstractFileConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractFileConfiguration.java	4 Oct 2004 21:45:10 -0000	1.4
  +++ AbstractFileConfiguration.java	18 Oct 2004 11:12:08 -0000	1.5
  @@ -45,6 +45,7 @@
       protected String fileName;
       protected String basePath;
       protected URL url;
  +    protected boolean autoSave;
   
       /**
        * Load the configuration from the underlying URL. If the URL is not
  @@ -430,5 +431,46 @@
   
           // update the file name
           fileName = ConfigurationUtils.getFileName(url);
  +    }
  +
  +    public void setAutoSave(boolean autoSave)
  +    {
  +        this.autoSave = autoSave;
  +    }
  +
  +    public boolean isAutoSave()
  +    {
  +        return autoSave;
  +    }
  +
  +    /**
  +     * Save the configuration if the automatic persistence is enabled
  +     * and if a file is specified.
  +     */
  +    protected void possiblySave()
  +    {
  +        if (autoSave && fileName != null)
  +        {
  +            try
  +            {
  +                save();
  +            }
  +            catch (ConfigurationException e)
  +            {
  +                throw new ConfigurationRuntimeException("Failed to auto-save", e);
  +            }
  +        }
  +    }
  +
  +    protected void addPropertyDirect(String key, Object obj)
  +    {
  +        super.addPropertyDirect(key, obj);
  +        possiblySave();
  +    }
  +
  +    public void clearProperty(String key)
  +    {
  +        super.clearProperty(key);
  +        possiblySave();
       }
   }
  
  
  
  1.2       +17 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/FileConfiguration.java
  
  Index: FileConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/FileConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileConfiguration.java	22 Sep 2004 17:17:30 -0000	1.1
  +++ FileConfiguration.java	18 Oct 2004 11:12:08 -0000	1.2
  @@ -207,4 +207,20 @@
        */
       void setURL(URL url);
   
  +    /**
  +     * Enable of disable the automatical saving of modified properties to the disk.
  +     *
  +     * @param autoSave <code>true</code> to enable, <code>false</code>
to disable
  +     * @since 1.1
  +     */
  +    void setAutoSave(boolean autoSave);
  +
  +    /**
  +     * Tells if properties are automatically saved to the disk.
  +     *
  +     * @return <code>true</code> if auto-saving is enabled, <code>false</code>
otherwise
  +     * @since 1.1
  +     */
  +    boolean isAutoSave();
  +
   }
  
  
  
  1.4       +11 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalXMLConfiguration.java
  
  Index: HierarchicalXMLConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalXMLConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HierarchicalXMLConfiguration.java	22 Sep 2004 17:17:30 -0000	1.3
  +++ HierarchicalXMLConfiguration.java	18 Oct 2004 11:12:08 -0000	1.4
  @@ -239,6 +239,16 @@
           delegate.setURL(url);
       }
   
  +    public void setAutoSave(boolean autoSave)
  +    {
  +        delegate.setAutoSave(autoSave);
  +    }
  +
  +    public boolean isAutoSave()
  +    {
  +        return delegate.isAutoSave();
  +    }
  +
       private class FileConfigurationDelegate extends AbstractFileConfiguration {
   
           public void load(Reader in) throws ConfigurationException
  
  
  
  1.18      +7 -46     jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
  
  Index: XMLConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XMLConfiguration.java	4 Oct 2004 19:35:45 -0000	1.17
  +++ XMLConfiguration.java	18 Oct 2004 11:12:08 -0000	1.18
  @@ -54,15 +54,12 @@
    * <code>X.Y.Z[@attribute]</code>. The '@' symbol was chosen for consistency
    * with XPath.
    *
  - * Setting property values will <b>NOT </b> automatically persist changes to
  - * disk, unless <code>autoSave=true</code>.
  - *
    * @since commons-configuration 1.0
    *
    * @author Jörg Schaible
  - * @author <a href="mailto:kelvint@apache.org">Kelvin Tan </a>
  - * @author <a href="mailto:dlr@apache.org">Daniel Rall </a>
  - * @author Emmanuel Bourg
  + * @author <a href="mailto:kelvint@apache.org">Kelvin Tan</a>
  + * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
  + * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
    * @version $Revision$, $Date$
    */
   public class XMLConfiguration extends AbstractFileConfiguration
  @@ -84,11 +81,6 @@
       private Document document;
   
       /**
  -     * If true, modifications are immediately persisted.
  -     */
  -    private boolean autoSave = false;
  -
  -    /**
        * Creates an empty XML configuration.
        */
       public XMLConfiguration()
  @@ -220,7 +212,7 @@
       }
   
       /**
  -     * Calls super method, and also ensures the underlying {@linkDocument} is
  +     * Calls super method, and also ensures the underlying {@link Document} is
        * modified so changes are persisted when saved.
        *
        * @param name
  @@ -228,9 +220,8 @@
        */
       public void addProperty(String name, Object value)
       {
  -        super.addProperty(name, value);
           addXmlProperty(name, value);
  -        possiblySave();
  +        super.addProperty(name, value);
       }
   
       Object getXmlProperty(String name)
  @@ -425,9 +416,8 @@
        */
       public void clearProperty(String name)
       {
  -        super.clearProperty(name);
           clearXmlProperty(name);
  -        possiblySave();
  +        super.clearProperty(name);
       }
   
       private void clearXmlProperty(String name)
  @@ -492,35 +482,6 @@
                   child.removeAttribute(attName);
               }
           }
  -    }
  -
  -    /**
  -     * Save the configuration if the automatic persistence is enabled and a file
  -     * is specified.
  -     */
  -    private void possiblySave()
  -    {
  -        if (autoSave && fileName != null)
  -        {
  -            try
  -            {
  -                save();
  -            }
  -            catch (ConfigurationException ce)
  -            {
  -                throw new ConfigurationRuntimeException("Failed to auto-save", ce);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * If true, changes are automatically persisted.
  -     *
  -     * @param autoSave
  -     */
  -    public void setAutoSave(boolean autoSave)
  -    {
  -        this.autoSave = autoSave;
       }
   
       /**
  
  
  
  1.59      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- changes.xml	18 Oct 2004 10:44:31 -0000	1.58
  +++ changes.xml	18 Oct 2004 11:12:09 -0000	1.59
  @@ -8,6 +8,10 @@
     <body>
   
       <release version="1.1-dev" date="in CVS">
  +      <action dev="ebourg" type="add" issue="31532">
  +        The "autoSave" feature of XMLConfiguration has been generalized
  +        to all file based configurations.
  +      </action>
         <action dev="ebourg" type="add" issue="28026">
           Numeric properties can now be specified in hexadecimal format,
           for example "number = 0xC5F0".
  
  
  

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