commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r711407 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/CombinedConfiguration.java test/org/apache/commons/configuration/TestCombinedConfiguration.java
Date Tue, 04 Nov 2008 21:11:36 GMT
Author: oheger
Date: Tue Nov  4 13:11:36 2008
New Revision: 711407

URL: http://svn.apache.org/viewvc?rev=711407&view=rev
Log:
CONFIGURATION-336: CombinedConfiguration now allows setting a specific expression engine that
will be used when converting flat configurations to hierarchical ones.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/CombinedConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCombinedConfiguration.java

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/CombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/CombinedConfiguration.java?rev=711407&r1=711406&r2=711407&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/CombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/CombinedConfiguration.java
Tue Nov  4 13:11:36 2008
@@ -30,6 +30,7 @@
 import org.apache.commons.configuration.tree.DefaultConfigurationKey;
 import org.apache.commons.configuration.tree.DefaultConfigurationNode;
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
+import org.apache.commons.configuration.tree.ExpressionEngine;
 import org.apache.commons.configuration.tree.NodeCombiner;
 import org.apache.commons.configuration.tree.UnionCombiner;
 import org.apache.commons.configuration.tree.ViewNode;
@@ -200,6 +201,12 @@
     /** Stores a map with the named configurations. */
     private Map namedConfigurations;
 
+    /**
+     * An expression engine used for converting child configurations to
+     * hierarchical ones.
+     */
+    private ExpressionEngine conversionExpressionEngine;
+
     /** A flag whether an enhanced reload check is to be performed.*/
     private boolean forceReloadCheck;
 
@@ -287,6 +294,39 @@
     }
 
     /**
+     * Returns the <code>ExpressionEngine</code> for converting flat child
+     * configurations to hierarchical ones.
+     *
+     * @return the conversion expression engine
+     * @since 1.6
+     */
+    public ExpressionEngine getConversionExpressionEngine()
+    {
+        return conversionExpressionEngine;
+    }
+
+    /**
+     * Sets the <code>ExpressionEngine</code> for converting flat child
+     * configurations to hierarchical ones. When constructing the root node for
+     * this combined configuration the properties of all child configurations
+     * must be combined to a single hierarchical node structure. In this
+     * process, non hierarchical configurations are converted to hierarchical
+     * ones first. This can be problematic if a child configuration contains
+     * keys that are no compatible with the default expression engine used by
+     * hierarchical configurations. Therefore it is possible to specify a
+     * specific expression engine to be used for this purpose.
+     *
+     * @param conversionExpressionEngine the conversion expression engine
+     * @see ConfigurationUtils#convertToHierarchical(Configuration, ExpressionEngine)
+     * @since 1.6
+     */
+    public void setConversionExpressionEngine(
+            ExpressionEngine conversionExpressionEngine)
+    {
+        this.conversionExpressionEngine = conversionExpressionEngine;
+    }
+
+    /**
      * Adds a new configuration to this combined configuration. It is possible
      * (but not mandatory) to give the new configuration a name. This name must
      * be unique, otherwise a <code>ConfigurationRuntimeException</code> will
@@ -708,7 +748,7 @@
      * An internal helper class for storing information about contained
      * configurations.
      */
-    static class ConfigData
+    class ConfigData
     {
         /** Stores a reference to the configuration. */
         private AbstractConfiguration configuration;
@@ -808,7 +848,8 @@
 
             // Copy data of the root node to the new path
             HierarchicalConfiguration hc = ConfigurationUtils
-                    .convertToHierarchical(getConfiguration());
+                    .convertToHierarchical(getConfiguration(),
+                            getConversionExpressionEngine());
             atParent.appendChildren(hc.getRootNode());
             atParent.appendAttributes(hc.getRootNode());
             rootNode = hc.getRootNode();

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCombinedConfiguration.java?rev=711407&r1=711406&r2=711407&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCombinedConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCombinedConfiguration.java
Tue Nov  4 13:11:36 2008
@@ -32,6 +32,7 @@
 import org.apache.commons.configuration.event.ConfigurationEvent;
 import org.apache.commons.configuration.event.ConfigurationListener;
 import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
+import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.NodeCombiner;
 import org.apache.commons.configuration.tree.UnionCombiner;
 
@@ -638,6 +639,28 @@
     }
 
     /**
+     * Tests using a conversion expression engine for child configurations with
+     * strange keys. This test is related to CONFIGURATION-336.
+     */
+    public void testConversionExpressionEngine()
+    {
+        PropertiesConfiguration child = new PropertiesConfiguration();
+        child.addProperty("test(a)", "1,2,3");
+        config.addConfiguration(child);
+        DefaultExpressionEngine engineQuery = new DefaultExpressionEngine();
+        engineQuery.setIndexStart("<");
+        engineQuery.setIndexEnd(">");
+        config.setExpressionEngine(engineQuery);
+        DefaultExpressionEngine engineConvert = new DefaultExpressionEngine();
+        engineConvert.setIndexStart("[");
+        engineConvert.setIndexEnd("]");
+        config.setConversionExpressionEngine(engineConvert);
+        assertEquals("Wrong property 1", "1", config.getString("test(a)<0>"));
+        assertEquals("Wrong property 2", "2", config.getString("test(a)<1>"));
+        assertEquals("Wrong property 3", "3", config.getString("test(a)<2>"));
+    }
+
+    /**
      * Helper method for writing a file. The file is also added to a list and
      * will be deleted in teadDown() automatically.
      *



Mime
View raw message