Author: oheger
Date: Thu Dec 20 21:16:06 2012
New Revision: 1424706

URL: http://svn.apache.org/viewvc?rev=1424706&view=rev
Log:
XMLBeanDeclaration now also performs interpolation when querying constructor 
arguments.

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

Modified: 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java?rev=1424706&r1=1424705&r2=1424706&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/XMLBeanDeclaration.java
 Thu Dec 20 21:16:06 2012
@@ -538,28 +538,28 @@ public class XMLBeanDeclaration implemen
     }
 
     /**
-     * Checks whether the constructor argument represented by the given
-     * configuration node is a bean declaration.
+     * Helper method for obtaining an attribute of a configuration node.
      *
-     * @param nd the configuration node in question
-     * @return a flag whether this constructor argument is a bean declaration
+     * @param nd the node
+     * @param attr the name of the attribute
+     * @return the string value of this attribute (can be <b>null</b>)
      */
-    private static boolean isBeanDeclarationArgument(ConfigurationNode nd)
+    private String getAttribute(ConfigurationNode nd, String attr)
     {
-        return nd.getAttributes(ATTR_BEAN_CLASS_NAME).isEmpty();
+        List<ConfigurationNode> attributes = nd.getAttributes(attr);
+        return attributes.isEmpty() ? null : String
+                .valueOf(interpolate(attributes.get(0).getValue()));
     }
 
     /**
-     * Helper method for obtaining an attribute of a configuration node.
+     * Checks whether the constructor argument represented by the given
+     * configuration node is a bean declaration.
      *
-     * @param nd the node
-     * @param attr the name of the attribute
-     * @return the string value of this attribute (can be <b>null</b>)
+     * @param nd the configuration node in question
+     * @return a flag whether this constructor argument is a bean declaration
      */
-    private static String getAttribute(ConfigurationNode nd, String attr)
+    private static boolean isBeanDeclarationArgument(ConfigurationNode nd)
     {
-        List<ConfigurationNode> attributes = nd.getAttributes(attr);
-        return attributes.isEmpty() ? null : String.valueOf(attributes.get(0)
-                .getValue());
+        return nd.getAttributes(ATTR_BEAN_CLASS_NAME).isEmpty();
     }
 }

Modified: 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java?rev=1424706&r1=1424705&r2=1424706&view=diff
==============================================================================
--- 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
 (original)
+++ 
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestXMLBeanDeclaration.java
 Thu Dec 20 21:16:06 2012
@@ -467,6 +467,23 @@ public class TestXMLBeanDeclaration
     }
 
     /**
+     * Tests whether interpolation is done on constructor arguments.
+     */
+    @Test
+    public void testGetInterpolatedConstructorArgs()
+    {
+        HierarchicalConfiguration config = new BaseHierarchicalConfiguration();
+        String expectedValue = "ctorArg";
+        config.addProperty("value", expectedValue);
+        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
+        config.addProperty(KEY + ".config-constrarg[@config-value]", 
"${value}");
+        XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
+        Collection<ConstructorArg> args = decl.getConstructorArgs();
+        ConstructorArg arg = args.iterator().next();
+        assertEquals("Wrong interpolated value", expectedValue, 
arg.getValue());
+    }
+
+    /**
      * Initializes a configuration object with a bean declaration. Under the
      * specified key the given properties will be added.
      *


Reply via email to