commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1520800 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/ test/java/org/apache/commons/configuration/builder/
Date Sat, 07 Sep 2013 19:46:03 GMT
Author: oheger
Date: Sat Sep  7 19:46:03 2013
New Revision: 1520800

URL: http://svn.apache.org/r1520800
Log:
BasicBuilderParameters now supports setting a BeanHelper instance.

The BeanHelper is used by the ConfigurationBuilder for the creation and
initialization of the result configuration. By making use of this new
property a specific BeanHelper can be injected.

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=1520800&r1=1520799&r2=1520800&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
Sat Sep  7 19:46:03 2013
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.commons.configuration.beanutils.BeanHelper;
 import org.apache.commons.configuration.convert.ConversionHandler;
 import org.apache.commons.configuration.convert.ListDelimiterHandler;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
@@ -78,9 +79,13 @@ public class BasicBuilderParameters impl
     /** The key for the <em>synchronizer</em> property. */
     private static final String PROP_SYNCHRONIZER = "synchronizer";
 
-    /** The key or the <em>conversionHandler</em> property. */
+    /** The key for the <em>conversionHandler</em> property. */
     private static final String PROP_CONVERSION_HANDLER = "conversionHandler";
 
+    /** The key for the {@code BeanHelper}. */
+    private static final String PROP_BEAN_HELPER = RESERVED_PARAMETER_PREFIX
+            + "BeanHelper";
+
     /** The map for storing the current property values. */
     private Map<String, Object> properties;
 
@@ -238,6 +243,18 @@ public class BasicBuilderParameters impl
     }
 
     /**
+     * {@inheritDoc} This implementation stores the passed in {@code BeanHelper}
+     * object in the internal parameters map, but uses a reserved key, so that
+     * it is not used for the initialization of properties of the managed
+     * configuration object. The {@code fetchBeanHelper()} method can be used to
+     * obtain the {@code BeanHelper} instance from a parameters map.
+     */
+    public BasicBuilderParameters setBeanHelper(BeanHelper beanHelper)
+    {
+        return setProperty(PROP_BEAN_HELPER, beanHelper);
+    }
+
+    /**
      * 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
@@ -294,6 +311,22 @@ public class BasicBuilderParameters impl
     }
 
     /**
+     * Obtains the {@code BeanHelper} object from the specified map with
+     * parameters. This method can be used to obtain an instance from a
+     * parameters map that has been set via the {@code setBeanHelper()} method.
+     * If no such instance is found, result is <b>null</b>.
+     *
+     * @param params the map with parameters (must not be <b>null</b>)
+     * @return the {@code BeanHelper} stored in this map or <b>null</b>
+     * @throws IllegalArgumentException if the map is <b>null</b<
+     */
+    public static BeanHelper fetchBeanHelper(Map<String, Object> params)
+    {
+        checkParameters(params);
+        return (BeanHelper) params.get(PROP_BEAN_HELPER);
+    }
+
+    /**
      * Clones this object. This is useful because multiple builder instances may
      * use a similar set of parameters. However, single instances of parameter
      * objects must not assigned to multiple builders. Therefore, cloning a

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=1520800&r1=1520799&r2=1520800&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
Sat Sep  7 19:46:03 2013
@@ -20,6 +20,7 @@ import java.util.Collection;
 import java.util.Map;
 
 import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.commons.configuration.beanutils.BeanHelper;
 import org.apache.commons.configuration.convert.ConversionHandler;
 import org.apache.commons.configuration.convert.ListDelimiterHandler;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
@@ -157,4 +158,23 @@ public interface BasicBuilderProperties<
      * @return a reference to this object for method chaining
      */
     T setConversionHandler(ConversionHandler handler);
+
+    /**
+     * Sets a {@code BeanHelper} object to be used by the configuration builder.
+     * The {@code BeanHelper} is used to create the managed configuration
+     * instance dynamically. It is not a property of the configuration as most
+     * other properties defined by this interface. By setting an alternative
+     * {@code BeanHelper} the process of creating configuration instances via
+     * reflection can be adapted. (Some specialized configuration builder
+     * implementations also use a {@code BeanHelper} to create complex helper
+     * objects during construction of their result object.
+     * {@code CombinedConfigurationBuilder} for instance supports a complex
+     * configuration definition format which may contain several specialized
+     * bean declarations.) If no specific {@code BeanHelper} is set, the builder
+     * uses the default instance.
+     *
+     * @param beanHelper the {@code BeanHelper} to be used by the builder
+     * @return a reference to this object for method chaining
+     */
+    T setBeanHelper(BeanHelper beanHelper);
 }

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=1520800&r1=1520799&r2=1520800&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
Sat Sep  7 19:46:03 2013
@@ -29,6 +29,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.configuration.beanutils.BeanHelper;
 import org.apache.commons.configuration.convert.ConversionHandler;
 import org.apache.commons.configuration.convert.ListDelimiterHandler;
 import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
@@ -483,4 +484,35 @@ public class TestBasicBuilderParameters
         assertSame("ConversionHandler not set", handler, params.getParameters()
                 .get("conversionHandler"));
     }
+
+    /**
+     * Tests whether a BeanHelper can be set.
+     */
+    @Test
+    public void testSetBeanHelper()
+    {
+        BeanHelper helper = new BeanHelper();
+        assertSame("Wrong result", params, params.setBeanHelper(helper));
+        assertSame("BeanHelper not set", helper,
+                BasicBuilderParameters.fetchBeanHelper(params.getParameters()));
+    }
+
+    /**
+     * Tests fetchBeanHelper() if no helper was set.
+     */
+    @Test
+    public void testFetchBeanHelperNoSet()
+    {
+        assertNull("Got a BeanHelper",
+                BasicBuilderParameters.fetchBeanHelper(params.getParameters()));
+    }
+
+    /**
+     * Tries to invoke fetchBeanHelper() on a null map.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testFetchBeanHelperNullMap()
+    {
+        BasicBuilderParameters.fetchBeanHelper(null);
+    }
 }



Mime
View raw message