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 Tue, 05 Oct 2004 21:17:25 GMT
ebourg      2004/10/05 14:17:25

  Modified:    configuration/src/java/org/apache/commons/configuration
                        AbstractConfiguration.java SubsetConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestSubsetConfiguration.java
               configuration/xdocs changes.xml
  Log:
  SubsetConfiguration now shares the "throwExceptionOnMissing" property with its parent.
  
  Revision  Changes    Path
  1.25      +8 -6      jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AbstractConfiguration.java	21 Sep 2004 17:58:10 -0000	1.24
  +++ AbstractConfiguration.java	5 Oct 2004 21:17:25 -0000	1.25
  @@ -56,14 +56,15 @@
       private static final int INITIAL_LIST_SIZE = 2;
   
       /**
  -     * Whether the configuration should throw NoSuchElementExceptions or simply return
null
  -     * when a property does not exist. Defaults to return null.
  +     * Whether the configuration should throw NoSuchElementExceptions or simply
  +     * return null when a property does not exist. Defaults to return null.
        */
       private boolean throwExceptionOnMissing = false;
   
       /**
        * For configurations extending AbstractConfiguration, allow them to
        * change the delimiter from the default comma (",").
  +     *
        * @param delimiter The new delimiter
        */
       public static void setDelimiter(char delimiter)
  @@ -73,6 +74,7 @@
   
       /**
        * Retrieve the current delimiter.  By default this is a comma (",").
  +     * 
        * @return The delimiter in use
        */
       public static char getDelimiter()
  @@ -832,7 +834,7 @@
           {
               return number;
           }
  -        else if (throwExceptionOnMissing)
  +        else if (isThrowExceptionOnMissing())
           {
               throw new NoSuchElementException(
                   '\'' + key + "' doesn't map to an existing object");
  @@ -886,7 +888,7 @@
           {
               return number;
           }
  -        else if (throwExceptionOnMissing)
  +        else if (isThrowExceptionOnMissing())
           {
               throw new NoSuchElementException(
                       '\'' + key + "' doesn't map to an existing object");
  @@ -941,7 +943,7 @@
           {
               return s;
           }
  -        else if (throwExceptionOnMissing)
  +        else if (isThrowExceptionOnMissing())
           {
               throw new NoSuchElementException(
                   '\'' + key + "' doesn't map to an existing object");
  
  
  
  1.6       +35 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/SubsetConfiguration.java
  
  Index: SubsetConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/SubsetConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SubsetConfiguration.java	24 Jun 2004 14:01:03 -0000	1.5
  +++ SubsetConfiguration.java	5 Oct 2004 21:17:25 -0000	1.6
  @@ -238,4 +238,38 @@
               return config.interpolate(base);
           }
       }
  +
  +    /**
  +     * {@inheritDoc}
  +     *
  +     * Change the behaviour of the parent configuration if it supports this feature.
  +     */
  +    public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
  +    {
  +        if (parent instanceof AbstractConfiguration)
  +        {
  +            ((AbstractConfiguration) parent).setThrowExceptionOnMissing(throwExceptionOnMissing);
  +        }
  +        else
  +        {
  +            super.setThrowExceptionOnMissing(throwExceptionOnMissing);
  +        }
  +    }
  +
  +    /**
  +     * {@inheritDoc}
  +     *
  +     * The subset inherits this feature from its parent if it supports this feature.
  +     */
  +    public boolean isThrowExceptionOnMissing()
  +    {
  +        if (parent instanceof AbstractConfiguration)
  +        {
  +            return ((AbstractConfiguration) parent).isThrowExceptionOnMissing();
  +        }
  +        else
  +        {
  +            return super.isThrowExceptionOnMissing();
  +        }
  +    }
   }
  
  
  
  1.6       +36 -1     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java
  
  Index: TestSubsetConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestSubsetConfiguration.java	23 Sep 2004 11:41:05 -0000	1.5
  +++ TestSubsetConfiguration.java	5 Oct 2004 21:17:25 -0000	1.6
  @@ -19,6 +19,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.NoSuchElementException;
   import java.util.Vector;
   
   import junit.framework.TestCase;
  @@ -162,5 +163,39 @@
   
           assertEquals("prefix", "prefix", subset.getPrefix());
       }
  +
  +    public void testThrowtExceptionOnMissing()
  +    {
  +        BaseConfiguration config = new BaseConfiguration();
  +        config.setThrowExceptionOnMissing(true);
  +
  +        SubsetConfiguration subset = new SubsetConfiguration(config, "prefix");
  +
  +        try
  +        {
  +            subset.getString("foo");
  +            fail("NoSuchElementException expected");
  +        }
  +        catch (NoSuchElementException e)
  +        {
  +            // expected
  +        }
  +
  +        config.setThrowExceptionOnMissing(false);
  +        assertNull(subset.getString("foo"));
  +
  +
  +        subset.setThrowExceptionOnMissing(true);
  +        try
  +        {
  +            config.getString("foo");
  +            fail("NoSuchElementException expected");
  +        }
  +        catch (NoSuchElementException e)
  +        {
  +            // expected
  +        }
  +    }
  +
   
   }
  
  
  
  1.52      +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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- changes.xml	4 Oct 2004 21:45:11 -0000	1.51
  +++ changes.xml	5 Oct 2004 21:17:25 -0000	1.52
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0" date="IN CVS">
  +      <action dev="ebourg" type="fix" issue="31540">
  +        SubsetConfiguration now shares the "throwExceptionOnMissing" property
  +        with its parent.
  +      </action>
         <action dev="ebourg" type="fix">
           Removed "file:" at the beginning of the base path when calling
           setFile() on a FileConfiguration. This prevented auto saving an
  
  
  

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