commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r757108 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/interpol/ test/java/org/apache/commons/configuration2/
Date Sun, 22 Mar 2009 00:00:30 GMT
Author: joehni
Date: Sun Mar 22 00:00:29 2009
New Revision: 757108

URL: http://svn.apache.org/viewvc?rev=757108&view=rev
Log:
Enable local key lookup for SubnodeConfiguration (CONFIGURATION-377).

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java?rev=757108&r1=757107&r2=757108&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubnodeConfiguration.java
Sun Mar 22 00:00:29 2009
@@ -21,6 +21,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.configuration2.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration2.tree.ConfigurationNode;
 
 /**
@@ -323,14 +324,16 @@
     }
 
     /**
-     * Performs interpolation. This implementation will ask the parent
-     * configuration to perform the interpolation so that variables can be
-     * evaluated in the global context.
+     * Creates a ConfigurationInterpolator with a chain to the parent's
+     * interpolator. 
      *
-     * @param value the value to be interpolated
+     * @return the new interpolator
      */
-    protected Object interpolate(Object value)
-    {
-        return getParent().interpolate(value);
+    @Override
+    protected ConfigurationInterpolator createInterpolator() {
+        ConfigurationInterpolator interpolator = super.createInterpolator();
+        interpolator.setParentInterpolator(getParent().getInterpolator());
+        return interpolator;
     }
+    
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java?rev=757108&r1=757107&r2=757108&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
Sun Mar 22 00:00:29 2009
@@ -284,12 +284,19 @@
             String prefix = var.substring(0, prefixPos);
             String name = var.substring(prefixPos + 1);
             String value = fetchLookupForPrefix(prefix).lookup(name);
+            if (value == null && getParentInterpolator() != null) {
+                value = getParentInterpolator().fetchLookupForPrefix(prefix).lookup(name);
+            }
             if (value != null)
             {
                 return value;
-            }
+            } 
+        }
+        String value = fetchNoPrefixLookup().lookup(var);
+        if (value == null && getParentInterpolator() != null) {
+            value = getParentInterpolator().fetchNoPrefixLookup().lookup(var);
         }
-        return fetchNoPrefixLookup().lookup(var);
+        return value;
     }
 
     /**
@@ -302,17 +309,7 @@
      */
     protected StrLookup fetchNoPrefixLookup()
     {
-        StrLookup lookup = null;
-        if (getDefaultLookup() != null) { 
-            lookup = getDefaultLookup();
-        }
-        if (lookup == null) { 
-            ConfigurationInterpolator parent = getParentInterpolator();
-            lookup = (parent == null) 
-                ? StrLookup.noneLookup() 
-                : parent.fetchNoPrefixLookup();
-        }
-        return lookup;
+        return (getDefaultLookup() != null) ? getDefaultLookup() : StrLookup.noneLookup();
     }
 
     /**
@@ -329,10 +326,7 @@
         StrLookup lookup = localLookups.get(prefix);
         if (lookup == null)
         {
-            ConfigurationInterpolator parent = getParentInterpolator();
-            lookup = (parent == null) 
-                ? StrLookup.noneLookup() 
-                : parent.fetchLookupForPrefix(prefix);
+            lookup = StrLookup.noneLookup();
         }
         return lookup;
     }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java?rev=757108&r1=757107&r2=757108&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java
Sun Mar 22 00:00:29 2009
@@ -335,9 +335,26 @@
     }
 
     /**
+     * An additional test for interpolation when the configurationAt() method is
+     * involved for a local interpolation.
+     */
+    public void testLocalInterpolationFromConfigurationAt()
+    {
+        parent.addProperty("base.dir", "/home/foo");
+        parent.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
+        parent.addProperty("test.absolute.dir.dir2", "${dir1}");
+
+        Configuration sub = parent.configurationAt("test.absolute.dir");
+        assertEquals("Wrong interpolation in subnode",
+            "/home/foo/path1", sub.getString("dir1"));
+        assertEquals("Wrong local interpolation in subnode",
+            "/home/foo/path1", sub.getString("dir2"));
+    }
+
+    /**
      * Tests manipulating the interpolator.
      */
-    public void todoTestInterpolator()
+    public void testInterpolator()
     {
         parent.addProperty("tablespaces.tablespace.name", "default");
         parent.addProperty("tablespaces.tablespace(-1).name", "test");



Mime
View raw message