commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1426025 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/combined/ test/resources/
Date Wed, 26 Dec 2012 21:02:07 GMT
Author: oheger
Date: Wed Dec 26 21:02:07 2012
New Revision: 1426025

URL: http://svn.apache.org/viewvc?rev=1426025&view=rev
Log:
CombinedConfigurationBuilder now correctly configures a CatalogResolver with a ConfigurationInterpolator.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1426025&r1=1426024&r2=1426025&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
Wed Dec 26 21:02:07 2012
@@ -48,6 +48,8 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
 import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
 import org.apache.commons.configuration.builder.XMLBuilderProperties;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
+import org.apache.commons.configuration.interpol.Lookup;
 import org.apache.commons.configuration.resolver.CatalogResolver;
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.OverrideCombiner;
@@ -896,9 +898,10 @@ public class CombinedConfigurationBuilde
             {
                 BeanHelper.setProperty(resolver, "baseDir", basePath);
             }
-            // BeanHelper.setProperty(resolver, "substitutor",
-            // getSubstitutor());
-            // setEntityResolver(resolver);
+            ConfigurationInterpolator ci = new ConfigurationInterpolator();
+            ci.registerLookups(fetchPrefixLookups());
+            BeanHelper.setProperty(resolver, "interpolator", ci);
+
             xmlParams.setEntityResolver(resolver);
         }
     }
@@ -1185,6 +1188,19 @@ public class CombinedConfigurationBuilde
     }
 
     /**
+     * Returns a map with the current prefix lookup objects. This map is
+     * obtained from the {@code ConfigurationInterpolator} of the configuration
+     * under construction.
+     *
+     * @return the map with current prefix lookups (may be <b>null</b>)
+     */
+    private Map<String, ? extends Lookup> fetchPrefixLookups()
+    {
+        CombinedConfiguration cc = getConfigurationUnderConstruction();
+        return (cc != null) ? cc.getInterpolator().getLookups() : null;
+    }
+
+    /**
      * Creates a default builder for the definition configuration and
      * initializes it with a parameters object. The default builder creates an
      * {@code XMLConfiguration}; it expects a corresponding file specification.

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java?rev=1426025&r1=1426024&r2=1426025&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
Wed Dec 26 21:02:07 2012
@@ -51,8 +51,8 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.builder.XMLBuilderParametersImpl;
 import org.apache.commons.configuration.event.ConfigurationErrorListener;
 import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
 import org.apache.commons.configuration.resolver.CatalogResolver;
-import org.apache.commons.configuration.resolver.DefaultEntityResolver;
 import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
@@ -659,8 +659,11 @@ public class TestCombinedConfigurationBu
         CombinedConfiguration cc = factory.getConfiguration();
         XMLConfiguration xmlConf =
                 (XMLConfiguration) cc.getConfiguration("xml");
-        assertTrue("Wrong entity resolver: " + xmlConf.getEntityResolver(),
-                xmlConf.getEntityResolver() instanceof EntityResolverTestImpl);
+        EntityResolverWithPropertiesTestImpl resolver =
+                (EntityResolverWithPropertiesTestImpl) xmlConf
+                        .getEntityResolver();
+        assertFalse("No lookups", resolver.getInterpolator().getLookups()
+                .isEmpty());
     }
 
     /**
@@ -946,14 +949,6 @@ public class TestCombinedConfigurationBu
     }
 
     /**
-     * A special entity resolver implementation for testing whether a resolver
-     * can be defined in the definition file.
-     */
-    public static class EntityResolverTestImpl extends DefaultEntityResolver
-    {
-    }
-
-    /**
      * A specialized entity resolver implementation for testing whether
      * properties of a catalog resolver are correctly set.
      */
@@ -966,6 +961,9 @@ public class TestCombinedConfigurationBu
         /** The file system. */
         private FileSystem fileSystem;
 
+        /** The ConfigurationInterpolator. */
+        private ConfigurationInterpolator interpolator;
+
         public FileSystem getFileSystem()
         {
             return fileSystem;
@@ -989,6 +987,18 @@ public class TestCombinedConfigurationBu
             super.setBaseDir(baseDir);
             baseDirectory = baseDir;
         }
+
+        public ConfigurationInterpolator getInterpolator()
+        {
+            return interpolator;
+        }
+
+        @Override
+        public void setInterpolator(ConfigurationInterpolator interpolator)
+        {
+            super.setInterpolator(interpolator);
+            this.interpolator = interpolator;
+        }
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml?rev=1426025&r1=1426024&r2=1426025&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml (original)
+++ commons/proper/configuration/trunk/src/test/resources/testCCEntityResolver.xml Wed Dec
26 21:02:07 2012
@@ -23,7 +23,7 @@
 <configuration>
   <header>
     <entity-resolver
-      config-class="org.apache.commons.configuration.builder.combined.TestCombinedConfigurationBuilder$EntityResolverTestImpl"/>
+      config-class="org.apache.commons.configuration.builder.combined.TestCombinedConfigurationBuilder$EntityResolverWithPropertiesTestImpl"/>
   </header>
   <xml fileName="test.xml" config-name="xml"/>
 </configuration>



Mime
View raw message