commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r755734 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/ java/org/apache/commons/configuration/interpol/ test/org/apache/commons/configuration/
Date Wed, 18 Mar 2009 21:02:57 GMT
Author: joehni
Date: Wed Mar 18 21:02:56 2009
New Revision: 755734

URL: http://svn.apache.org/viewvc?rev=755734&view=rev
Log:
Merge changes for CONFIGURATION-375 and CONFIGURATION-376 from configuration2 branch.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/   (props
changed)
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/SubsetConfiguration.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/   (props
changed)
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 18 21:02:56 2009
@@ -1 +1 @@
-/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2:751544-751840
+/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2:751544-751840,755692

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/SubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/SubsetConfiguration.java?rev=755734&r1=755733&r2=755734&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/SubsetConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/SubsetConfiguration.java
Wed Mar 18 21:02:56 2009
@@ -21,6 +21,7 @@
 
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.iterators.TransformIterator;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 
 /**
  * <p>A subset of another configuration. The new Configuration object contains
@@ -215,7 +216,11 @@
         else
         {
             SubsetConfiguration config = new SubsetConfiguration(parent, "");
-            getInterpolator().registerLocalLookups(config.getInterpolator());
+            ConfigurationInterpolator interpolator = config.getInterpolator();
+            getInterpolator().registerLocalLookups(interpolator);
+            if (parent instanceof AbstractConfiguration) {
+                interpolator.setParentInterpolator(((AbstractConfiguration)parent).getInterpolator());
+            }
             return config.interpolate(base);
         }
     }

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java?rev=755734&r1=755733&r2=755734&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
Wed Mar 18 21:02:56 2009
@@ -127,6 +127,9 @@
 
     /** Stores the default lookup object. */
     private StrLookup defaultLookup;
