ebourg      2004/08/20 08:49:27

  Modified:    configuration/xdocs changes.xml
               configuration/src/java/org/apache/commons/configuration
                        HierarchicalConfigurationConverter.java
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationFactory.java
               configuration/conf testDigesterConfiguration3.xml
  Log:
  Fixed the handling of attribute properties by HierarchicalConfigurationConverter 
(bug 30655)
  
  Revision  Changes    Path
  1.37      +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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- changes.xml       20 Aug 2004 13:55:41 -0000      1.36
  +++ changes.xml       20 Aug 2004 15:49:27 -0000      1.37
  @@ -7,6 +7,9 @@
   
     <body>
       <release version="1.0-rc2" date="in CVS">
  +      <action dev="ebourg" type="fix" issue="30655" due-to="Oliver Heger">
  +        Fixed the handling of attribute properties by 
HierarchicalConfigurationConverter.
  +      </action>
         <action dev="ebourg" type="fix" issue="30676">
           Fixed a ClassCastException thrown on adding a non string property
           in a DatabaseConfiguration.
  
  
  
  1.4       +33 -10    
jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationConverter.java
  
  Index: HierarchicalConfigurationConverter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalConfigurationConverter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HierarchicalConfigurationConverter.java   24 Jun 2004 12:35:15 -0000      1.3
  +++ HierarchicalConfigurationConverter.java   20 Aug 2004 15:49:27 -0000      1.4
  @@ -19,8 +19,10 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Collections;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Set;
   
   /**
    * <p>A base class for converters that transform a normal configuration
  @@ -56,18 +58,28 @@
           {
               ConfigurationKey keyEmpty = new ConfigurationKey();
               ConfigurationKey keyLast = keyEmpty;
  +            Set keySet = new HashSet();
   
               for (Iterator it = config.getKeys(); it.hasNext();)
               {
                   String key = (String) it.next();
  +                if (keySet.contains(key))
  +                {
  +                     // this key has already been processed by openElements
  +                     continue;
  +                }
                   ConfigurationKey keyAct = new ConfigurationKey(key);
                   closeElements(keyLast, keyAct);
  -                String elem = openElements(keyLast, keyAct);
  -                fireValue(elem, config.getProperty(key));
  +                String elem = openElements(keyLast, keyAct, config, keySet);
  +                if (elem != null)
  +                {
  +                     fireValue(elem, config.getProperty(key));
  +                }
                   keyLast = keyAct;
               }
   
  -            closeElements(keyLast, keyEmpty); // close all open
  +            // close all open
  +            closeElements(keyLast, keyEmpty);
           }
       }
   
  @@ -142,22 +154,33 @@
        * Fires all necessary element start events for the specified key. This
        * method is called for each key obtained from the configuration to be
        * converted. It ensures that all elements "between" the last key and the
  -     * actual key are opened.
  +     * actual key are opened and their values are set.
        *
        * @param keyLast the last processed key
        * @param keyAct the actual key
  +     * @param config the configuration to process
  +     * @param keySet the set with the processed keys
        * @return the name of the last element on the path
        */
  -    protected String openElements(ConfigurationKey keyLast, ConfigurationKey keyAct)
  +    protected String openElements(ConfigurationKey keyLast, ConfigurationKey 
keyAct, Configuration config, Set keySet)
       {
           ConfigurationKey.KeyIterator it = keyLast.differenceKey(keyAct).iterator();
   
  -        for (it.nextKey(); it.hasNext(); it.nextKey())
  +        if(it.hasNext())
           {
  -            elementStart(it.currentKey(), null);
  +             ConfigurationKey k = keyLast.commonKey(keyAct);
  +             for (it.nextKey(); it.hasNext(); it.nextKey())
  +             {
  +                     k.append(it.currentKey(true));
  +                 elementStart(it.currentKey(true), 
config.getProperty(k.toString()));
  +                 keySet.add(k.toString());
  +             }
  +             return it.currentKey(true);
  +        }
  +        else
  +        {
  +             return null;
           }
  -
  -        return it.currentKey();
       }
   
       /**
  
  
  
  1.14      +4 -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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TestConfigurationFactory.java     12 Aug 2004 15:46:15 -0000      1.13
  +++ TestConfigurationFactory.java     20 Aug 2004 15:49:27 -0000      1.14
  @@ -222,7 +222,9 @@
           //assertEquals(4, cc.getNumberOfConfigurations());
   
           assertNotNull(config.getProperty("tables.table(0).fields.field(2).name"));
  -        //assertNotNull(config.getProperty("element2.subelement.subsubelement"));
  +        assertNotNull(config.getProperty("element2.subelement.subsubelement"));
  +        assertEquals("value", config.getProperty("element3"));
  +        assertEquals("foo", config.getProperty("[EMAIL PROTECTED]"));
           assertNotNull(config.getProperty("mail.account.user"));
                   
           assertNotNull(config.getProperty("test.onlyinjndi"));
  
  
  
  1.6       +1 -2      
jakarta-commons/configuration/conf/testDigesterConfiguration3.xml
  
  Index: testDigesterConfiguration3.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/conf/testDigesterConfiguration3.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- testDigesterConfiguration3.xml    14 Aug 2004 11:21:26 -0000      1.5
  +++ testDigesterConfiguration3.xml    20 Aug 2004 15:49:27 -0000      1.6
  @@ -3,8 +3,7 @@
   
   <configuration>
     <additional>
  -    <!--xml format seems to cause configuration factory to die-->
  -    <!--xml fileName="test.xml"/-->
  +    <xml fileName="test.xml"/>
       <hierarchicalXml fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
       <properties fileName="testDigesterConfigurationInclude2.properties" at="mail"/>
       <jndi prefix=""/>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to