commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r481592 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/ xdocs/
Date Sat, 02 Dec 2006 18:20:44 GMT
Author: oheger
Date: Sat Dec  2 10:20:43 2006
New Revision: 481592

URL: http://svn.apache.org/viewvc?view=rev&rev=481592
Log:
The subset configuration of a HierarchicalConfiguration now takes its parent configuration
into account for variable interpolation; fix for CONFIGURATION-242

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?view=diff&rev=481592&r1=481591&r2=481592
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
Sat Dec  2 10:20:43 2006
@@ -410,7 +410,15 @@
             return new HierarchicalConfiguration();
         }
 
-        HierarchicalConfiguration result = new HierarchicalConfiguration();
+        final HierarchicalConfiguration parent = this;
+        HierarchicalConfiguration result = new HierarchicalConfiguration()
+        {
+            // Override interpolate to always interpolate on the parent
+            protected Object interpolate(Object value)
+            {
+                return parent.interpolate(value);
+            }
+        };
         CloneVisitor visitor = new CloneVisitor();
 
         for (Iterator it = nodes.iterator(); it.hasNext();)

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?view=diff&rev=481592&r1=481591&r2=481592
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Sat Dec  2 10:20:43 2006
@@ -668,6 +668,26 @@
 		checkContent(copy);
 	}
 
+    /**
+     * Tests interpolation facilities.
+     */
+    public void testInterpolation()
+    {
+        config.addProperty("base.dir", "/home/foo");
+        config.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
+        config.addProperty("test.absolute.dir.dir2", "${base.dir}/path2");
+        config.addProperty("test.absolute.dir.dir3", "${base.dir}/path3");
+
+        Configuration sub = config.subset("test.absolute.dir");
+        for (int i = 1; i < 4; i++)
+        {
+            assertEquals("Wrong interpolation in parent", "/home/foo/path" + i,
+                    config.getString("test.absolute.dir.dir" + i));
+            assertEquals("Wrong interpolation in subnode",
+                    "/home/foo/path" + i, sub.getString("dir" + i));
+        }
+    }
+
 	/**
      * Tests the copy constructor when a null reference is passed.
      */
@@ -679,7 +699,7 @@
 
 	/**
      * Helper method for testing the getKeys(String) method.
-     * 
+     *
      * @param prefix the key to pass into getKeys()
      * @param expected the expected result
      */
@@ -746,7 +766,7 @@
 	/**
      * Checks the content of the passed in configuration object. Used by some
      * tests that copy a configuration.
-     * 
+     *
      * @param c the configuration to check
      */
 	private void checkContent(Configuration c)

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java?view=diff&rev=481592&r1=481591&r2=481592
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
Sat Dec  2 10:20:43 2006
@@ -293,6 +293,27 @@
     }
 
     /**
+     * An additional test for interpolation when the configurationAt() method is
+     * involved.
+     */
+    public void testInterpolationFromConfigurationAt()
+    {
+        parent.addProperty("base.dir", "/home/foo");
+        parent.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
+        parent.addProperty("test.absolute.dir.dir2", "${base.dir}/path2");
+        parent.addProperty("test.absolute.dir.dir3", "${base.dir}/path3");
+
+        Configuration sub = parent.configurationAt("test.absolute.dir");
+        for (int i = 1; i < 4; i++)
+        {
+            assertEquals("Wrong interpolation in parent", "/home/foo/path" + i,
+                    parent.getString("test.absolute.dir.dir" + i));
+            assertEquals("Wrong interpolation in subnode",
+                    "/home/foo/path" + i, sub.getString("dir" + i));
+        }
+    }
+
+    /**
      * Initializes the parent configuration. This method creates the typical
      * structure of tables and fields nodes.
      *

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=481592&r1=481591&r2=481592
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Dec  2 10:20:43 2006
@@ -23,6 +23,13 @@
 
   <body>
     <release version="1.4-dev" date="in SVN">
+      <action dev="oheger" type="update" issue="CONFIGURATION-242">
+        The configuration returned by HierarchicalConfiguration.subset()
+        performed variable interpolation only in the keys that belong to the
+        subset. Now the parent configuration is searched, too, to resolve the
+        value of the referenced property. This is consistent with the way
+        SubnodeConfiguration works.
+      </action>
       <action dev="oheger" type="update" issue="CONFIGURATION-234">
         DefaultConfigurationBuilder now internally uses the standard expression
         engine for hierarchical configurations. So the dependency to Commons



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


Mime
View raw message