+    
+    /** Stores a parent interpolator objects if the interpolator is nested hierarchically.
*/
+    private ConfigurationInterpolator parentInterpolator;
 
     /**
      * Creates a new instance of <code>ConfigurationInterpolator</code>.
@@ -295,20 +298,30 @@
      * Returns the lookup object to be used for variables without a prefix. This
      * implementation will check whether a default lookup object was set. If
      * this is the case, it will be returned. Otherwise a <b>null</b> lookup
-     * object will be returned.
+     * object will be returned (never <code>null</code>).
      *
      * @return the lookup object to be used for variables without a prefix
      */
     protected StrLookup fetchNoPrefixLookup()
     {
-        return (getDefaultLookup() != null) ? getDefaultLookup() : StrLookup.noneLookup();
+        StrLookup lookup = null;
+        if (getDefaultLookup() != null) { 
+            lookup = getDefaultLookup();
+        }
+        if (lookup == null) { 
+            ConfigurationInterpolator parent = getParentInterpolator();
+            lookup = (parent == null) 
+                ? StrLookup.noneLookup() 
+                : parent.fetchNoPrefixLookup();
+        }
+        return lookup;
     }
 
     /**
      * Obtains the lookup object for the specified prefix. This method is called
      * by the <code>lookup()</code> method. This implementation will check
      * whether a lookup object is registered for the given prefix. If not, a
-     * <b>null</b> lookup object will be returned.
+     * <b>null</b> lookup object will be returned (never <code>null</code>).
      *
      * @param prefix the prefix
      * @return the lookup object to be used for this prefix
@@ -318,7 +331,10 @@
         StrLookup lookup = (StrLookup) localLookups.get(prefix);
         if (lookup == null)
         {
-            lookup = StrLookup.noneLookup();
+            ConfigurationInterpolator parent = getParentInterpolator();
+            lookup = (parent == null) 
+                ? StrLookup.noneLookup() 
+                : parent.fetchLookupForPrefix(prefix);
         }
         return lookup;
     }
@@ -333,6 +349,28 @@
         interpolator.localLookups.putAll(localLookups);
     }
 
+    /**
+     * Sets the parent interpolator. This object is used if the interpolation is nested hierarchically
+     * and the current interpolation object cannot resolve a variable. 
+     * 
+     * @param parentInterpolator the parent interpolator object or <code>null</code>
+     * @since upcoming
+     */
+    public void setParentInterpolator(ConfigurationInterpolator parentInterpolator) {
+        this.parentInterpolator = parentInterpolator;
+    }
+
+    /**
+     * Requests the parent interpolator. This object is used if the interpolation is nested
hierarchically
+     * and the current interpolation
+     * 
+     * @return the parent interpolator or <code>null</code>
+     * @since upcoming
+     */
+    public ConfigurationInterpolator getParentInterpolator() {
+        return this.parentInterpolator;
+    }
+
     // static initializer, sets up the map with the standard lookups
     static
     {

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 18 21:02:56 2009
@@ -1 +1 @@
-/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2:751544-751840
+/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2:751544-751840,755692

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java?rev=755734&r1=755733&r2=755734&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
Wed Mar 18 21:02:56 2009
@@ -29,9 +29,11 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
 import org.apache.commons.configuration.tree.ConfigurationNode;
 import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
+import org.apache.commons.lang.text.StrLookup;
 
 /**
  * Test case for SubnodeConfiguration.
@@ -332,6 +334,35 @@
     }
 
     /**
+     * Tests manipulating the interpolator.
+     */
+    public void todoTestInterpolator()
+    {
+        parent.addProperty("tablespaces.tablespace.name", "default");
+        parent.addProperty("tablespaces.tablespace(-1).name", "test");
+
+        setUpSubnodeConfig();
+        InterpolationTestHelper.testGetInterpolator(config);
+    }
+
+    public void testLocalLookupsInInterpolatorAreInherited() {
+        parent.addProperty("tablespaces.tablespace.name", "default");
+        parent.addProperty("tablespaces.tablespace(-1).name", "test");
+        parent.addProperty("tables.table(0).var", "${brackets:x}");
+        
+        ConfigurationInterpolator interpolator = parent.getInterpolator();
+        interpolator.registerLookup("brackets", new StrLookup(){
+
+            public String lookup(String key) {
+                return "(" + key +")";
+            }
+            
+        });
+        setUpSubnodeConfig();
+        assertEquals("Local lookup was not inherited", "(x)", config.getString("var", ""));
+    }
+
+    /**
      * Tests a reload operation for the parent configuration when the subnode
      * configuration does not support reloads. Then the new value should not be
      * detected.

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java?rev=755734&r1=755733&r2=755734&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubsetConfiguration.java
Wed Mar 18 21:02:56 2009
@@ -295,8 +295,7 @@
         InterpolationTestHelper.testGetInterpolator(subset);
     }
     
-    // TODO: Next step
-    public void todoTestLocalLookupsInInterpolorAreInherited() {
+    public void testLocalLookupsInInterpolatorAreInherited() {
         BaseConfiguration config = new BaseConfiguration();
         ConfigurationInterpolator interpolator = config.getInterpolator();
         interpolator.registerLookup("brackets", new StrLookup(){
@@ -309,6 +308,17 @@
         config.setProperty("prefix.var", "${brackets:x}");
         AbstractConfiguration subset = (AbstractConfiguration) config
                 .subset("prefix");
-        assertEquals("Local lookup was not inherited", "(x)", subset.getString("var", ""));
+        assertEquals("Local lookup was not inherited", "(x)", subset
+                .getString("var", ""));
+    }
+    
+    public void testInterpolationForKeysOfTheParent() {
+        BaseConfiguration config = new BaseConfiguration();
+        config.setProperty("test", "junit");
+        config.setProperty("prefix.key", "${test}");
+        AbstractConfiguration subset = (AbstractConfiguration) config
+                .subset("prefix");
+        assertEquals("Interpolation does not resolve parent keys", "junit",
+                subset.getString("key", ""));
     }
 }



Mime
View raw message