You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ep...@apache.org on 2004/02/12 13:59:19 UTC

cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration HierarchicalConfigurationXMLReader.java CompositeConfiguration.java AbstractConfiguration.java Configuration.java BaseConfigurationXMLReader.java

epugh       2004/02/12 04:59:19

  Modified:    configuration/xdocs changes.xml
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationFactory.java
                        TestJNDIConfiguration.java
                        TestBaseConfiguration.java
               configuration/src/java/org/apache/commons/configuration
                        HierarchicalConfigurationXMLReader.java
                        CompositeConfiguration.java
                        AbstractConfiguration.java Configuration.java
                        BaseConfigurationXMLReader.java
  Log:
  Add in bignumber and biginteger.
  
  Revision  Changes    Path
  1.8       +3 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- changes.xml	30 Jan 2004 14:53:11 -0000	1.7
  +++ changes.xml	12 Feb 2004 12:59:19 -0000	1.8
  @@ -7,6 +7,9 @@
   
     <body>
       <release version="1.0-dev-4" date="">
  +      <action dev="ebourg" type="add">
  +        The Configuration interface now supports BigDecimal and BigInteger numbers.
  +      </action>
   	 <action dev="epugh" type="add">
         	ConfigurationException is now thrown by public methods instead of Exception or
         	IOException or whatnot.
  
  
  
  1.6       +2 -2      jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
  
  Index: TestConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestConfigurationFactory.java	30 Jan 2004 14:46:37 -0000	1.5
  +++ TestConfigurationFactory.java	12 Feb 2004 12:59:19 -0000	1.6
  @@ -183,7 +183,7 @@
   	{
       	configurationFactory.setConfigurationFileName(testDigesterBadXML.toString());
       	try {
  -    		Configuration c = configurationFactory.getConfiguration();
  +    		configurationFactory.getConfiguration();
       		fail("Should have throw an Exception");
       	}
       	catch (ConfigurationException cle){
  
  
  
  1.2       +2 -2      jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestJNDIConfiguration.java
  
  Index: TestJNDIConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestJNDIConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestJNDIConfiguration.java	16 Jan 2004 17:32:36 -0000	1.1
  +++ TestJNDIConfiguration.java	12 Feb 2004 12:59:19 -0000	1.2
  @@ -74,7 +74,7 @@
       public void setUp() throws Exception
       {
   		InitialContext context = new InitialContext();
  -			
  +		assertNotNull(context);
           
           JNDIConfiguration jndiConfiguration = new JNDIConfiguration();
   		jndiConfiguration.setPrefix("");
  
  
  
  1.4       +24 -2     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
  
  Index: TestBaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestBaseConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestBaseConfiguration.java	16 Jan 2004 14:23:39 -0000	1.3
  +++ TestBaseConfiguration.java	12 Feb 2004 12:59:19 -0000	1.4
  @@ -54,9 +54,11 @@
    * <http://www.apache.org/>.
    */
   
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
  +import java.util.List;
   import java.util.NoSuchElementException;
   import java.util.Properties;
  -import java.util.List;
   
   import junit.framework.TestCase;
   
  @@ -160,6 +162,26 @@
           assertEquals("This returns 1(Double)",
                        eprop.getDouble("numberD",new Double("2")),
                        new Double(oneD));
  +    }
  +
  +    public void testGetBigDecimal() {
  +        eprop.setProperty("numberBigD", "123.456");
  +        BigDecimal number = new BigDecimal("123.456");
  +        BigDecimal defaultValue = new BigDecimal("654.321");
  +
  +        assertEquals("Existing key", number, eprop.getBigDecimal("numberBigD"));
  +        assertEquals("Existing key with default value", number, eprop.getBigDecimal("numberBigD", defaultValue));
  +        assertEquals("Missing key with default value", defaultValue, eprop.getBigDecimal("numberNotInConfig", defaultValue));
  +    }
  +
  +    public void testGetBigInteger() {
  +        eprop.setProperty("numberBigI", "1234567890");
  +        BigInteger number = new BigInteger("1234567890");
  +        BigInteger defaultValue = new BigInteger("654321");
  +
  +        assertEquals("Existing key", number, eprop.getBigInteger("numberBigI"));
  +        assertEquals("Existing key with default value", number, eprop.getBigInteger("numberBigI", defaultValue));
  +        assertEquals("Missing key with default value", defaultValue, eprop.getBigInteger("numberNotInConfig", defaultValue));
       }
   
       public void testGetBoolean() {
  
  
  
  1.2       +2 -5      jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java
  
  Index: HierarchicalConfigurationXMLReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationXMLReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HierarchicalConfigurationXMLReader.java	23 Dec 2003 15:09:05 -0000	1.1
  +++ HierarchicalConfigurationXMLReader.java	12 Feb 2004 12:59:19 -0000	1.2
  @@ -54,11 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.IOException;
  -
   import org.apache.commons.configuration.HierarchicalConfiguration.Node;
   import org.xml.sax.Attributes;
  -import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
   
   /**
  @@ -137,7 +134,7 @@
        * @throws IOException if no configuration has been specified
        * @throws SAXException if an error occurs during parsing
        */
  -    protected void processKeys() throws IOException, SAXException
  +    protected void processKeys()
       {
           getConfiguration().getRoot().visit(new SAXVisitor(), null);
       }
  
  
  
  1.5       +36 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java
  
  Index: CompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CompositeConfiguration.java	7 Feb 2004 13:43:15 -0000	1.4
  +++ CompositeConfiguration.java	12 Feb 2004 12:59:19 -0000	1.5
  @@ -53,6 +53,8 @@
    * <http://www.apache.org/>.
    */
   
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.LinkedList;
  @@ -654,6 +656,39 @@
               return defaultValue;
           }
       }
  +
  +    public BigDecimal getBigDecimal(String key) throws NoSuchElementException {
  +        return getFirstMatchingConfig(key).getBigDecimal(key);
  +    }
  +
  +    public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
  +    {
  +        try
  +        {
  +            return getFirstMatchingConfig(key).getBigDecimal(key, defaultValue);
  +        }
  +        catch (NoSuchElementException nsee)
  +        {
  +            return defaultValue;
  +        }
  +    }
  +
  +    public BigInteger getBigInteger(String key) throws NoSuchElementException {
  +        return getFirstMatchingConfig(key).getBigInteger(key);
  +    }
  +
  +    public BigInteger getBigInteger(String key, BigInteger defaultValue)
  +    {
  +        try
  +        {
  +            return getFirstMatchingConfig(key).getBigInteger(key, defaultValue);
  +        }
  +        catch (NoSuchElementException nsee)
  +        {
  +            return defaultValue;
  +        }
  +    }
  +
       /**
        * Get a string associated with the given configuration key.
        *
  
  
  
  1.4       +89 -1     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractConfiguration.java	16 Jan 2004 14:27:57 -0000	1.3
  +++ AbstractConfiguration.java	12 Feb 2004 12:59:19 -0000	1.4
  @@ -61,6 +61,8 @@
   import java.util.NoSuchElementException;
   import java.util.Properties;
   import java.util.StringTokenizer;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   import org.apache.commons.lang.BooleanUtils;
   
  @@ -1200,6 +1202,92 @@
           {
               throw new ClassCastException(
                   '\'' + key + "' doesn't map to a Short object");
  +        }
  +    }
  +
  +    public BigDecimal getBigDecimal(String key) throws NoSuchElementException {
  +        BigDecimal number = getBigDecimal(key, null);
  +        if (number != null)
  +        {
  +            return number;
  +        }
  +        else
  +        {
  +            throw new NoSuchElementException(
  +                '\'' + key + "' doesn't map to an existing object");
  +        }
  +    }
  +
  +    public BigDecimal getBigDecimal(String key, BigDecimal defaultValue) {
  +        Object value = resolveContainerStore(key);
  +
  +        if (value instanceof BigDecimal)
  +        {
  +            return (BigDecimal) value;
  +        }
  +        else if (value instanceof String)
  +        {
  +            BigDecimal number = new BigDecimal((String) value);
  +            return number;
  +        }
  +        else if (value == null)
  +        {
  +            if (defaults != null)
  +            {
  +                return defaults.getBigDecimal(key, defaultValue);
  +            }
  +            else
  +            {
  +                return defaultValue;
  +            }
  +        }
  +        else
  +        {
  +            throw new ClassCastException(
  +                '\'' + key + "' doesn't map to a BigDecimal object");
  +        }
  +    }
  +
  +    public BigInteger getBigInteger(String key) throws NoSuchElementException {
  +        BigInteger number = getBigInteger(key, null);
  +        if (number != null)
  +        {
  +            return number;
  +        }
  +        else
  +        {
  +            throw new NoSuchElementException(
  +                '\'' + key + "' doesn't map to an existing object");
  +        }
  +    }
  +
  +    public BigInteger getBigInteger(String key, BigInteger defaultValue) {
  +        Object value = resolveContainerStore(key);
  +
  +        if (value instanceof BigDecimal)
  +        {
  +            return (BigInteger) value;
  +        }
  +        else if (value instanceof String)
  +        {
  +            BigInteger number = new BigInteger((String) value);
  +            return number;
  +        }
  +        else if (value == null)
  +        {
  +            if (defaults != null)
  +            {
  +                return defaults.getBigInteger(key, defaultValue);
  +            }
  +            else
  +            {
  +                return defaultValue;
  +            }
  +        }
  +        else
  +        {
  +            throw new ClassCastException(
  +                '\'' + key + "' doesn't map to a BigDecimal object");
           }
       }
   
  
  
  
  1.3       +50 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/Configuration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Configuration.java	24 Dec 2003 14:28:22 -0000	1.2
  +++ Configuration.java	12 Feb 2004 12:59:19 -0000	1.3
  @@ -57,6 +57,9 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Properties;
  +import java.util.NoSuchElementException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    * Configuration interface.
  @@ -454,6 +457,52 @@
        * map to an existing object.
        */
       Short getShort(String key, Short defaultValue);
  +
  +    /**
  +     * Get a BigDecimal associated with the given configuration key.
  +     *
  +     * @param key The configuration key.
  +     *
  +     * @return The associated BigDecimal if key is found and has valid format
  +     *
  +     * @exception NoSuchElementException is thrown if the key doesn't
  +     * map to an existing object.
  +     */
  +    BigDecimal getBigDecimal(String key) throws NoSuchElementException;
  +
  +    /**
  +     * Get a BigDecimal associated with the given configuration key.
  +     *
  +     * @param key          The configuration key.
  +     * @param defaultValue The default value.
  +     *
  +     * @return The associated BigDecimal if key is found and has valid
  +     * format, default value otherwise.
  +     */
  +    BigDecimal getBigDecimal(String key, BigDecimal defaultValue);
  +
  +    /**
  +     * Get a BigInteger associated with the given configuration key.
  +     *
  +     * @param key The configuration key.
  +     *
  +     * @return The associated BigInteger if key is found and has valid format
  +     *
  +     * @exception NoSuchElementException is thrown if the key doesn't
  +     * map to an existing object.
  +     */
  +    BigInteger getBigInteger(String key) throws NoSuchElementException;
  +
  +    /**
  +     * Get a BigInteger associated with the given configuration key.
  +     *
  +     * @param key          The configuration key.
  +     * @param defaultValue The default value.
  +     *
  +     * @return The associated BigInteger if key is found and has valid
  +     * format, default value otherwise.
  +     */
  +    BigInteger getBigInteger(String key, BigInteger defaultValue);
   
       /**
        * Get a string associated with the given configuration key.
  
  
  
  1.2       +2 -7      jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfigurationXMLReader.java
  
  Index: BaseConfigurationXMLReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BaseConfigurationXMLReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseConfigurationXMLReader.java	23 Dec 2003 15:09:05 -0000	1.1
  +++ BaseConfigurationXMLReader.java	12 Feb 2004 12:59:19 -0000	1.2
  @@ -54,9 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.IOException;
  -
  -import org.xml.sax.SAXException;
   
   /**
    * <p>A specialized SAX2 XML parser that processes configuration objects.</p>
  @@ -124,10 +121,8 @@
        * <code>HierarchicalConfigurationConverter</code> object to iterate over
        * all keys in the actual configuration and to generate corresponding SAX
        * events.
  -     * @throws IOException if no configuration object is specified
  -     * @throws SAXException if a SAXException occurs during parsing
        */
  -    protected void processKeys() throws IOException, SAXException
  +    protected void processKeys()
       {
           fireElementStart(getRootName(), null);
           new SAXConverter().process(getConfiguration());
  
  
  

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