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 2007/10/27 17:38:16 UTC
svn commit: r589136 - in /commons/proper/configuration/trunk: ./
src/java/org/apache/commons/configuration/
src/test/org/apache/commons/configuration/
Author: oheger
Date: Sat Oct 27 08:38:15 2007
New Revision: 589136
URL: http://svn.apache.org/viewvc?rev=589136&view=rev
Log:
CONFIGURATION-273: Provide a special implementation of interpolatedConfiguration() for hierarchical configurations
Modified:
commons/proper/configuration/trunk/project.xml
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/InterpolationTestHelper.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Modified: commons/proper/configuration/trunk/project.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/project.xml?rev=589136&r1=589135&r2=589136&view=diff
==============================================================================
--- commons/proper/configuration/trunk/project.xml (original)
+++ commons/proper/configuration/trunk/project.xml Sat Oct 27 08:38:15 2007
@@ -551,6 +551,7 @@
<exclude>**/AbstractTestConfigurationEvents.java</exclude>
<exclude>**/AbstractTestFileConfigurationEvents.java</exclude>
<exclude>**/AbstractTestPListEvents.java</exclude>
+ <exclude>**/InterpolationTestHelper.java</exclude>
</excludes>
<resources>
<resource>
Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=589136&r1=589135&r2=589136&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java Sat Oct 27 08:38:15 2007
@@ -90,7 +90,7 @@
* element if there are multiple hits.</p><p>For instance the key
* <code>tables.table(0).name</code> can be used to find out the name of the
* first table. In opposite <code>tables.table.name</code> would return a
- * collection with the names of all available tables. Similarily the key
+ * collection with the names of all available tables. Similarly the key
* <code>tables.table(1).fields.field.name</code> returns a collection with
* the names of all fields of the second table. If another index is added after
* the <code>field</code> element, a single field can be accessed:
@@ -891,6 +891,29 @@
}
/**
+ * Returns a configuration with the same content as this configuration, but
+ * with all variables replaced by their actual values. This implementation
+ * is specific for hierarchical configurations. It clones the current
+ * configuration and runs a specialized visitor on the clone, which performs
+ * interpolation on the single configuration nodes.
+ *
+ * @return a configuration with all variables interpolated
+ * @since 1.5
+ */
+ public Configuration interpolatedConfiguration()
+ {
+ HierarchicalConfiguration c = (HierarchicalConfiguration) clone();
+ c.getRootNode().visit(new ConfigurationNodeVisitorAdapter()
+ {
+ public void visitAfterChildren(ConfigurationNode node)
+ {
+ node.setValue(interpolate(node.getValue()));
+ }
+ });
+ return c;
+ }
+
+ /**
* Helper method for fetching a list of all nodes that are addressed by the
* specified key.
*
@@ -984,7 +1007,7 @@
* Clears the value of the specified node. If the node becomes undefined by
* this operation, it is removed from the hierarchy.
*
- * @param node the node to be cleard
+ * @param node the node to be cleared
* @deprecated Use the method <code>{@link #clearNode(ConfigurationNode)}</code>
* instead
*/
@@ -997,7 +1020,7 @@
* Clears the value of the specified node. If the node becomes undefined by
* this operation, it is removed from the hierarchy.
*
- * @param node the node to be cleard
+ * @param node the node to be cleared
*/
protected void clearNode(ConfigurationNode node)
{
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/InterpolationTestHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/InterpolationTestHelper.java?rev=589136&r1=589135&r2=589136&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/InterpolationTestHelper.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/InterpolationTestHelper.java Sat Oct 27 08:38:15 2007
@@ -216,8 +216,9 @@
* actual values.
*
* @param config the configuration to test
+ * @return the interpolated configuration
*/
- public static void testInterpolatedConfiguration(
+ public static Configuration testInterpolatedConfiguration(
AbstractConfiguration config)
{
config.setProperty("applicationRoot", "/home/applicationRoot");
@@ -249,5 +250,7 @@
.get(1));
Assert.assertEquals("Unresolvable variable not found",
"${unknown.property}", c.getProperty("inttest.interpol"));
+
+ return c;
}
}
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=589136&r1=589135&r2=589136&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java Sat Oct 27 08:38:15 2007
@@ -811,6 +811,91 @@
}
}
+ /**
+ * Basic interpolation tests.
+ */
+ public void testInterpolationBasic()
+ {
+ InterpolationTestHelper.testInterpolation(config);
+ }
+
+ /**
+ * Tests multiple levels of interpolation.
+ */
+ public void testInterpolationMultipleLevels()
+ {
+ InterpolationTestHelper.testMultipleInterpolation(config);
+ }
+
+ /**
+ * Tests an invalid interpolation that causes an endless loop.
+ */
+ public void testInterpolationLoop()
+ {
+ InterpolationTestHelper.testInterpolationLoop(config);
+ }
+
+ /**
+ * Tests interpolation with a subset.
+ */
+ public void testInterpolationSubset()
+ {
+ InterpolationTestHelper.testInterpolationSubset(config);
+ }
+
+ /**
+ * Tests interpolation of a variable, which cannot be resolved.
+ */
+ public void testInterpolationUnknownProperty()
+ {
+ InterpolationTestHelper.testInterpolationUnknownProperty(config);
+ }
+
+ /**
+ * Tests interpolation with system properties.
+ */
+ public void testInterpolationSysProperties()
+ {
+ InterpolationTestHelper.testInterpolationSystemProperties(config);
+ }
+
+ /**
+ * Tests interpolation with constant values.
+ */
+ public void testInterpolationConstants()
+ {
+ InterpolationTestHelper.testInterpolationConstants(config);
+ }
+
+ /**
+ * Tests escaping variables.
+ */
+ public void testInterpolationEscaped()
+ {
+ InterpolationTestHelper.testInterpolationEscaped(config);
+ }
+
+ /**
+ * Tests manipulating the interpolator.
+ */
+ public void testInterpolator()
+ {
+ InterpolationTestHelper.testGetInterpolator(config);
+ }
+
+ /**
+ * Tests obtaining a configuration with all variables substituted.
+ */
+ public void testInterpolatedConfiguration()
+ {
+ HierarchicalConfiguration c = (HierarchicalConfiguration) InterpolationTestHelper
+ .testInterpolatedConfiguration(config);
+
+ // tests whether the hierarchical structure has been maintained
+ config = c;
+ testGetProperty();
+ }
+
/**
* Tests the copy constructor when a null reference is passed.
*/