commons-commits mailing list archives

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

URL: http://svn.apache.org/r1520801
Log:
Configuration builders now use the configured BeanHelper instance.

BasicConfigurationBuilder's fetchBeanHelper() was rewritten to obtain a
BeanHelper object from configuration parameters. If one is found, it is used.
Otherwise, the default BeanHelper instance is used. Configuration builders use
the BeanHelper for creating their result configurations. Some builders also
create additional objects dynamically.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1520801&r1=1520800&r2=1520801&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
Sat Sep  7 19:46:40 2013
@@ -538,8 +538,9 @@ public class BasicConfigurationBuilder<T
      */
     protected final BeanHelper fetchBeanHelper()
     {
-        // TODO support configuration of a BeanHelper
-        return BeanHelper.INSTANCE;
+        BeanHelper helper =
+                BasicBuilderParameters.fetchBeanHelper(getParameters());
+        return (helper != null) ? helper : BeanHelper.INSTANCE;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java?rev=1520801&r1=1520800&r2=1520801&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Sat Sep  7 19:46:40 2013
@@ -38,7 +38,11 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.Initializable;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.beanutils.BeanCreationContext;
 import org.apache.commons.configuration.beanutils.BeanDeclaration;
+import org.apache.commons.configuration.beanutils.BeanFactory;
+import org.apache.commons.configuration.beanutils.BeanHelper;
+import org.apache.commons.configuration.beanutils.DefaultBeanFactory;
 import org.apache.commons.configuration.beanutils.XMLBeanDeclaration;
 import org.apache.commons.configuration.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration.convert.ListDelimiterHandler;
@@ -540,6 +544,32 @@ public class TestBasicConfigurationBuild
     }
 
     /**
+     * Tests whether a configured BeanHelper is used for result creation.
+     */
+    @Test
+    public void testBeanHelperInConfiguration() throws ConfigurationException
+    {
+        final Set<Class<?>> classesPassedToFactory = new HashSet<Class<?>>();
+        BeanFactory factory = new DefaultBeanFactory()
+        {
+            @Override
+            public Object createBean(BeanCreationContext bcc) throws Exception
+            {
+                classesPassedToFactory.add(bcc.getBeanClass());
+                return super.createBean(bcc);
+            }
+        };
+        BeanHelper helper = new BeanHelper(factory);
+        BasicConfigurationBuilder<PropertiesConfiguration> builder =
+                new BasicConfigurationBuilder<PropertiesConfiguration>(
+                        PropertiesConfiguration.class);
+        builder.configure(new BasicBuilderParameters().setBeanHelper(helper));
+        PropertiesConfiguration config = builder.getConfiguration();
+        assertTrue("BeanFactory was not used correctly",
+                classesPassedToFactory.contains(config.getClass()));
+    }
+
+    /**
      * A test thread class for testing whether the builder's result object can
      * be requested concurrently.
      */



Mime
View raw message