commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r751830 - 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 Mon, 09 Mar 2009 21:00:26 GMT
Author: joehni
Date: Mon Mar  9 21:00:26 2009
New Revision: 751830

URL: http://svn.apache.org/viewvc?rev=751830&view=rev
Log:
Fix local lookups for SubsetConfiguration (CONFIGURATION-369).

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubsetConfiguration.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/TestSubsetConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubsetConfiguration.java?rev=751830&r1=751829&r2=751830&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubsetConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubsetConfiguration.java
Mon Mar  9 21:00:26 2009
@@ -17,7 +17,12 @@
 
 package org.apache.commons.configuration2;
 
+import org.apache.commons.configuration2.interpol.ConfigurationInterpolator;
+import org.apache.commons.lang.text.StrLookup;
+
 import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * <p>A subset of another configuration. The new Configuration object contains
@@ -195,7 +200,7 @@
     {
         return new SubsetIterator(parent.getKeys(prefix));
     }
-
+    
     @Override
     protected Object interpolate(Object base)
     {
@@ -206,6 +211,7 @@
         else
         {
             SubsetConfiguration config = new SubsetConfiguration(parent, "");
+            getInterpolator().registerLocalLookups(config.getInterpolator());
             return config.interpolate(base);
         }
     }
@@ -323,7 +329,7 @@
     /**
      * A specialized iterator to be returned by the <code>getKeys()</code>
      * methods. This implementation wraps an iterator from the parent
-     * configuration. The keys returned by this iterator are correspondigly
+     * configuration. The keys returned by this iterator are correspondingly
      * transformed.
      */
     private class SubsetIterator implements Iterator<String>

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=751830&r1=751829&r2=751830&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
Mon Mar  9 21:00:26 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.configuration2.interpol;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -229,7 +230,7 @@
      *
      * @return a set with the registered variable prefixes
      */
-    public Set prefixSet()
+    public Set<String> prefixSet()
     {
         return localLookups.keySet();
     }
@@ -313,13 +314,23 @@
      */
     protected StrLookup fetchLookupForPrefix(String prefix)
     {
-        StrLookup lookup = (StrLookup) localLookups.get(prefix);
+        StrLookup lookup = localLookups.get(prefix);
         if (lookup == null)
         {
             lookup = StrLookup.noneLookup();
         }
         return lookup;
     }
+    
+    /**
+     * Registers the local lookup instances for the given interpolator.
+     * 
+     * @param interpolator the instance receiving the local lookups
+     * @since upcoming
+     */
+    public void registerLocalLookups(ConfigurationInterpolator interpolator) {
+        interpolator.localLookups.putAll(localLookups);
+    }
 
     // static initializer, sets up the map with the standard lookups
     static

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubsetConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubsetConfiguration.java?rev=751830&r1=751829&r2=751830&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubsetConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubsetConfiguration.java
Mon Mar  9 21:00:26 2009
@@ -26,6 +26,8 @@
 import java.util.Set;
 
 import org.apache.commons.configuration2.flat.BaseConfiguration;
+import org.apache.commons.configuration2.interpol.ConfigurationInterpolator;
+import org.apache.commons.lang.text.StrLookup;
 
 import junit.framework.TestCase;
 
@@ -160,7 +162,7 @@
         assertEquals("prefix", "prefix", subset.getPrefix());
     }
 
-    public void testThrowtExceptionOnMissing()
+    public void testThrowExceptionOnMissing()
     {
         BaseConfiguration config = new BaseConfiguration();
         config.setThrowExceptionOnMissing(true);
@@ -208,7 +210,7 @@
         keys.add("type");
         while(itKeys.hasNext())
         {
-            String k = (String) itKeys.next();
+            String k = itKeys.next();
             assertTrue(keys.contains(k));
             keys.remove(k);
         }
@@ -283,4 +285,33 @@
         assertFalse("Wrong value of list parsing flag in parent", config
                 .isDelimiterParsingDisabled());
     }
+
+    /**
+     * Tests manipulating the interpolator.
+     */
+    public void testInterpolator()
+    {
+        BaseConfiguration config = new BaseConfiguration();
+        AbstractConfiguration subset = (AbstractConfiguration) config
+                .subset("prefix");
+        InterpolationTestHelper.testGetInterpolator(subset);
+    }
+    
+    // TODO: Next step
+    public void todoTestLocalLookupsInInterpolorAreInherited() {
+        BaseConfiguration config = new BaseConfiguration();
+        ConfigurationInterpolator interpolator = config.getInterpolator();
+        interpolator.registerLookup("brackets", new StrLookup(){
+
+            @Override
+            public String lookup(String key) {
+                return "(" + key +")";
+            }
+            
+        });
+        config.setProperty("prefix.var", "${brackets:x}");
+        AbstractConfiguration subset = (AbstractConfiguration) config
+                .subset("prefix");
+        assertEquals("Local lookup was not inherited", "(x)", subset.getString("var", ""));
+    }
 }



Mime
View raw message