Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 087D6D05F for ; Fri, 28 Dec 2012 20:26:09 +0000 (UTC) Received: (qmail 33209 invoked by uid 500); 28 Dec 2012 20:26:08 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 33161 invoked by uid 500); 28 Dec 2012 20:26:08 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 33154 invoked by uid 99); 28 Dec 2012 20:26:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Dec 2012 20:26:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Dec 2012 20:26:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 18951238896F; Fri, 28 Dec 2012 20:25:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1426620 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/ test/java/org/apache/commons/configuration/builder/ Date: Fri, 28 Dec 2012 20:25:44 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121228202545.18951238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Fri Dec 28 20:25:44 2012 New Revision: 1426620 URL: http://svn.apache.org/viewvc?rev=1426620&view=rev Log: BasicBuilderParameters now support a property for the parent ConfigurationInterpolator. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java?rev=1426620&r1=1426619&r2=1426620&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderParameters.java Fri Dec 28 20:25:44 2012 @@ -71,6 +71,9 @@ public class BasicBuilderParameters impl /** The key for the defaultLookups property. */ private static final String PROP_DEFAULT_LOOKUPS = "defaultLookups"; + /** The key for the parentInterpolator property. */ + private static final String PROP_PARENT_INTERPOLATOR = "parentInterpolator"; + /** The map for storing the current property values. */ private final Map properties; @@ -96,6 +99,7 @@ public class BasicBuilderParameters impl // A custom ConfigurationInterpolator overrides lookups result.remove(PROP_PREFIX_LOOKUPS); result.remove(PROP_DEFAULT_LOOKUPS); + result.remove(PROP_PARENT_INTERPOLATOR); } return result; } @@ -208,6 +212,16 @@ public class BasicBuilderParameters impl } /** + * {@inheritDoc} This implementation stores the passed in + * {@code ConfigurationInterpolator} object in the internal parameters map. + */ + public BasicBuilderParameters setParentInterpolator( + ConfigurationInterpolator parent) + { + return setProperty(PROP_PARENT_INTERPOLATOR, parent); + } + + /** * Merges this object with the given parameters object. This method adds all * property values defined by the passed in parameters object to the * internal storage which are not already in. So properties already defined @@ -238,15 +252,23 @@ public class BasicBuilderParameters impl /** * Sets a property for this parameters object. Properties are stored in an - * internal map. With this method a new entry can be added to this map. It - * can be used by sub classes which also store properties in a map. + * internal map. With this method a new entry can be added to this map. If + * the value is null, the key is removed from the internal map. This + * method can be used by sub classes which also store properties in a map. * * @param key the key of the property * @param value the value of the property */ protected void storeProperty(String key, Object value) { - properties.put(key, value); + if (value == null) + { + properties.remove(key); + } + else + { + properties.put(key, value); + } } /** Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java?rev=1426620&r1=1426619&r2=1426620&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicBuilderProperties.java Fri Dec 28 20:25:44 2012 @@ -128,4 +128,16 @@ public interface BasicBuilderProperties< * @see ConfigurationInterpolator#addDefaultLookups(Collection) */ T setDefaultLookups(Collection lookups); + + /** + * Sets the parent {@code ConfigurationInterpolator} for this + * configuration's {@code ConfigurationInterpolator}. Setting a parent + * {@code ConfigurationInterpolator} can be used for defining a default + * behavior for variables which cannot be resolved. + * + * @param parent the new parent {@code ConfigurationInterpolator} + * @return a reference to this object for method chaining + * @see ConfigurationInterpolator#setParentInterpolator(ConfigurationInterpolator) + */ + T setParentInterpolator(ConfigurationInterpolator parent); } Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java?rev=1426620&r1=1426619&r2=1426620&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicBuilderParameters.java Fri Dec 28 20:25:44 2012 @@ -195,6 +195,20 @@ public class TestBasicBuilderParameters } /** + * Tests whether a parent {@code ConfigurationInterpolator} can be set. + */ + @Test + public void testSetParentInterpolator() + { + ConfigurationInterpolator parent = + EasyMock.createMock(ConfigurationInterpolator.class); + EasyMock.replay(parent); + assertSame("Wrong result", params, params.setParentInterpolator(parent)); + assertSame("Wrong parent", parent, + params.getParameters().get("parentInterpolator")); + } + + /** * Tests whether a custom {@code ConfigurationInterpolator} overrides * settings for custom lookups. */ @@ -203,14 +217,19 @@ public class TestBasicBuilderParameters { Lookup look1 = EasyMock.createMock(Lookup.class); Lookup look2 = EasyMock.createMock(Lookup.class); + ConfigurationInterpolator parent = + EasyMock.createMock(ConfigurationInterpolator.class); ConfigurationInterpolator ci = EasyMock.createMock(ConfigurationInterpolator.class); params.setDefaultLookups(Collections.singleton(look1)); params.setPrefixLookups(Collections.singletonMap("test", look2)); params.setInterpolator(ci); + params.setParentInterpolator(parent); Map map = params.getParameters(); assertFalse("Got prefix lookups", map.containsKey("prefixLookups")); assertFalse("Got default lookups", map.containsKey("defaultLookups")); + assertFalse("Got a parent interpolator", + map.containsKey("parentInterpolator")); } /**