You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oh...@apache.org on 2007/04/21 21:03:59 UTC
svn commit: r531087 - in /jakarta/commons/proper/configuration/trunk:
src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
xdocs/changes.xml
Author: oheger
Date: Sat Apr 21 12:03:58 2007
New Revision: 531087
URL: http://svn.apache.org/viewvc?view=rev&rev=531087
Log:
CONFIGURATION-266: ConfigurationInterpolator now also invokes the default lookup object for variables with a prefix that could not be resolved by their associated lookup object. Thanks to Tobias Noebel.
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java?view=diff&rev=531087&r1=531086&r2=531087
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/interpol/ConfigurationInterpolator.java Sat Apr 21 12:03:58 2007
@@ -29,7 +29,7 @@
* </p>
* <p>
* Each instance of <code>AbstractConfiguration</code> is associated with an
- * object of this class. Each interpolation tasks are delegated to this object.
+ * object of this class. All interpolation tasks are delegated to this object.
* </p>
* <p>
* <code>ConfigurationInterpolator</code> works together with the
@@ -40,13 +40,14 @@
* </p>
* <p>
* The basic idea of this class is that it can maintain a set of primitive
- * <code>StrLookup</code> objects, each of which are identified by a special
+ * <code>StrLookup</code> objects, each of which is identified by a special
* prefix. The variables to be processed have the form
* <code>${prefix:name}</code>. <code>ConfigurationInterpolator</code> will
* extract the prefix and determine, which primitive lookup object is registered
* for it. Then the name of the variable is passed to this object to obtain the
* actual value. It is also possible to define a default lookup object, which
- * will be used for variables that do not have a prefix.
+ * will be used for variables that do not have a prefix or that cannot be
+ * resolved by their associated lookup object.
* </p>
* <p>
* When a new instance of this class is created it is initialized with a default
@@ -92,8 +93,8 @@
* Implementation node: Instances of this class are not thread-safe related to
* modifications of their current set of registered lookup objects. It is
* intended that each instance is associated with a single
- * <code>Configuration</conde>
- * object and used for its interpolation tasks.</p>
+ * <code>Configuration</code> object and used for its interpolation tasks.
+ * </p>
*
* @version $Id$
* @since 1.4
@@ -262,7 +263,8 @@
* a variable prefix from the given variable name (the first colon (':') is
* used as prefix separator). It then passes the name of the variable with
* the prefix stripped to the lookup object registered for this prefix. If
- * no prefix can be found, the default lookup object will be used.
+ * no prefix can be found or if the associated lookup object cannot resolve
+ * this variable, the default lookup object will be used.
*
* @param var the name of the variable whose value is to be looked up
* @return the value of this variable or <b>null</b> if it cannot be
@@ -274,18 +276,19 @@
{
return null;
}
-
+
int prefixPos = var.indexOf(PREFIX_SEPARATOR);
- if (prefixPos < 0)
- {
- return fetchNoPrefixLookup().lookup(var);
- }
- else
+ if (prefixPos >= 0)
{
String prefix = var.substring(0, prefixPos);
String name = var.substring(prefixPos + 1);
- return fetchLookupForPrefix(prefix).lookup(name);
+ String value = fetchLookupForPrefix(prefix).lookup(name);
+ if (value != null)
+ {
+ return value;
+ }
}
+ return fetchNoPrefixLookup().lookup(var);
}
/**
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java?view=diff&rev=531087&r1=531086&r2=531087
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/interpol/TestConfigurationInterpolator.java Sat Apr 21 12:03:58 2007
@@ -336,4 +336,20 @@
.lookup(ConfigurationInterpolator.PREFIX_CONSTANTS
+ ":" + varName));
}
+
+ /**
+ * Tests whether the default lookup is called for variables with a prefix
+ * when the lookup that was registered for this prefix is not able to
+ * resolve the variable.
+ */
+ public void testLookupDefaultAfterPrefixFails()
+ {
+ final String varName = TEST_PREFIX + ':' + TEST_NAME + "2";
+ interpolator.registerLookup(TEST_PREFIX, setUpTestLookup());
+ Map map = new HashMap();
+ map.put(varName, TEST_VALUE);
+ interpolator.setDefaultLookup(StrLookup.mapLookup(map));
+ assertEquals("Variable is not resolved by default lookup", TEST_VALUE,
+ interpolator.lookup(varName));
+ }
}
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=531087&r1=531086&r2=531087
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Apr 21 12:03:58 2007
@@ -23,6 +23,11 @@
<body>
<release version="1.5-SNAPSHOT" date="in SVN" description="">
+ <action dev="oheger" type="update" issue="CONFIGURATION-266" due-to="Tobias Noebel">
+ ConfigurationInterpolator now also invokes the default lookup object for
+ variables with a prefix that could not be resolved by their associated
+ lookup object.
+ </action>
<action dev="oheger" type="add" issue="CONFIGURATION-264">
A SubnodeConfiguration per default does not see certain changes of its
parent configuration (e.g. reloads). With a new boolean parameter of
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org