You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2008/06/23 22:36:37 UTC

svn commit: r670739 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java xdocs/changes.xml

Author: oheger
Date: Mon Jun 23 13:36:37 2008
New Revision: 670739

URL: http://svn.apache.org/viewvc?rev=670739&view=rev
Log:
CONFIGURATION-331: Added a factory method to XMLBeanDeclaration for creating the declarations for complex nested properties.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java?rev=670739&r1=670738&r2=670739&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java Mon Jun 23 13:36:37 2008
@@ -310,8 +310,7 @@
             ConfigurationNode child = (ConfigurationNode) it.next();
             if (!isReservedNode(child))
             {
-                nested.put(child.getName(), new XMLBeanDeclaration(
-                        getConfiguration().configurationAt(child.getName()), child));
+                nested.put(child.getName(), createBeanDeclaration(child));
             }
         }
 
@@ -351,6 +350,26 @@
     }
 
     /**
+     * Creates a new <code>BeanDeclaration</code> for a child node of the
+     * current configuration node. This method is called by
+     * <code>getNestedBeanDeclarations()</code> for all complex sub properties
+     * detected by this method. Derived classes can hook in if they need a
+     * specific initialization. This base implementation creates a
+     * <code>XMLBeanDeclaration</code> that is properly initialized from the
+     * passed in node.
+     *
+     * @param node the child node, for which a <code>BeanDeclaration</code> is
+     *        to be created
+     * @return the <code>BeanDeclaration</code> for this child node
+     * @since 1.6
+     */
+    protected BeanDeclaration createBeanDeclaration(ConfigurationNode node)
+    {
+        return new XMLBeanDeclaration(getConfiguration().configurationAt(
+                node.getName()), node);
+    }
+
+    /**
      * Initializes the internally managed subnode configuration. This method
      * will set some default values for some properties.
      *

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java?rev=670739&r1=670738&r2=670739&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java Mon Jun 23 13:36:37 2008
@@ -19,6 +19,7 @@
 import java.util.Map;
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.SubnodeConfiguration;
 import org.apache.commons.configuration.tree.ConfigurationNode;
 
 import junit.framework.TestCase;
@@ -242,9 +243,10 @@
     }
 
     /**
-     * Tests fetching nested bean declarations.
+     * Creates a configuration with data for testing nested bean declarations.
+     * @return the initialized test configuration
      */
-    public void testGetNestedBeanDeclarations()
+    private HierarchicalConfiguration prepareNestedBeanDeclarations()
     {
         HierarchicalConfiguration config = new HierarchicalConfiguration();
         setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
@@ -256,7 +258,15 @@
                     KEY + '.' + COMPLEX_PROPS[i] + "[@config-class]",
                     COMPLEX_CLASSES[i]);
         }
+        return config;
+    }
 
+    /**
+     * Tests fetching nested bean declarations.
+     */
+    public void testGetNestedBeanDeclarations()
+    {
+        HierarchicalConfiguration config = prepareNestedBeanDeclarations();
         decl = new XMLBeanDeclaration(config, KEY);
         checkProperties(decl, TEST_PROPS, TEST_VALUES);
 
@@ -275,6 +285,31 @@
     }
 
     /**
+     * Tests whether the factory method for creating nested bean declarations
+     * gets called.
+     */
+    public void testGetNestedBeanDeclarationsFactoryMethod()
+    {
+        HierarchicalConfiguration config = prepareNestedBeanDeclarations();
+        decl = new XMLBeanDeclaration(config, KEY)
+        {
+            protected BeanDeclaration createBeanDeclaration(
+                    ConfigurationNode node)
+            {
+                return new XMLBeanDeclarationTestImpl(getConfiguration()
+                        .configurationAt(node.getName()), node);
+            }
+        };
+        Map nested = decl.getNestedBeanDeclarations();
+        for (int i = 0; i < COMPLEX_PROPS.length; i++)
+        {
+            Object d = nested.get(COMPLEX_PROPS[i]);
+            assertTrue("Wrong class for bean declaration: " + d,
+                    d instanceof XMLBeanDeclarationTestImpl);
+        }
+    }
+
+    /**
      * Tests fetching nested bean declarations if none are defined.
      */
     public void testGetNestedBeanDeclarationsEmpty()
@@ -395,4 +430,17 @@
                     props.get(names[i]));
         }
     }
+
+    /**
+     * A helper class used for testing the createBeanDeclaration() factory
+     * method.
+     */
+    private static class XMLBeanDeclarationTestImpl extends XMLBeanDeclaration
+    {
+        public XMLBeanDeclarationTestImpl(SubnodeConfiguration config,
+                ConfigurationNode node)
+        {
+            super(config, node);
+        }
+    }
 }

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=670739&r1=670738&r2=670739&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Mon Jun 23 13:36:37 2008
@@ -23,6 +23,12 @@
 
   <body>
     <release version="1.6" date="in SVN" description="">
+      <action dev="oheger" type="add" issue="CONFIGURATION-331">
+        XMLBeanDeclaration now defines a factory method createBeanDeclaration()
+        for creating the declarations for complex nested properties. This
+        method can be overridden by derived classes for injecting custom
+        BeanDeclaration implementations.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-307">
         XMLConfiguration now supports the xml:space attribute. This attribute
         can be used to preserve whitespace in the content of XML elements.