You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2004/07/12 14:14:38 UTC

cvs commit: jakarta-commons/configuration/xdocs changes.xml howto_configurationfactory.xml howto_xml.xml overview.xml

ebourg      2004/07/12 05:14:38

  Modified:    configuration/conf digesterRules.xml
                        testConfigurationXMLDocument.xml
                        testDigesterBadXML.xml
                        testDigesterConfiguration.xml
                        testDigesterConfiguration2.xml
                        testDigesterConfiguration3.xml
                        testDigesterConfigurationNamespaceAware.xml
                        testDigesterConfigurationReverseOrder.xml
                        testDigesterConfigurationWJNDI.xml
               configuration/src/java/org/apache/commons/configuration
                        ConfigurationFactory.java ConfigurationUtils.java
                        XMLConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        NonStringTestHolder.java
                        TestCompositeConfiguration.java
                        TestConfigurationFactory.java
                        TestHierarchicalConfigurationXMLReader.java
               configuration/xdocs changes.xml
                        howto_configurationfactory.xml howto_xml.xml
                        overview.xml
  Added:       configuration/conf testHierarchicalXMLConfiguration.xml
               configuration/src/java/org/apache/commons/configuration
                        HierarchicalXMLConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestHierarchicalXMLConfiguration.java
                        TestXMLConfiguration.java
  Removed:     configuration/conf testHierarchicalDOM4JConfiguration.xml
               configuration/src/java/org/apache/commons/configuration
                        DOM4JConfiguration.java DOMConfiguration.java
                        HierarchicalDOM4JConfiguration.java
                        HierarchicalDOMConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestDOM4JConfiguration.java
                        TestDOMConfiguration.java
                        TestHierarchicalDOM4JConfiguration.java
                        TestHierarchicalDOMConfiguration.java
  Log:
  Removed the DOM4J implementations in favor of the DOM ones.
  DOMConfiguration has been renamed to XMLConfiguration, and HierarchicalDOMConfiguration to HierarchicalXMLConfiguration.
  The elements parsed by the ConfigurationFactory have been changed accordingly.
  
  Revision  Changes    Path
  1.2       +22 -18    jakarta-commons/configuration/conf/digesterRules.xml
  
  Index: digesterRules.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/digesterRules.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- digesterRules.xml	23 Dec 2003 15:09:05 -0000	1.1
  +++ digesterRules.xml	12 Jul 2004 12:14:37 -0000	1.2
  @@ -1,22 +1,26 @@
   <?xml version="1.0"?>
   <!DOCTYPE digester-rules PUBLIC "-//Jakarta Apache //DTD digester-rules XML V1.0//EN" "http://jakarta.apache.org/commons/digester/dtds/digester-rules.dtd">
  +
   <digester-rules>
  -  <pattern value="configuration/properties">
  -    <object-create-rule classname="org.apache.commons.configuration.PropertiesConfiguration"/>
  -    <set-properties-rule/>
  -    <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  -    <call-method-rule methodname="load"/>
  -  </pattern>
  -  <pattern value="configuration/dom4j">
  -    <object-create-rule classname="org.apache.commons.configuration.DOM4JConfiguration"/>
  -    <set-properties-rule/>
  -    <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  -    <call-method-rule methodname="load"/>
  -  </pattern>  
  -  <pattern value="configuration/jndi">
  -    <object-create-rule classname="org.apache.commons.configuration.JNDIConfiguration"/>
  -    <set-properties-rule/>
  -    <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  -    
  -  </pattern>    
  +
  +    <pattern value="configuration/properties">
  +        <object-create-rule classname="org.apache.commons.configuration.PropertiesConfiguration"/>
  +        <set-properties-rule/>
  +        <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  +        <call-method-rule methodname="load"/>
  +    </pattern>
  +
  +    <pattern value="configuration/xml">
  +        <object-create-rule classname="org.apache.commons.configuration.XMLConfiguration"/>
  +        <set-properties-rule/>
  +        <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  +        <call-method-rule methodname="load"/>
  +    </pattern>
  +
  +    <pattern value="configuration/jndi">
  +        <object-create-rule classname="org.apache.commons.configuration.JNDIConfiguration"/>
  +        <set-properties-rule/>
  +        <set-next-rule methodname="addConfiguration" paramtype="org.apache.commons.configuration.Configuration"/>
  +    </pattern>
  +
   </digester-rules>
  
  
  
  1.4       +3 -9      jakarta-commons/configuration/conf/testConfigurationXMLDocument.xml
  
  Index: testConfigurationXMLDocument.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testConfigurationXMLDocument.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testConfigurationXMLDocument.xml	8 Mar 2004 23:27:09 -0000	1.3
  +++ testConfigurationXMLDocument.xml	12 Jul 2004 12:14:37 -0000	1.4
  @@ -3,14 +3,8 @@
   
   <configuration>
     <additional>
  -    <hierarchicalDom4j fileName="testHierarchicalDOM4JConfiguration.xml" at="database"/>
  -    <hierarchicalDom4j fileName="testDigesterConfigurationInclude1.xml" at="database.tables"/>
  -    <hierarchicalDom4j fileName="testDigesterCreateObject.xml" at="database"/>
  +    <hierarchicalXml fileName="testHierarchicalXMLConfiguration.xml" at="database"/>
  +    <hierarchicalXml fileName="testDigesterConfigurationInclude1.xml" at="database.tables"/>
  +    <hierarchicalXml fileName="testDigesterCreateObject.xml" at="database"/>
     </additional>
   </configuration>
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.2       +1 -1      jakarta-commons/configuration/conf/testDigesterBadXML.xml
  
  Index: testDigesterBadXML.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterBadXML.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testDigesterBadXML.xml	23 Jan 2004 11:52:36 -0000	1.1
  +++ testDigesterBadXML.xml	12 Jul 2004 12:14:37 -0000	1.2
  @@ -5,7 +5,7 @@
   
   <configuration>
     <additional>
  -    <dom4j className="org.apache.commons.configuration.HierarchicalDOM4JConfiguration" fileName="testHierarchicalDOM4JConfiguration.xml"/>
  +    <xml className="org.apache.commons.configuration.HierarchicalXMLConfiguration" fileName="testHierarchicalXMLConfiguration.xml"/>
      
   </configuration>
   
  
  
  
  1.3       +1 -7      jakarta-commons/configuration/conf/testDigesterConfiguration.xml
  
  Index: testDigesterConfiguration.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfiguration.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testDigesterConfiguration.xml	8 Mar 2004 23:21:30 -0000	1.2
  +++ testDigesterConfiguration.xml	12 Jul 2004 12:14:37 -0000	1.3
  @@ -2,11 +2,5 @@
   
   <configuration>
     <properties fileName="conf/test.properties"/>
  -  <dom4j fileName="conf/test.xml"/>
  +  <xml fileName="conf/test.xml"/>
   </configuration>
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.4       +2 -8      jakarta-commons/configuration/conf/testDigesterConfiguration2.xml
  
  Index: testDigesterConfiguration2.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfiguration2.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testDigesterConfiguration2.xml	8 Mar 2004 23:21:30 -0000	1.3
  +++ testDigesterConfiguration2.xml	12 Jul 2004 12:14:37 -0000	1.4
  @@ -4,8 +4,8 @@
   
   <configuration>
     <additional>
  -    <hierarchicalDom4j fileName="testHierarchicalDOM4JConfiguration.xml"/>
  -    <hierarchicalDom4j fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
  +    <hierarchicalXml fileName="testHierarchicalXMLConfiguration.xml"/>
  +    <hierarchicalXml fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
       <properties fileName="testDigesterConfigurationInclude2.properties" at="mail"/>
     </additional>
   
  @@ -13,9 +13,3 @@
       <properties fileName="testDigesterConfigurationOverwrite.properties"/>
     </override>
   </configuration>
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.2       +2 -8      jakarta-commons/configuration/conf/testDigesterConfiguration3.xml
  
  Index: testDigesterConfiguration3.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfiguration3.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testDigesterConfiguration3.xml	14 Feb 2004 20:06:23 -0000	1.1
  +++ testDigesterConfiguration3.xml	12 Jul 2004 12:14:37 -0000	1.2
  @@ -3,15 +3,9 @@
   
   <configuration>
     <additional>
  -    <dom4j fileName="test.xml"/>
  -    <hierarchicalDom4j fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
  +    <xml fileName="test.xml"/>
  +    <hierarchicalXml fileName="testDigesterConfigurationInclude1.xml" at="tables"/>
       <properties fileName="testDigesterConfigurationInclude2.properties" at="mail"/>
       <jndi prefix=""/>
     </additional>
   </configuration>
  -
  -  
  -
  -
  -
  -
  
  
  
  1.2       +1 -10     jakarta-commons/configuration/conf/testDigesterConfigurationNamespaceAware.xml
  
  Index: testDigesterConfigurationNamespaceAware.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfigurationNamespaceAware.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testDigesterConfigurationNamespaceAware.xml	23 Dec 2003 15:09:05 -0000	1.1
  +++ testDigesterConfigurationNamespaceAware.xml	12 Jul 2004 12:14:37 -0000	1.2
  @@ -1,16 +1,7 @@
   <?xml version="1.0" encoding="ISO-8859-1" ?>
   
  -
  -
   <configuration xmlns:foo="namespace-one"
                  xmlns:bar="namespace-two">
     <foo:properties className="org.apache.commons.configuration.PropertiesConfiguration" fileName="conf/test.properties"/>
  -  <bar:dom4j className="org.apache.commons.configuration.DOM4JConfiguration" fileName="conf/test.xml"/>
  +  <bar:dom className="org.apache.commons.configuration.XMLConfiguration" fileName="conf/test.xml"/>
   </configuration>
  -
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.3       +1 -8      jakarta-commons/configuration/conf/testDigesterConfigurationReverseOrder.xml
  
  Index: testDigesterConfigurationReverseOrder.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfigurationReverseOrder.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testDigesterConfigurationReverseOrder.xml	8 Mar 2004 23:21:30 -0000	1.2
  +++ testDigesterConfigurationReverseOrder.xml	12 Jul 2004 12:14:37 -0000	1.3
  @@ -1,13 +1,6 @@
   <?xml version="1.0" encoding="ISO-8859-1" ?>
   
   <configuration>
  -  <dom4j fileName="conf/test.xml"/>
  +  <xml fileName="conf/test.xml"/>
     <properties fileName="conf/test.properties"/>
  -  
   </configuration>
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.2       +1 -9      jakarta-commons/configuration/conf/testDigesterConfigurationWJNDI.xml
  
  Index: testDigesterConfigurationWJNDI.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testDigesterConfigurationWJNDI.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testDigesterConfigurationWJNDI.xml	23 Dec 2003 15:09:05 -0000	1.1
  +++ testDigesterConfigurationWJNDI.xml	12 Jul 2004 12:14:37 -0000	1.2
  @@ -3,13 +3,5 @@
   <configuration>
     <jndi className="org.apache.commons.configuration.JNDIConfiguration" prefix="java:comp/env"/>
     <properties className="org.apache.commons.configuration.PropertiesConfiguration" fileName="conf/test.properties"/>
  -  <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" fileName="conf/test.xml"/>
  -  
  -  
  +  <dom className="org.apache.commons.configuration.XMLConfiguration" fileName="conf/test.xml"/>
   </configuration>
  -
  -  
  -  
  -
  -
  -
  
  
  
  1.1                  jakarta-commons/configuration/conf/testHierarchicalXMLConfiguration.xml
  
  Index: testHierarchicalXMLConfiguration.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  
  <database>
    <tables>
      <table tableType="system">
        <name>users</name>
        <fields>
          <field>
  	  <name>uid</name>
  	  <type>long</type>
  	</field>
          <field>
  	  <name>uname</name>
  	  <type>java.lang.String</type>
  	</field>
          <field>
  	  <name>firstName</name>
  	  <type>java.lang.String</type>
  	</field>
          <field>
  	  <name>lastName</name>
  	  <type>java.lang.String</type>
  	</field>
          <field>
  	  <name>email</name>
  	  <type>java.lang.String</type>
  	</field>
        </fields>
      </table>
      <table tableType="application">
        <name>documents</name>
        <fields>
          <field>
  	  <name>docid</name>
  	  <type>long</type>
  	</field>
          <field>
  	  <name>name</name>
  	  <type>java.lang.String</type>
  	</field>
          <field>
  	  <name>creationDate</name>
  	  <type>java.util.Date</type>
  	</field>
          <field>
  	  <name>authorID</name>
  	  <type>long</type>
  	</field>
          <field>
  	  <name>version</name>
  	  <type>int</type>
  	</field>
        </fields>
      </table>
    </tables>
  </database>
  
  
  
  1.15      +14 -12    jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
  
  Index: ConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ConfigurationFactory.java	5 Jul 2004 09:54:17 -0000	1.14
  +++ ConfigurationFactory.java	12 Jul 2004 12:14:37 -0000	1.15
  @@ -278,18 +278,21 @@
               new BasePathConfigurationFactory(PropertiesConfiguration.class),
               METH_LOAD,
               additional);
  +
           setupDigesterInstance(
               digester,
  -            matchString + "dom4j",
  -            new BasePathConfigurationFactory(DOM4JConfiguration.class),
  +            matchString + "xml",
  +            new BasePathConfigurationFactory(XMLConfiguration.class),
               METH_LOAD,
               additional);
  +
           setupDigesterInstance(
               digester,
  -            matchString + "hierarchicalDom4j",
  -            new BasePathConfigurationFactory(HierarchicalDOM4JConfiguration.class),
  +            matchString + "hierarchicalXml",
  +            new BasePathConfigurationFactory(HierarchicalXMLConfiguration.class),
               METH_LOAD,
               additional);
  +
           setupDigesterInstance(
               digester,
               matchString + "jndi",
  @@ -310,11 +313,11 @@
        * added
        */
       protected void setupDigesterInstance(
  -        Digester digester,
  -        String matchString,
  -        ObjectCreationFactory factory,
  -        String method,
  -        boolean additional)
  +            Digester digester,
  +            String matchString,
  +            ObjectCreationFactory factory,
  +            String method,
  +            boolean additional)
       {
           if (additional)
           {
  @@ -486,9 +489,8 @@
       /**
        * A tiny inner class that allows the Configuration Factory to
        * let the digester construct JNDIPathConfiguration objects.
  -     *
        */
  -    public class JNDIConfigurationFactory extends DigesterConfigurationFactory
  +    private class JNDIConfigurationFactory extends DigesterConfigurationFactory
       {
           /**
            * C'tor
  
  
  
  1.5       +2 -2      jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java
  
  Index: ConfigurationUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConfigurationUtils.java	23 Jun 2004 11:15:45 -0000	1.4
  +++ ConfigurationUtils.java	12 Jul 2004 12:14:38 -0000	1.5
  @@ -151,7 +151,7 @@
        */
       static File constructFile(String basePath, String fileName)
       {
  -        // code from DOM4JConfiguration
  +        // code from XMLConfiguration
           File file = null;
           if (StringUtils.isEmpty(basePath))
           {
  
  
  
  1.4       +463 -4    jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
  
  Index: XMLConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLConfiguration.java	24 Jun 2004 12:35:15 -0000	1.3
  +++ XMLConfiguration.java	12 Jul 2004 12:14:38 -0000	1.4
  @@ -16,14 +16,473 @@
   
   package org.apache.commons.configuration;
   
  +import java.io.File;
  +import java.io.FileWriter;
  +import java.io.IOException;
  +import java.net.URL;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.FactoryConfigurationError;
  +import javax.xml.parsers.ParserConfigurationException;
  +
  +import org.apache.commons.lang.StringUtils;
  +import org.w3c.dom.Attr;
  +import org.w3c.dom.CharacterData;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
  +import org.xml.sax.SAXException;
  +
   /**
  - * Base class for reading an XML configuration file.
  + * Reads a XML configuration file.
    *
  - * @since 0.8.1
  + * To retrieve the value of an attribute of an element, use
  + * <code>X.Y.Z[@attribute]</code>.  The '@' symbol was chosen for
  + * consistency with XPath.
    *
  + * Setting property values will <b>NOT</b> automatically persist
  + * changes to disk, unless <code>autoSave=true</code>.
  + *
  + * @since commons-configuration 1.0
  + *
  + * @author J�rg Schaible
  + * @author <a href="mailto:kelvint@apache.org">Kelvin Tan</a>
    * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
    * @version $Revision$, $Date$
    */
  -public abstract class XMLConfiguration extends BasePathConfiguration
  +public class XMLConfiguration extends BasePathConfiguration
   {
  +    // For conformance with xpath
  +    private static final char ATTRIB_MARKER = '@';
  +    private static final String ATTRIB_START_MARKER = "[" + ATTRIB_MARKER;
  +
  +    /**
  +     * For consistency with properties files.  Access nodes via an
  +     * "A.B.C" notation.
  +     */
  +    private static final String NODE_DELIMITER = ".";
  +
  +    /**
  +     * A handle to our data source.
  +     */
  +    private String fileName;
  +
  +    /**
  +     * The XML document from our data source.
  +     */
  +    private Document document;
  +
  +    /**
  +     * If true, modifications are immediately persisted.
  +     */
  +    private boolean autoSave = false;
  +
  +    /**
  +     * Empty construtor.  You must provide a file/fileName
  +     * and call the load method
  +     *
  +     */
  +    public XMLConfiguration()
  +    {
  +    }
  +
  +    /**
  +     * Attempts to load the XML file as a resource from the
  +     * classpath. The XML file must be located somewhere in the
  +     * classpath.
  +     *
  +     * @param resource Name of the resource
  +     * @throws ConfigurationException If error reading data source.
  +     */
  +    public XMLConfiguration(String resource) throws ConfigurationException
  +    {
  +        setFile(resourceURLToFile(resource));
  +        load();
  +    }
  +
  +    /**
  +     * Attempts to load the XML file.
  +     *
  +     * @param file File object representing the XML file.
  +     * @throws ConfigurationException If error reading data source.
  +     */
  +    public XMLConfiguration(File file) throws ConfigurationException
  +    {
  +        setFile(file);
  +        load();
  +    }
  +
  +    public void load() throws ConfigurationException
  +    {
  +        File file = null;
  +        try
  +        {
  +            URL url = ConfigurationUtils.getURL(getBasePath(), getFileName());
  +            file = new File(url.getFile());
  +            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  +            document = builder.parse(file);
  +        }
  +        catch (IOException de)
  +        {
  +            throw new ConfigurationException("Could not load from " + file.getAbsolutePath());
  +        }
  +        catch (ParserConfigurationException ex)
  +        {
  +            throw new ConfigurationException("Could not configure parser");
  +		}
  +        catch (FactoryConfigurationError ex)
  +        {
  +            throw new ConfigurationException("Could not create parser");
  +        }
  +        catch (SAXException ex)
  +        {
  +            throw new ConfigurationException("Error parsing file " + file.getAbsolutePath());
  +		}
  +
  +        initProperties(document.getDocumentElement(), new StringBuffer());
  +    }
  +
  +    private static File resourceURLToFile(String resource)
  +    {
  +        URL confURL = XMLConfiguration.class.getClassLoader().getResource(resource);
  +        if (confURL == null)
  +        {
  +            confURL = ClassLoader.getSystemResource(resource);
  +        }
  +        return new File(confURL.getFile());
  +    }
  +
  +    /**
  +     * Loads and initializes from the XML file.
  +     *
  +     * @param element The element to start processing from.  Callers
  +     *                should supply the root element of the document.
  +     * @param hierarchy
  +     */
  +    private void initProperties(Element element, StringBuffer hierarchy)
  +    {
  +        StringBuffer buffer = new StringBuffer();
  +        NodeList list = element.getChildNodes();
  +        for (int i = 0; i < list.getLength(); i++)
  +        {
  +            Node node = list.item(i);
  +            if (node instanceof Element)
  +            {
  +                StringBuffer subhierarchy = new StringBuffer(hierarchy.toString());
  +                Element child = (Element) node;
  +                subhierarchy.append(child.getTagName());
  +                processAttributes(subhierarchy.toString(), child);
  +                initProperties(child,
  +                        new StringBuffer(subhierarchy.toString()).append('.'));
  +            }
  +            else if (node instanceof CharacterData)
  +            {
  +                CharacterData data = (CharacterData)node;
  +                buffer.append(data.getData());
  +            }
  +        }
  +        String text = buffer.toString().trim();
  +        if (text.length() > 0 && hierarchy.length() > 0)
  +        {
  +            super.addProperty(
  +                    hierarchy.substring(0, hierarchy.length()-1), text);
  +        }
  +    }
  +
  +    /**
  +     * Helper method for constructing properties for the attributes of the
  +     * given XML element.
  +     *
  +     * @param hierarchy the actual hierarchy
  +     * @param element the actual XML element
  +     */
  +    private void processAttributes(String hierarchy, Element element)
  +    {
  +        // Add attributes as x.y{ATTRIB_START_MARKER}att{ATTRIB_END_MARKER}
  +        NamedNodeMap attributes = element.getAttributes();
  +        for (int i = 0; i < attributes.getLength(); ++i)
  +        {
  +            Node node = attributes.item(i);
  +            if (node instanceof Attr)
  +            {
  +                Attr attr = (Attr) node;
  +                String attrName = hierarchy + '[' + ATTRIB_MARKER + attr.getName() + ']';
  +                super.addProperty(attrName, attr.getValue());
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Calls super method, and also ensures the underlying {@link
  +     * Document} is modified so changes are persisted when saved.
  +     *
  +     * @param name
  +     * @param value
  +     */
  +    public void addProperty(String name, Object value)
  +    {
  +        super.addProperty(name, value);
  +        setXmlProperty(name, value);
  +        possiblySave();
  +    }
  +
  +    /**
  +     * Calls super method, and also ensures the underlying {@link
  +     * Document} is modified so changes are persisted when saved.
  +     *
  +     * @param name
  +     * @param value
  +     */
  +    public void setProperty(String name, Object value)
  +    {
  +        super.setProperty(name, value);
  +        setXmlProperty(name, value);
  +        possiblySave();
  +    }
  +
  +    /**
  +     * Sets the property value in our document tree, auto-saving if
  +     * appropriate.
  +     *
  +     * @param name The name of the element to set a value for.
  +     * @param value The value to set.
  +     */
  +    private void setXmlProperty(String name, Object value)
  +    {
  +        String[] nodes = StringUtils.split(name, NODE_DELIMITER);
  +        String attName = null;
  +        Element element = document.getDocumentElement();
  +        for (int i = 0; i < nodes.length; i++)
  +        {
  +            String eName = nodes[i];
  +            int index = eName.indexOf(ATTRIB_START_MARKER);
  +            if (index > -1)
  +            {
  +                attName = eName.substring(index + ATTRIB_START_MARKER.length(), eName.length() - 1);
  +                eName = eName.substring(0, index);
  +            }
  +
  +            Element child = null;
  +            NodeList list = element.getChildNodes();
  +            for (int j = 0; j < list.getLength(); j++)
  +            {
  +                Node node = list.item(j);
  +                if (node instanceof Element)
  +                {
  +                    child = (Element) node;
  +                    if (eName.equals(child.getTagName()))
  +                    {
  +                        break;
  +                    }
  +                    child = null;
  +                }
  +            }
  +            // If we don't find this part of the property in the XML hierarchy
  +            // we add it as a new node
  +            if (child == null && attName == null)
  +            {
  +                child = document.createElement(eName);
  +                element.appendChild(child);
  +            }
  +            element = child;
  +        }
  +
  +        if (attName == null)
  +        {
  +            CharacterData data = document.createTextNode((String) value);
  +            element.appendChild(data);
  +        }
  +        else
  +        {
  +            element.setAttribute(attName, (String) value);
  +        }
  +    }
  +
  +    /**
  +     * Calls super method, and also ensures the underlying {@link Document} is
  +     * modified so changes are persisted when saved.
  +     *
  +     * @param name The name of the property to clear.
  +     */
  +    public void clearProperty(String name)
  +    {
  +        super.clearProperty(name);
  +        clearXmlProperty(name);
  +        possiblySave();
  +    }
  +
  +    private void clearXmlProperty(String name)
  +    {
  +        String[] nodes = StringUtils.split(name, NODE_DELIMITER);
  +        String attName = null;
  +        Element element = null;
  +        Element child = document.getDocumentElement();
  +        for (int i = 0; i < nodes.length; i++)
  +        {
  +            element = child;
  +            String eName = nodes[i];
  +            int index = eName.indexOf(ATTRIB_START_MARKER);
  +            if (index > -1)
  +            {
  +                attName = eName.substring(index + ATTRIB_START_MARKER.length(), eName.length() - 1);
  +                eName = eName.substring(0, index);
  +            }
  +
  +            NodeList list = element.getChildNodes();
  +            for (int j = 0; j < list.getLength(); j++) {
  +                Node node = list.item(j);
  +                if (node instanceof Element)
  +                {
  +                    child = (Element) node;
  +                    if (eName.equals(child.getTagName()))
  +                    {
  +                        break;
  +                    }
  +                    child = null;
  +                }
  +            }
  +            if (child == null)
  +            {
  +                return;
  +            }
  +        }
  +
  +        if (attName == null)
  +        {
  +            element.removeChild(child);
  +        }
  +        else
  +        {
  +            child.removeAttribute(attName);
  +        }
  +    }
  +
  +    /**
  +     * Save the configuration if the automatic persistence is enabled.
  +     */
  +    private void possiblySave()
  +    {
  +        if (autoSave)
  +        {
  +            try
  +            {
  +                save();
  +            }
  +            catch (ConfigurationException ce)
  +            {
  +                throw new ConfigurationRuntimeException("Failed to auto-save", ce);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * If true, changes are automatically persisted.
  +     *
  +     * @param autoSave
  +     */
  +    public void setAutoSave(boolean autoSave)
  +    {
  +        this.autoSave = autoSave;
  +    }
  +
  +    public synchronized void save() throws ConfigurationException
  +    {
  +        FileWriter writer = null;
  +        try
  +        {
  +            writer = new FileWriter(getFile());
  +            writer.write(toString());
  +        }
  +        catch (IOException ioe){
  +        	throw new ConfigurationException("Could not save to " + getFile());
  +        }
  +        finally
  +        {
  +        	try
  +            {
  +                if (writer != null)
  +                {
  +                    writer.close();
  +                }
  +        	}
  +        	catch (IOException ioe)
  +            {
  +        		throw new ConfigurationException(ioe);
  +        	}
  +        }
  +    }
  +
  +    /**
  +     * Returns the file.
  +     *
  +     * @return File
  +     */
  +    public File getFile()
  +    {
  +        return ConfigurationUtils.constructFile(getBasePath(), getFileName());
  +    }
  +
  +    /**
  +     * Sets the file.
  +     *
  +     * @param file The file to set
  +     */
  +    public void setFile(File file)
  +    {
  +        this.fileName = file.getAbsolutePath();
  +    }
  +
  +    public void setFileName(String fileName)
  +    {
  +        this.fileName = fileName;
  +    }
  +
  +    /**
  +     * Returns the fileName.
  +     * 
  +     * @return String
  +     */
  +    public String getFileName()
  +    {
  +        return fileName;
  +    }
  +
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        toXML(document, buffer);
  +    	return buffer.toString();
  +    }
  +
  +    private void toXML(Node element, StringBuffer buffer)
  +	{
  +    	NodeList nodeList = element.getChildNodes();
  +    	for (int i = 0; i < nodeList.getLength(); i++)
  +        {
  +    		Node node = nodeList.item(i);
  +    		if (node instanceof Element)
  +            {
  +    			buffer.append("<" + node.getNodeName());
  +                if (node.hasAttributes())
  +                {
  +                	NamedNodeMap map = node.getAttributes();
  +                    for (int j = 0; j < map.getLength(); j++)
  +                    {
  +                    	Attr attr = (Attr) map.item(j);
  +                        buffer.append(" " + attr.getName());
  +                        buffer.append("=\"" + attr.getValue() + "\"");
  +                    }
  +                }
  +                buffer.append(">");
  +    			toXML(node, buffer);
  +    			buffer.append("</" + node.getNodeName() + ">");
  +    		}
  +    		else if (node instanceof CharacterData)
  +    		{
  +    			CharacterData data = (CharacterData) node;
  +    			buffer.append(data.getData());
  +    		}
  +    	}
  +    }
   }
  
  
  
  1.1                  jakarta-commons/configuration/src/java/org/apache/commons/configuration/HierarchicalXMLConfiguration.java
  
  Index: HierarchicalXMLConfiguration.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import org.w3c.dom.Attr;
  import org.w3c.dom.CharacterData;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.NodeList;
  
  /**
   * A specialized hierarchical configuration class that is able to parse
   * XML documents.
   *
   * <p>The parsed document will be stored keeping its structure. The
   * contained properties can be accessed using all methods supported by
   * the base class <code>HierarchicalConfiguration</code>.
   *
   * @since commons-configuration 1.0
   *
   * @author J&ouml;rg Schaible
   * @author <a href="mailto:oliver.heger@t-online.de">Oliver Heger</a>
   * @version $Revision: 1.1 $, $Date: 2004/07/12 12:14:38 $
   */
  public class HierarchicalXMLConfiguration extends HierarchicalConfiguration implements BasePathLoader
  {
      /** Stores the file name of the document to be parsed.*/
      private String file;
  
      /** Stores the base path of this configuration.*/
      private String basePath;
  
  
      /**
       * Constructs a HierarchicalXMLConfiguration.
       */
      public HierarchicalXMLConfiguration()
      {
          super();
      }
  
      /**
       * Returns the name of the file to be parsed by this object.
       * @return the file to be parsed
       */
      public String getFileName()
      {
          return file;
      }
  
      /**
       * Sets the name of the file to be parsed by this object.
       * @param file the file to be parsed
       */
      public void setFileName(String file)
      {
          this.file = file;
      }
  
      /**
       * Returns the base path.
       * @return the base path
       */
      public String getBasePath()
      {
          return basePath;
      }
  
      /**
       * Allows to set a base path. Relative file names are resolved based on
       * this path.
       * @param path the base path; this can be a URL or a file path
       */
      public void setBasePath(String path)
      {
          basePath = path;
      }
  
      /**
       * Loads and parses an XML document. The file to be loaded must have
       * been specified before.
       * @throws ConfigurationException Thrown if an error occurs
       */
      public void load() throws ConfigurationException
      {
          try
          {
              load(ConfigurationUtils.getURL(getBasePath(), getFileName()));
          }
          catch (MalformedURLException mue)
          {
              throw new ConfigurationException("Could not load from " + getBasePath() + ", " + getFileName(), mue);
          }
      }
  
      /**
       * Loads and parses the specified XML document.
       * @param url the URL to the XML document
       *
       * @throws ConfigurationException Thrown if an error occurs
       */
      public void load(URL url) throws ConfigurationException
      {
          try
          {
              DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
              initProperties(builder.parse(url.toExternalForm()));
          }
          catch (Exception e)
          {
              throw new ConfigurationException("Could not load from " + url);
          }
      }
  
      /**
       * Initializes this configuration from an XML document.
       *
       * @param document the document to be parsed
       */
      public void initProperties(Document document)
      {
          constructHierarchy(getRoot(), document.getDocumentElement());
      }
  
      /**
       * Helper method for building the internal storage hierarchy. The XML
       * elements are transformed into node objects.
       *
       * @param node the actual node
       * @param element the actual XML element
       */
      private void constructHierarchy(Node node, Element element)
      {
          StringBuffer buffer = new StringBuffer();
          NodeList list = element.getChildNodes();
          for (int i = 0; i < list.getLength(); i++)
          {
              org.w3c.dom.Node w3cNode = list.item(i);
              if (w3cNode instanceof Element)
              {
                  Element child = (Element) w3cNode;
                  Node childNode = new Node(child.getTagName());
                  constructHierarchy(childNode, child);
                  node.addChild(childNode);
                  processAttributes(childNode, child);
              }
              else if (w3cNode instanceof CharacterData)
              {
                  CharacterData data = (CharacterData) w3cNode;
                  buffer.append(data.getData());
              }
          }
          String text = buffer.toString().trim();
          if (text.length() > 0)
          {
              node.setValue(text);
          }
      }
  
      /**
       * Helper method for constructing node objects for the attributes of the
       * given XML element.
       *
       * @param node the actual node
       * @param element the actual XML element
       */
      private void processAttributes(Node node, Element element)
      {
          NamedNodeMap attributes = element.getAttributes();
          for (int i = 0; i < attributes.getLength(); ++i)
          {
              org.w3c.dom.Node w3cNode = attributes.item(i);
              if (w3cNode instanceof Attr)
              {
                  Attr attr = (Attr) w3cNode;
                  Node child =
                      new Node(
                          ConfigurationKey.constructAttributeKey(attr.getName()));
                  child.setValue(attr.getValue());
                  node.addChild(child);
              }
          }
      }
  }
  
  
  
  1.7       +6 -18     jakarta-commons/configuration/src/test/org/apache/commons/configuration/NonStringTestHolder.java
  
  Index: NonStringTestHolder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/NonStringTestHolder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NonStringTestHolder.java	21 Jun 2004 09:58:54 -0000	1.6
  +++ NonStringTestHolder.java	12 Jul 2004 12:14:38 -0000	1.7
  @@ -16,7 +16,6 @@
   
   package org.apache.commons.configuration;
   
  -import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
   
  @@ -32,6 +31,11 @@
   {
       private Configuration configuration;
   
  +    public void setConfiguration(Configuration configuration)
  +    {
  +        this.configuration = configuration;
  +    }
  +
       public void testBoolean() throws Exception
       {
           boolean booleanValue = configuration.getBoolean("test.boolean");
  @@ -150,22 +154,6 @@
       public void testIsEmpty() throws Exception
       {
           Assert.assertTrue("Configuration should not be empty", !configuration.isEmpty());
  -    }
  -
  -    /**
  -     * @return
  -     */
  -    public Configuration getConfiguration()
  -    {
  -        return configuration;
  -    }
  -
  -    /**
  -     * @param configuration
  -     */
  -    public void setConfiguration(Configuration configuration)
  -    {
  -        this.configuration = configuration;
       }
   
   }
  
  
  
  1.9       +16 -16    jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
  
  Index: TestCompositeConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestCompositeConfiguration.java	4 Jun 2004 12:58:53 -0000	1.8
  +++ TestCompositeConfiguration.java	12 Jul 2004 12:14:38 -0000	1.9
  @@ -33,7 +33,7 @@
   {
       protected BasePropertiesConfiguration conf1;
       protected BasePropertiesConfiguration conf2;
  -    protected DOM4JConfiguration dom4jConf;
  +    protected XMLConfiguration xmlConf;
       protected CompositeConfiguration cc;
   
       /** The File that we test with */
  @@ -46,7 +46,7 @@
           cc = new CompositeConfiguration();
           conf1 = new PropertiesConfiguration(testProperties);
           conf2 = new PropertiesConfiguration(testProperties2);
  -        dom4jConf = new DOM4JConfiguration(new File(testPropertiesXML));
  +        xmlConf = new XMLConfiguration(new File(testPropertiesXML));
       }
   
       public void testAddRemoveConfigurations() throws Exception
  @@ -118,13 +118,13 @@
       public void testMultipleTypesOfConfigs() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           assertEquals("Make sure we get the property from conf1 first", 1, cc.getInt("test.short"));
           cc.clear();
   
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           cc.addConfiguration(conf1);
  -        assertEquals("Make sure we get the property from dom4j", 8, cc.getInt("test.short"));
  +        assertEquals("Make sure we get the property from xml", 8, cc.getInt("test.short"));
       }
   
       /**
  @@ -133,7 +133,7 @@
       public void testPropertyExistsInOnlyOneConfig() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           assertEquals("value", cc.getString("element"));
       }
   
  @@ -143,7 +143,7 @@
       public void testDefaultValueWhenKeyMissing() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           assertEquals("default", cc.getString("bogus", "default"));
           assertTrue(1.4 == cc.getDouble("bogus", 1.4));
           assertTrue(1.4 == cc.getDouble("bogus", 1.4));
  @@ -155,9 +155,9 @@
       public void testGettingConfiguration() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           assertEquals(PropertiesConfiguration.class, cc.getConfiguration(0).getClass());
  -        assertEquals(DOM4JConfiguration.class, cc.getConfiguration(1).getClass());
  +        assertEquals(XMLConfiguration.class, cc.getConfiguration(1).getClass());
       }
   
       /**
  @@ -166,7 +166,7 @@
       public void testClearingProperty() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           cc.clearProperty("test.short");
           assertTrue("Make sure test.short is gone!", !cc.containsKey("test.short"));
       }
  @@ -178,7 +178,7 @@
       public void testAddingProperty() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
   
           String[] values = cc.getStringArray("test.short");
   
  @@ -200,7 +200,7 @@
       public void testSettingMissingProperty() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
           cc.setProperty("my.new.property", "supernew");
           assertEquals("supernew", cc.getString("my.new.property"));
       }
  @@ -211,7 +211,7 @@
       public void testGettingSubset() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
   
           Configuration subset = null;
           subset = cc.subset("test");
  @@ -245,7 +245,7 @@
       public void testList() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
   
           List packages = cc.getList("packages");
           // we should get 3 packages here
  @@ -266,7 +266,7 @@
       public void testStringArray() throws Exception
       {
           cc.addConfiguration(conf1);
  -        cc.addConfiguration(dom4jConf);
  +        cc.addConfiguration(xmlConf);
   
           String[] packages = cc.getStringArray("packages");
           // we should get 3 packages here
  
  
  
  1.12      +34 -52    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestConfigurationFactory.java	2 Jun 2004 16:42:25 -0000	1.11
  +++ TestConfigurationFactory.java	12 Jul 2004 12:14:38 -0000	1.12
  @@ -1,5 +1,3 @@
  -package org.apache.commons.configuration;
  -
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
    *
  @@ -16,6 +14,8 @@
    * limitations under the License.
    */
   
  +package org.apache.commons.configuration;
  +
   import java.io.File;
   import java.util.Collection;
   
  @@ -51,32 +51,29 @@
   
       private Configuration configuration;
       private CompositeConfiguration compositeConfiguration;
  -    private ConfigurationFactory configurationFactory;
  +    private ConfigurationFactory factory;
   
       public void setUp() throws Exception
       {
           System.setProperty("java.naming.factory.initial","org.apache.commons.configuration.MockStaticMemoryInitialContextFactory");
  -        configurationFactory = new ConfigurationFactory();
  +        factory = new ConfigurationFactory();
       }
   
       public void testJNDI()
       {
  -        
  -        
           JNDIConfiguration jndiConfiguration = new JNDIConfiguration();
  -        jndiConfiguration.setPrefix("");
           Object o = jndiConfiguration.getProperty("test.boolean");
           assertNotNull(o);
           assertEquals("true",o.toString());
  -
       }
  +
       public void testLoadingConfiguration() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  +        factory.setConfigurationFileName(
               testDigesterFile.toString());
   
           compositeConfiguration =
  -            (CompositeConfiguration) configurationFactory.getConfiguration();
  +            (CompositeConfiguration) factory.getConfiguration();
   
           assertEquals(
               "Verify how many configs",
  @@ -109,28 +106,25 @@
   
       public void testLoadingConfigurationReverseOrder() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  +        factory.setConfigurationFileName(
               testDigesterFileReverseOrder.toString());
   
  -        configuration = configurationFactory.getConfiguration();
  +        configuration = factory.getConfiguration();
   
           assertEquals("8", configuration.getProperty("test.short"));
   
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterFile.toString());
  +        factory.setConfigurationFileName(testDigesterFile.toString());
   
  -        configuration = configurationFactory.getConfiguration();
  +        configuration = factory.getConfiguration();
           assertEquals("1", configuration.getProperty("test.short"));
       }
   
       public void testLoadingConfigurationWithRulesXML() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterFile.toString());
  -        configurationFactory.setDigesterRules(digesterRules.toURL());
  +        factory.setConfigurationFileName(testDigesterFile.toString());
  +        factory.setDigesterRules(digesterRules.toURL());
   
  -        compositeConfiguration =
  -            (CompositeConfiguration) configurationFactory.getConfiguration();
  +        compositeConfiguration = (CompositeConfiguration) factory.getConfiguration();
   
           assertEquals(
               "Verify how many configs",
  @@ -168,50 +162,44 @@
   
       public void testLoadingConfigurationNamespaceAware() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterFileNamespaceAware.toString());
  -        //configurationFactory.setDigesterRules(digesterRules.toURL());
  -        configurationFactory.setDigesterRuleNamespaceURI("namespace-one");
  +        factory.setConfigurationFileName(testDigesterFileNamespaceAware.toString());
  +        //factory.setDigesterRules(digesterRules.toURL());
  +        factory.setDigesterRuleNamespaceURI("namespace-one");
   
           checkCompositeConfiguration();
       }
   
       public void testLoadingConfigurationBasePath() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterFileBasePath.toString());
  +        factory.setConfigurationFileName(testDigesterFileBasePath.toString());
   
  -        configurationFactory.setBasePath(testBasePath);
  +        factory.setBasePath(testBasePath);
   
  -        //configurationFactory.setDigesterRules(digesterRules.toURL());
  -        //configurationFactory.setDigesterRuleNamespaceURI("namespace-one");
  +        //factory.setDigesterRules(digesterRules.toURL());
  +        //factory.setDigesterRuleNamespaceURI("namespace-one");
   
           checkCompositeConfiguration();
       }
   
       public void testLoadingAdditional() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterFileEnhanced.toString());
  -        configurationFactory.setBasePath(null);
  +        factory.setConfigurationFileName(testDigesterFileEnhanced.toString());
  +        factory.setBasePath(null);
           checkUnionConfig();
       }
   
       public void testLoadingURL() throws Exception
       {
  -        configurationFactory.setConfigurationURL(
  -            testDigesterFileEnhanced.toURL());
  +        factory.setConfigurationURL(testDigesterFileEnhanced.toURL());
           checkUnionConfig();
       }
   
  -    public void testThrowingConfigurationInitializationException()
  -        throws Exception
  +    public void testThrowingConfigurationInitializationException() throws Exception
       {
  -        configurationFactory.setConfigurationFileName(
  -            testDigesterBadXML.toString());
  +        factory.setConfigurationFileName(testDigesterBadXML.toString());
           try
           {
  -            configurationFactory.getConfiguration();
  +            factory.getConfiguration();
               fail("Should have throw an Exception");
           }
           catch (ConfigurationException cle)
  @@ -224,18 +212,16 @@
       public void testAllConfiguration() throws Exception
       {
   
  -        configurationFactory.setConfigurationURL(
  -            testDigesterFileComplete.toURL());
  -        Configuration config = configurationFactory.getConfiguration();
  +        factory.setConfigurationURL(testDigesterFileComplete.toURL());
  +        Configuration config = factory.getConfiguration();
           assertFalse(config.isEmpty());
           assertTrue(config instanceof CompositeConfiguration);
           CompositeConfiguration cc = (CompositeConfiguration)config;
           assertTrue(cc.getNumberOfConfigurations()>1);
           // Currently fails, should be 4?  Only 2?
  -        //assertEquals(4,cc.getNumberOfConfigurations());
  +        //assertEquals(4, cc.getNumberOfConfigurations());
   
  -        assertNotNull(
  -            config.getProperty("tables.table(0).fields.field(2).name"));
  +        assertNotNull(config.getProperty("tables.table(0).fields.field(2).name"));
           assertNotNull(config.getProperty("element2.subelement.subsubelement"));
           assertNotNull(config.getProperty("mail.account.user"));
                   
  @@ -245,13 +231,11 @@
           Configuration subset = config.subset("test");
           assertNotNull(subset.getProperty("onlyinjndi"));
           assertTrue(subset.getBoolean("onlyinjndi"));
  -        
       }
   
       private void checkUnionConfig() throws Exception
       {
  -        compositeConfiguration =
  -            (CompositeConfiguration) configurationFactory.getConfiguration();
  +        compositeConfiguration = (CompositeConfiguration) factory.getConfiguration();
           assertEquals(
               "Verify how many configs",
               3,
  @@ -300,8 +284,7 @@
   
       private void checkCompositeConfiguration() throws Exception
       {
  -        compositeConfiguration =
  -            (CompositeConfiguration) configurationFactory.getConfiguration();
  +        compositeConfiguration = (CompositeConfiguration) factory.getConfiguration();
   
           assertEquals(
               "Verify how many configs",
  @@ -330,6 +313,5 @@
           Object property = compositeConfiguration.getProperty(
               "element2.subelement.subsubelement");
           assertNull("Should have returned a null",property);
  -        
       }
   }
  
  
  
  1.4       +6 -7      jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java
  
  Index: TestHierarchicalConfigurationXMLReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHierarchicalConfigurationXMLReader.java	27 Feb 2004 17:41:34 -0000	1.3
  +++ TestHierarchicalConfigurationXMLReader.java	12 Jul 2004 12:14:38 -0000	1.4
  @@ -1,5 +1,3 @@
  -package org.apache.commons.configuration;
  -
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
    *
  @@ -16,6 +14,8 @@
    * limitations under the License.
    */
   
  +package org.apache.commons.configuration;
  +
   import java.util.Iterator;
   import java.util.List;
   
  @@ -33,15 +33,14 @@
    */
   public class TestHierarchicalConfigurationXMLReader extends TestCase
   {
  -    private static final String TEST_FILE =
  -    "conf/testHierarchicalDOM4JConfiguration.xml";
  +    private static final String TEST_FILE = "conf/testHierarchicalXMLConfiguration.xml";
       
       private HierarchicalConfigurationXMLReader parser;
       
       protected void setUp() throws Exception
       {
  -        HierarchicalDOM4JConfiguration config =
  -        new HierarchicalDOM4JConfiguration();
  +        HierarchicalXMLConfiguration config =
  +        new HierarchicalXMLConfiguration();
           config.setFileName(TEST_FILE);
           config.load();
           parser = new HierarchicalConfigurationXMLReader(config);
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java
  
  Index: TestHierarchicalXMLConfiguration.java
  ===================================================================
  package org.apache.commons.configuration;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
   
  import java.io.File;
  import java.util.Collection;
  
  import junit.framework.TestCase;
  
  /**
   * Test class for HierarchicalXMLConfiguration,
   *
   * @version $Id: TestHierarchicalXMLConfiguration.java,v 1.1 2004/07/12 12:14:38 ebourg Exp $
   */
  public class TestHierarchicalXMLConfiguration extends TestCase
  {
      private static final String TEST_DIR = "conf";
      
      private static final String TEST_FILENAME = "testHierarchicalXMLConfiguration.xml";
      
      private static final String TEST_FILE = TEST_DIR + File.separator + TEST_FILENAME;
      
      private HierarchicalXMLConfiguration config;
      
      protected void setUp() throws Exception
      {
          config = new HierarchicalXMLConfiguration();
      }
  
      private void configTest(HierarchicalXMLConfiguration config)
      {
          assertEquals(1, config.getMaxIndex("tables.table"));
          assertEquals("system", config.getProperty("tables.table(0)[@tableType]"));
          assertEquals("application", config.getProperty("tables.table(1)[@tableType]"));
          
          assertEquals("users", config.getProperty("tables.table(0).name"));
          assertEquals("documents", config.getProperty("tables.table(1).name"));
          
          Object prop = config.getProperty("tables.table.fields.field.name");
          assertTrue(prop instanceof Collection);
          assertEquals(10, ((Collection) prop).size());
          
          prop = config.getProperty("tables.table(0).fields.field.type");
          assertTrue(prop instanceof Collection);
          assertEquals(5, ((Collection) prop).size());
          
          prop = config.getProperty("tables.table(1).fields.field.type");
          assertTrue(prop instanceof Collection);
          assertEquals(5, ((Collection) prop).size());
      }
      
      public void testGetProperty() throws Exception
      {
          config.setFileName(TEST_FILE);
          config.load();
  
          configTest(config);
      }
      
      public void testLoadURL() throws Exception
      {
          config.load(new File(TEST_FILE).getAbsoluteFile().toURL());
          configTest(config);
      }
      
      public void testLoadBasePath1() throws Exception
      {
          config.setBasePath(TEST_DIR);
          config.setFileName(TEST_FILENAME);
          config.load();
          configTest(config);
      }
      
      public void testLoadBasePath2() throws Exception
      {
          config.setBasePath(new File(TEST_FILE).getAbsoluteFile().toURL().toString());
          config.setFileName(TEST_FILENAME);
          config.load();
          configTest(config);
      }
  }
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
  
  Index: TestXMLConfiguration.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.configuration;
  
  import java.io.File;
  
  import junit.framework.TestCase;
  
  /**
   * test for loading and saving xml properties files
   *
   * @version $Id: TestXMLConfiguration.java,v 1.1 2004/07/12 12:14:38 ebourg Exp $
   */
  public class TestXMLConfiguration extends TestCase
  {
      /** The File that we test with */
      private String testProperties = new File("conf/test.xml").getAbsolutePath();
      private String testBasePath = new File("conf").getAbsolutePath();
      private XMLConfiguration conf;
  
      protected void setUp() throws Exception
      {
          conf = new XMLConfiguration(new File(testProperties));
      }
  
      public void testGetProperty() throws Exception
      {
          assertEquals("value", conf.getProperty("element"));
      }
  
      public void testGetComplexProperty() throws Exception
      {
          assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
      }
  
      public void testSettingFileNames() throws Exception
      {
          conf = new XMLConfiguration();
          conf.setFileName(testProperties);
          assertEquals(testProperties.toString(), conf.getFileName());
  
          conf.setBasePath(testBasePath);
          conf.setFileName("hello.xml");
          assertEquals("hello.xml", conf.getFileName());
          assertEquals(testBasePath.toString(), conf.getBasePath());
          assertEquals(new File(testBasePath, "hello.xml"), conf.getFile());
  
          conf.setBasePath(testBasePath);
          conf.setFileName("/subdir/hello.xml");
          assertEquals("/subdir/hello.xml", conf.getFileName());
          assertEquals(testBasePath.toString(), conf.getBasePath());
          assertEquals(new File(testBasePath, "/subdir/hello.xml"), conf.getFile());
      }
  
      public void testLoad() throws Exception
      {
          conf = new XMLConfiguration();
          conf.setFileName(testProperties);
          conf.load();
  
          assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
      }
      
      public void testLoadWithBasePath() throws Exception
      {
          conf = new XMLConfiguration();
          
          conf.setFileName("test.xml");
          conf.setBasePath(testBasePath);
          conf.load();
  
          assertEquals("I'm complex!", conf.getProperty("element2.subelement.subsubelement"));
      }
  }
  
  
  
  1.24      +7 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- changes.xml	21 Jun 2004 17:45:29 -0000	1.23
  +++ changes.xml	12 Jul 2004 12:14:38 -0000	1.24
  @@ -7,6 +7,13 @@
   
     <body>
       <release version="1.0rc1" date="2004-06-??">
  +      <action dev="ebourg" type="update">
  +        Removed the DOM4J implementations in favor of the DOM ones.
  +        DOMConfiguration has been renamed to XMLConfiguration, and
  +        HierarchicalDOMConfiguration to HierarchicalXMLConfiguration. The
  +        elements parsed by the ConfigurationFactory have been changed
  +        accordingly.
  +      </action>
         <action dev="ebourg" type="add">
           Added a save() method to PropertiesConfiguration and save(Writer out),
           save(OutputStream out), save(OutputStream out, String encoding) to
  
  
  
  1.3       +2 -2      jakarta-commons/configuration/xdocs/howto_configurationfactory.xml
  
  Index: howto_configurationfactory.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/howto_configurationfactory.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- howto_configurationfactory.xml	28 Mar 2004 19:58:30 -0000	1.2
  +++ howto_configurationfactory.xml	12 Jul 2004 12:14:38 -0000	1.3
  @@ -164,7 +164,7 @@
   			<p>
   				To make this XML document part of our global configuration we
   				have to modify our configuration definition file to also include
  -				the new file. For XML documents the element <code>dom4j</code>
  +				the new file. For XML documents the element <code>xml</code>
   				can be used so that we have now:
   			</p>
      			<source>
  @@ -173,7 +173,7 @@
   
   <configuration>
     <properties fileName="usergui.properties"/>
  -  <dom4j fileName="gui.xml"/>
  +  <xml fileName="gui.xml"/>
   </configuration>
   ]]>
   			</source>
  
  
  
  1.4       +18 -18    jakarta-commons/configuration/xdocs/howto_xml.xml
  
  Index: howto_xml.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/howto_xml.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- howto_xml.xml	22 Jun 2004 10:07:57 -0000	1.3
  +++ howto_xml.xml	12 Jul 2004 12:14:38 -0000	1.4
  @@ -103,13 +103,13 @@
   
   <configuration>
     <properties fileName="usergui.properties"/>
  -  <dom4j fileName="gui.xml"/>
  -  <dom4j fileName="tables.xml"/>
  +  <xml fileName="gui.xml"/>
  +  <xml fileName="tables.xml"/>
   </configuration>
   ]]>
   			</source>
   			<p>
  -				The additional <code>dom4j</code> element causes the document
  +				The additional <code>xml</code> element causes the document
   				with the table definitions to be loaded. When we now want to
   				read some of the properties we face a problem: the syntax for
   				constructing configuration keys we learned so far is not
  @@ -177,16 +177,16 @@
   
   <configuration>
     <properties fileName="usergui.properties"/>
  -  <dom4j fileName="gui.xml"/>
  -  <hierarchicalDom4j fileName="tables.xml"/>
  +  <xml fileName="gui.xml"/>
  +  <hierarchicalXml fileName="tables.xml"/>
   </configuration>
   ]]>
   			</source>
   			<p>
  -				Note that one <code>dom4j</code> element was replaced by a
  -				<code>hierarchicalDom4j</code> element. This element tells the configuration
  +				Note that one <code>xml</code> element was replaced by a
  +				<code>hierarchicalXml</code> element. This element tells the configuration
   				factory that not the default class for processing XML documents
  -				should be used, but the class <code>HierarchicalDOM4JConfiguration</code>.
  +				should be used, but the class <code>HierarchicalXMLConfiguration</code>.
   				As the name implies this class is capable of saving the
   				hierarchy of XML documents thus keeping their structure.
   			</p>
  @@ -350,12 +350,12 @@
   <configuration>
     <override>
       <properties fileName="usergui.properties"/>
  -    <dom4j fileName="gui.xml"/>
  +    <xml fileName="gui.xml"/>
     </override>
     
     <additional>
  -    <hierarchicalDom4j fileName="tables.xml"/>
  -    <hierarchicalDom4j fileName="tasktables.xml" at="tables"/>
  +    <hierarchicalXml fileName="tables.xml"/>
  +    <hierarchicalXml fileName="tasktables.xml" at="tables"/>
     </additional>
   </configuration>
   ]]>
  @@ -378,7 +378,7 @@
   		<p>
   			It is the <code>additonal</code> section that introduces a new behaviour.
   			All configuration sources listed here are combined to a union configuration.
  -			In our example we have put two <code>dom4j</code> elements in this area
  +			In our example we have put two <code>xml</code> elements in this area
   			that load the available files with database table definitions. The syntax
   			of elements in the <code>additional</code> section is analogous to the
   			syntax described so far. The only difference is an additionally supported
  @@ -877,13 +877,13 @@
   <configuration>
     <override>
       <properties fileName="usergui.properties"/>
  -    <dom4j fileName="gui.xml"/>
  +    <xml fileName="gui.xml"/>
     </override>
     
     <additional>
  -    <hierarchicalDom4j fileName="tables.xml"/>
  -    <hierarchicalDom4j fileName="tasktables.xml" at="tables"/>
  -    <hierarchicalDom4j fileName="connection.xml"/>
  +    <hierarchicalXml fileName="tables.xml"/>
  +    <hierarchicalXml fileName="tasktables.xml" at="tables"/>
  +    <hierarchicalXml fileName="connection.xml"/>
     </additional>
   </configuration>
   ]]>
  @@ -929,8 +929,8 @@
   						The problem here is the loss of information concerning the
   						structure of the properties (as was explained in an earlier secion). 
   						So if you read a configuration source
  -						using the <code>dom4j</code> element rather than the
  -						<code>hierarchicalDom4j</code> element, XML documents
  +						using the <code>xml</code> element rather than the
  +						<code>hierarchicalXml</code> element, XML documents
   						generated by <code>ConfigurationXMLDocument</code> may
   						look wired; the same is true for <code>properties</code>
   						elements.
  
  
  
  1.4       +15 -17    jakarta-commons/configuration/xdocs/overview.xml
  
  Index: overview.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/overview.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- overview.xml	30 Jan 2004 14:05:00 -0000	1.3
  +++ overview.xml	12 Jul 2004 12:14:38 -0000	1.4
  @@ -18,31 +18,31 @@
         <subsection name="Configuration Sources">
         <p>
           Currently there are quite a number of different sources of Configuration objects.  But,
  -        by just using a Configuration object versus a specific type like XmlConfiguration or
  +        by just using a Configuration object versus a specific type like XMLConfiguration or
           JNDIConfiguration, you are sheltered from the mechanics of actually retrieving the 
  -        configuration values.  These various sources include:
  +        configuration values. These various sources include:
           <ul>
             <li>
                 <strong>PropertiesConfiguration</strong>
                 Loads configuration values from a properties file.
             </li>
             <li>
  -              <strong>BasePropertiesConfiguration</strong>
  +              <strong>BaseConfiguration</strong>
                 An in-memory method of populating a Configuration object.
             </li>
             <li>
  -              <strong>ConfigurationConverter</strong>
  -              Takes an o.a.c.collections.ExtendedProperties and converts it to a Configuration
  -              object.
  +              <strong>XMLConfiguration</strong>
  +              Takes values from an XML document.
             </li>
             <li>
  -              <strong>DOM4JConfiguration</strong>
  -              Takes values from an XML documentation using DOM4J.
  +              <strong>JNDIConfiguration</strong>
  +              Using a key in the JNDI tree, can retrieve values as configuration properties.
             </li>
             <li>
  -              <strong>JNDIConfiguration</strong>
  -              Using a key in the JNDI tree, can retrieve values as configuration properties.              
  -          </li>          
  +              <strong>ConfigurationConverter</strong>
  +              Takes a java.util.Properties or an o.a.c.collections.ExtendedProperties
  +              and converts it to a Configuration object.
  +          </li>
          </ul>
           
         </p>
  @@ -55,8 +55,6 @@
           this is a very rigid way of doing things.  Instead, with the CompositeConfiguration you can
           provide many different ways of setting up a configuration.  You can either do it manually (see
           JUnit testcase "TestCompositeConfiguration.java", or via the ConfigurationFactory class.
  -              
  -              
         </p>
         <p>
           Using the ConfigurationFactory, (see the Junit testcase "TestConfigurationFactory.java") you load
  @@ -69,13 +67,13 @@
   <configuration>
     <jndi className="org.apache.commons.configuration.JNDIConfiguration" prefix="java:comp/env"/>
     <properties className="org.apache.commons.configuration.PropertiesConfiguration" fileName="conf/test.properties"/>
  -  <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" fileName="conf/test.xml"/>
  +  <xml className="org.apache.commons.configuration.XMLConfiguration" fileName="conf/test.xml"/>
   </configuration>
   ]]>   
           </source>
           
           What this says is that we are loading up all JNDI values under java:comp/env key, as well 
  -        as a properties file in conf/test.properties as well as a dom4j XML file in conf/test.xml.  
  +        as a properties file in conf/test.properties as well as a XML file in conf/test.xml.
           Please inspect the test cases and the files in the conf/ directory for more information on how
           to structure your configuration xml file..
         </p>
  @@ -91,7 +89,7 @@
         <p>
         Configuration is done by taking the configuration XML file and using included Digester rules,
         parsing the individual configurations.  Make sure to include the various dependencies required for
  -      each type of configuration!  If you have an XML file, you'll need dom4j.jar for instance!
  +      each type of configuration!
         </p>
         <subsection name="Classic Properties File">
           <source>
  @@ -106,7 +104,7 @@
         <subsection name="XML Properties File">
           <source>
   <![CDATA[       
  -  <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" fileName="conf/test.xml"/>
  +  <xml className="org.apache.commons.configuration.XMLConfiguration" fileName="conf/test.xml"/>
   ]]>   
           </source>     
           <p>
  
  
  

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