commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1554639 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/interpol/ExprLookup.java test/java/org/apache/commons/configuration/interpol/TestExprLookup.java
Date Wed, 01 Jan 2014 16:47:06 GMT
Author: oheger
Date: Wed Jan  1 16:47:06 2014
New Revision: 1554639

URL: http://svn.apache.org/r1554639
Log:
[CONFIGURATION-562] Changed API of ExprLookup.

The class no longer supports setting an AbstractConfiguration object. Instead,
a ConfigurationInterpolator and a logger can be set. This change also removes a
cyclic dependency between the interpol and the top-level package.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestExprLookup.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java?rev=1554639&r1=1554638&r2=1554639&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java
Wed Jan  1 16:47:06 2014
@@ -18,7 +18,6 @@ package org.apache.commons.configuration
 
 import java.util.ArrayList;
 
-import org.apache.commons.configuration.AbstractConfiguration;
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.jexl2.Expression;
 import org.apache.commons.jexl2.JexlContext;
@@ -28,6 +27,7 @@ import org.apache.commons.lang3.ClassUti
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.text.StrLookup;
 import org.apache.commons.lang3.text.StrSubstitutor;
+import org.apache.commons.logging.Log;
 
 /**
  * Lookup that allows expressions to be evaluated.
@@ -75,12 +75,15 @@ public class ExprLookup implements Looku
     /** The default suffix for subordinate lookup expressions */
     private static final String DEFAULT_SUFFIX = "]";
 
-    /** Configuration being operated on */
-    private AbstractConfiguration configuration;
+    /** The ConfigurationInterpolator used by this object. */
+    private ConfigurationInterpolator interpolator;
 
     /** The StrSubstitutor for performing replace operations. */
     private StrSubstitutor substitutor;
 
+    /** The logger used by this instance. */
+    private Log logger;
+
     /** The engine. */
     private final JexlEngine engine = new JexlEngine();
 
@@ -133,7 +136,6 @@ public class ExprLookup implements Looku
         prefixMatcher = prefix;
     }
 
-
     /**
      * Set the suffix to use to identify subordinate expressions. This cannot be the
      * same as the suffix used for the primary expression.
@@ -163,13 +165,50 @@ public class ExprLookup implements Looku
     }
 
     /**
-     * Set the configuration to be used to interpolate subordinate expressions.
-     * @param config The Configuration.
+     * Returns the logger used by this object.
+     *
+     * @return the {@code Log}
+     * @since 2.0
+     */
+    public Log getLogger()
+    {
+        return logger;
+    }
+
+    /**
+     * Sets the logger to be used by this object. If no logger is passed in, no
+     * log output is generated.
+     *
+     * @param logger the {@code Log}
+     * @since 2.0
      */
-    public void setConfiguration(AbstractConfiguration config)
+    public void setLogger(Log logger)
     {
-        this.configuration = config;
-        installSubstitutor(config);
+        this.logger = logger;
+    }
+
+    /**
+     * Returns the {@code ConfigurationInterpolator} used by this object.
+     *
+     * @return the {@code ConfigurationInterpolator}
+     * @since 2.0
+     */
+    public ConfigurationInterpolator getInterpolator()
+    {
+        return interpolator;
+    }
+
+    /**
+     * Sets the {@code ConfigurationInterpolator} to be used by this object.
+     *
+     * @param interpolator the {@code ConfigurationInterpolator} (may be
+     *        <b>null</b>)
+     * @since 2.0
+     */
+    public void setInterpolator(ConfigurationInterpolator interpolator)
+    {
+        this.interpolator = interpolator;
+        installSubstitutor(interpolator);
     }
 
     /**
@@ -192,24 +231,25 @@ public class ExprLookup implements Looku
         }
         catch (Exception e)
         {
-            configuration.getLogger().debug("Error encountered evaluating " + result, e);
+            Log l = getLogger();
+            if (l != null)
+            {
+                l.debug("Error encountered evaluating " + result, e);
+            }
         }
 
         return result;
     }
 
     /**
-     * Creates a {@code StrSubstitutor} object which uses the
-     * {@code ConfigurationInterpolator} of the passed in configuration as
-     * lookup object.
+     * Creates a {@code StrSubstitutor} object which uses the passed in
+     * {@code ConfigurationInterpolator} as lookup object.
      *
-     * @param config the associated configuration
+     * @param ip the {@code ConfigurationInterpolator} to be used
      */
-    private void installSubstitutor(AbstractConfiguration config)
+    private void installSubstitutor(final ConfigurationInterpolator ip)
     {
-        final ConfigurationInterpolator interpolator =
-                (config == null) ? null : config.getInterpolator();
-        if (interpolator == null)
+        if (ip == null)
         {
             substitutor = null;
         }
@@ -220,7 +260,7 @@ public class ExprLookup implements Looku
                 @Override
                 public String lookup(String key)
                 {
-                    Object value = interpolator.resolve(key);
+                    Object value = ip.resolve(key);
                     return (value != null) ? value.toString() : null;
                 }
             };

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestExprLookup.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestExprLookup.java?rev=1554639&r1=1554638&r2=1554639&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestExprLookup.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/interpol/TestExprLookup.java
Wed Jan  1 16:47:06 2014
@@ -65,7 +65,8 @@ public class TestExprLookup
         handler.load(TEST_FILE);
         config.setLogger(log);
         ExprLookup lookup = new ExprLookup(vars);
-        lookup.setConfiguration(config);
+        lookup.setInterpolator(config.getInterpolator());
+        lookup.setLogger(log);
         String str = lookup.lookup(PATTERN1);
         assertTrue(str.startsWith("Goodbye"));
         str = lookup.lookup(PATTERN2);
@@ -74,10 +75,10 @@ public class TestExprLookup
     }
 
     /**
-     * Tests a lookup() operation if no configuration object has been set.
+     * Tests a lookup() operation if no ConfigurationInterpolator object has been set.
      */
     @Test
-    public void testLookupNoConfiguration()
+    public void testLookupNoConfigurationInterpolator()
     {
         ExprLookup.Variables vars = new ExprLookup.Variables();
         vars.add(new ExprLookup.Variable("String", org.apache.commons.lang3.StringUtils.class));



Mime
View raw message