commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1520795 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/beanutils/ main/java/org/apache/commons/configuration/builder/ main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apac...
Date Sat, 07 Sep 2013 19:43:48 GMT
Author: oheger
Date: Sat Sep  7 19:43:47 2013
New Revision: 1520795

URL: http://svn.apache.org/r1520795
Log:
BeanHelper now provides a shared default instance.

This instance can be used by an application if no special configuration is
needed. All references to BeanHelper's static methods (which occurred
exclusively in builder classes) were changed to use this default instance.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java?rev=1520795&r1=1520794&r2=1520795&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
Sat Sep  7 19:43:47 2013
@@ -69,6 +69,14 @@ import org.apache.commons.lang3.ClassUti
  */
 public final class BeanHelper
 {
+    /**
+     * A default instance of {@code BeanHelper} which can be shared between
+     * arbitrary components. If no special configuration is needed, this
+     * instance can be used throughout an application. Otherwise, new instances
+     * can be created with their own configuration.
+     */
+    public static final BeanHelper INSTANCE = new BeanHelper();
+
     /** Stores a map with the registered bean factories. */
     private final Map<String, BeanFactory> BEAN_FACTORIES = Collections
             .synchronizedMap(new HashMap<String, BeanFactory>());

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=1520795&r1=1520794&r2=1520795&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:43:47 2013
@@ -469,7 +469,7 @@ public class BasicConfigurationBuilder<T
      */
     protected T createResultInstance() throws ConfigurationException
     {
-        Object bean = BeanHelper.createBean(getResultDeclaration());
+        Object bean = fetchBeanHelper().createBean(getResultDeclaration());
         checkResultInstance(bean);
         return getResultClass().cast(bean);
     }
@@ -487,7 +487,7 @@ public class BasicConfigurationBuilder<T
      */
     protected void initResultInstance(T obj) throws ConfigurationException
     {
-        BeanHelper.initBean(obj, getResultDeclaration());
+        fetchBeanHelper().initBean(obj, getResultDeclaration());
         registerEventListeners(obj);
         handleInitializable(obj);
     }
@@ -529,6 +529,20 @@ public class BasicConfigurationBuilder<T
     }
 
     /**
+     * Obtains the {@code BeanHelper} object to be used when dealing with bean
+     * declarations. This method checks whether this builder was configured with
+     * a specific {@code BeanHelper} instance. If so, this instance is used.
+     * Otherwise, the default {@code BeanHelper} is returned.
+     *
+     * @return the {@code BeanHelper} to be used
+     */
+    protected final BeanHelper fetchBeanHelper()
+    {
+        // TODO support configuration of a BeanHelper
+        return BeanHelper.INSTANCE;
+    }
+
+    /**
      * Creates a new {@code BeanDeclaration} which is used for creating new
      * result objects dynamically. This implementation creates a specialized
      * {@code BeanDeclaration} object that is initialized from the given map of

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java?rev=1520795&r1=1520794&r2=1520795&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/BaseConfigurationBuilderProvider.java
Sat Sep  7 19:43:47 2013
@@ -25,7 +25,6 @@ import java.util.Map;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.ConfigurationUtils;
-import org.apache.commons.configuration.beanutils.BeanHelper;
 import org.apache.commons.configuration.builder.BasicConfigurationBuilder;
 import org.apache.commons.configuration.builder.BuilderParameters;
 import org.apache.commons.configuration.builder.ConfigurationBuilder;
@@ -245,7 +244,7 @@ public class BaseConfigurationBuilderPro
     {
         inheritParentBuilderProperties(decl, params);
         MultiWrapDynaBean wrapBean = new MultiWrapDynaBean(params);
-        BeanHelper.initBean(wrapBean, decl);
+        decl.getConfigurationBuilder().initBean(wrapBean, decl);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java?rev=1520795&r1=1520794&r2=1520795&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilder.java
Sat Sep  7 19:43:47 2013
@@ -860,7 +860,7 @@ public class CombinedConfigurationBuilde
         {
             XMLBeanDeclaration decl = new XMLBeanDeclaration(config);
             String key = config.getString(KEY_LOOKUP_KEY);
-            Lookup lookup = (Lookup) BeanHelper.createBean(decl);
+            Lookup lookup = (Lookup) fetchBeanHelper().createBean(decl);
             lookups.put(key, lookup);
         }
 
@@ -892,7 +892,7 @@ public class CombinedConfigurationBuilde
         {
             XMLBeanDeclaration decl =
                     new XMLBeanDeclaration(config, FILE_SYSTEM);
-            return (FileSystem) BeanHelper.createBean(decl);
+            return (FileSystem) fetchBeanHelper().createBean(decl);
         }
         return null;
     }
@@ -942,7 +942,7 @@ public class CombinedConfigurationBuilde
             XMLBeanDeclaration decl =
                     new XMLBeanDeclaration(config, KEY_ENTITY_RESOLVER, true);
             EntityResolver resolver =
-                    (EntityResolver) BeanHelper.createBean(decl,
+                    (EntityResolver) fetchBeanHelper().createBean(decl,
                             CatalogResolver.class);
             FileSystem fileSystem = xmlParams.getFileHandler().getFileSystem();
             if (fileSystem != null)
@@ -1038,6 +1038,20 @@ public class CombinedConfigurationBuilde
     }
 
     /**
+     * Initializes a bean using the current {@code BeanHelper}. This is needed
+     * by builder providers when the configuration objects for sub builders are
+     * constructed.
+     *
+     * @param bean the bean to be initialized
+     * @param decl the {@code BeanDeclaration}
+     */
+    void initBean(Object bean, BeanDeclaration decl)
+    {
+        fetchBeanHelper().initBean(bean, decl);
+        ;
+    }
+
+    /**
      * Initializes the current parameters object. This object has either been
      * passed at builder configuration time or it is newly created. In any
      * case, it is manipulated during result creation.
@@ -1261,7 +1275,7 @@ public class CombinedConfigurationBuilde
             XMLBeanDeclaration decl = new XMLBeanDeclaration(config);
             String key = config.getString(KEY_PROVIDER_KEY);
             currentParameters.registerProvider(key,
-                    (ConfigurationBuilderProvider) BeanHelper.createBean(decl));
+                    (ConfigurationBuilderProvider) fetchBeanHelper().createBean(decl));
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java?rev=1520795&r1=1520794&r2=1520795&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
Sat Sep  7 19:43:47 2013
@@ -90,6 +90,17 @@ public class TestBeanHelper
     }
 
     /**
+     * Tests the default instance of BeanHelper.
+     */
+    @Test
+    public void testDefaultInstance()
+    {
+        assertSame("Wrong factory for default instance",
+                DefaultBeanFactory.INSTANCE,
+                BeanHelper.INSTANCE.getDefaultBeanFactory());
+    }
+
+    /**
      * Tests that a newly created instance does not have any bean factories
      * registered.
      */



Mime
View raw message