You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by he...@apache.org on 2002/12/21 18:11:30 UTC

cvs commit: jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration BaseConfiguration.java

henning     2002/12/21 09:11:30

  Modified:    configuration/src/java/org/apache/commons/configuration
                        BaseConfiguration.java
  Log:
  If in a property is stored a multiple value field (a Container) and only
  a single property value is requested, return transparently the first value
  in the multi value property. This did work for Strings but not for all other
  property types. Suggested by Mark Orciuch <mo...@apache.org>.
  
  Revision  Changes    Path
  1.6       +29 -15    jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java
  
  Index: BaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseConfiguration.java	3 Dec 2002 14:13:55 -0000	1.5
  +++ BaseConfiguration.java	21 Dec 2002 17:11:30 -0000	1.6
  @@ -619,8 +619,7 @@
        */
       public Boolean getBoolean(String key, Boolean defaultValue)
       {
  -
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Boolean)
           {
  @@ -706,7 +705,7 @@
        */
       public Byte getByte(String key, Byte defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Byte)
           {
  @@ -791,7 +790,7 @@
        */
       public Double getDouble(String key, Double defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Double)
           {
  @@ -876,7 +875,7 @@
        */
       public Float getFloat(String key, Float defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Float)
           {
  @@ -969,7 +968,7 @@
        */
       public Integer getInteger(String key, Integer defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Integer)
           {
  @@ -1054,7 +1053,7 @@
        */
       public Long getLong(String key, Long defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Long)
           {
  @@ -1139,7 +1138,7 @@
        */
       public Short getShort(String key, Short defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof Short)
           {
  @@ -1192,7 +1191,7 @@
        */
       public String getString(String key, String defaultValue)
       {
  -        Object value = store.get(key);
  +        Object value = resolveContainerStore(key);
   
           if (value instanceof String)
           {
  @@ -1209,10 +1208,6 @@
                   return interpolate(defaultValue);
               }
           }
  -        else if (value instanceof Container)
  -        {
  -            return interpolate((String) ((Container) value).get(0));
  -        }
           else
           {
               throw new ClassCastException(
  @@ -1326,6 +1321,26 @@
       }
   
       /**
  +     * Returns an object from the store described by the key.
  +     * If the value is a Container object, replace it with the
  +     * first object in the container
  +     *
  +     * @param key The property key.
  +     *
  +     * @return value Value, transparently resolving a possible
  +     *               Container dependency.
  +     */
  +    private Object resolveContainerStore(String key)
  +    {
  +        Object value = store.get(key);
  +        if (value != null && value instanceof Container)
  +        {
  +            value = ((Container) value).get(0);
  +        }
  +        return value;
  +    }
  +
  +    /**
        * This class divides into tokens a property value.  Token
        * separator is "," but commas into the property value are escaped
        * using the backslash in front.
  @@ -1381,7 +1396,6 @@
               return buffer.toString().trim();
           }
       } // class PropertiesTokenizer
  -
   
       /**
        * Private Wrapper class for Vector, so we can distinguish between
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>