commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration BaseConfiguration.java AbstractConfiguration.java
Date Fri, 17 Oct 2003 08:11:52 GMT
epugh       2003/10/17 01:11:52

  Modified:    configuration/xdocs changes.xml
               configuration/src/java/org/apache/commons/configuration
                        BaseConfiguration.java AbstractConfiguration.java
  Log:
  Patch from Oliver Heger to faciliate extending configuration classes
  
  Revision  Changes    Path
  1.3       +4 -0      jakarta-commons-sandbox/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/xdocs/changes.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- changes.xml	7 Oct 2003 10:58:56 -0000	1.2
  +++ changes.xml	17 Oct 2003 08:11:52 -0000	1.3
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0-dev-4" date="">
  +     <action dev="oheger" type="update">
  +      	AbstractConfiguration addProperty now delegates to an abstract addPropertyDirect
  +      	implemented by BaseConfiguration.  
  +     </action>    	
        <action dev="kshaposhnikov" type="update">
         	Changed getString() method to throw a NoSuchElementException instead of "" if the
         	configuration property doesn't exist.     
  
  
  
  1.16      +35 -2     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BaseConfiguration.java	12 Oct 2003 09:32:30 -0000	1.15
  +++ BaseConfiguration.java	17 Oct 2003 08:11:52 -0000	1.16
  @@ -79,6 +79,7 @@
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
    * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    * @author <a href="mailto:ksh@scand.com">Konstantin Shaposhnikov</a>
  + * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
    *
    * @version $Id$
    */
  @@ -115,7 +116,39 @@
        */
       protected void addPropertyDirect(String key, Object obj)
       {
  -        store.put(key, obj);
  +        Object o = getPropertyDirect(key);
  +        Object objAdd = null;
  +        
  +        if(o == null)
  +        {
  +            objAdd = obj;
  +        }
  +        else
  +        {
  +            if (o instanceof Container)
  +            {
  +                ((Container) o).add(obj);
  +            }
  +            else
  +            {
  +                // The token key is not a container.
  +                Container c = new Container();
  +
  +                // There is an element. Put it into the container
  +                // at the first position
  +                c.add(o);
  +
  +                // Now gobble up the supplied object
  +                c.add(obj);
  +
  +                objAdd = c;
  +            }
  +        }
  +        
  +        if(objAdd != null)
  +        {
  +            store.put(key, objAdd);
  +        }
       }
   
       /**
  
  
  
  1.3       +9 -55     jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/AbstractConfiguration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractConfiguration.java	12 Oct 2003 09:32:30 -0000	1.2
  +++ AbstractConfiguration.java	17 Oct 2003 08:11:52 -0000	1.3
  @@ -69,6 +69,7 @@
    * then you should implement only abstract methods from this class.
    *
    * @author <a href="mailto:ksh@scand.com">Konstantin Shaposhnikov</a>
  + * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
    * @version $Id$
    */
   public abstract class AbstractConfiguration implements Configuration
  @@ -124,11 +125,13 @@
        */
       public void addProperty(String key, Object token)
       {
  -        List tokenAdd = null;
  -
           if (token instanceof String)
           {
  -            tokenAdd = processString((String) token);
  +            for(Iterator it = processString((String) token).iterator();
  +            it.hasNext();)
  +            {
  +                addPropertyDirect(key, it.next());
  +            }
           }
           else if (token instanceof Collection)
           {
  @@ -136,59 +139,10 @@
               {
                   addProperty(key, it.next());
               }
  -            return;
  -        }
  -        else
  -        {
  -            tokenAdd = new Vector(1);
  -            tokenAdd.add(token);
  -        }
  -
  -        Object o = getPropertyDirect(key);
  -
  -        if (o instanceof Container)
  -        {
  -            // There is already a container for our key in the config
  -            // Simply add the new tokens
  -            for (Iterator it = tokenAdd.iterator(); it.hasNext();)
  -            {
  -                ((Container) o).add(it.next());
  -            }
           }
           else
           {
  -            // No Key at all or the token key is not a container.
  -            Container c = new Container();
  -
  -            if (o != null)
  -            {
  -                // There is an element. Put it into the container
  -                // at the first position
  -                c.add(o);
  -            }
  -
  -            // Now gobble up the supplied objects
  -            for (Iterator it = tokenAdd.iterator(); it.hasNext();)
  -            {
  -                c.add(it.next());
  -            }
  -
  -            // Do we have a key? If not, we simply add either the container
  -            // (If the element was a CSV) or the first element of the
  -            // Container (if its size is 1)
  -
  -            if (o == null && c.size() == 1)
  -            {
  -                // No Key existed and only one got put into the container. Then
  -                // add the key direct. Do not mess with the container
  -                addPropertyDirect(key, c.get(0));
  -            }
  -            else
  -            {
  -                // Either a key already existed or there was a CSV supplied
  -                // Add the Container to the Store
  -                addPropertyDirect(key, c);
  -            }
  +            addPropertyDirect(key, token);
           }
       }
   
  @@ -1550,7 +1504,7 @@
        * Private Wrapper class for Vector, so we can distinguish between
        * Vector objects and our container
        */
  -    class Container
  +    static class Container
       {
           /** We're wrapping a List object (A vector) */
           private List l = null;
  
  
  

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