org.apache.commons.configuration.beanutils
public class BeanHelper extends Object
A helper class for creating bean instances that are defined in configuration files.
This class provides static utility methods related to bean creation operations. These methods simplify such operations because a client need not deal with all involved interfaces. Usually, if a bean declaration has already been obtained, a single method call is necessary to create a new bean instance.
This class also supports the registration of custom bean factories.
Implementations of the BeanFactory
interface can be
registered under a symbolic name using the registerBeanFactory()
method. In the configuration file the name of the bean factory can be
specified in the bean declaration. Then this factory will be used to create
the bean.
Since: 1.3
Version: $Id: BeanHelper.java 508152 2007-02-15 21:16:37Z oheger $
Field Summary | |
---|---|
static Map | beanFactories Stores a map with the registered bean factories. |
static BeanFactory | defaultBeanFactory
Stores the default bean factory, which will be used if no other factory
is provided. |
Constructor Summary | |
---|---|
BeanHelper()
Private constructor, so no instances can be created. |
Method Summary | |
---|---|
static Object | createBean(BeanDeclaration data, Class defaultClass, Object param)
The main method for creating and initializing beans from a configuration.
|
static Object | createBean(BeanDeclaration data, Class defaultClass)
Returns a bean instance for the specified declaration. |
static Object | createBean(BeanDeclaration data)
Returns a bean instance for the specified declaration. |
static BeanFactory | deregisterBeanFactory(String name)
Deregisters the bean factory with the given name. |
static Class | fetchBeanClass(BeanDeclaration data, Class defaultClass, BeanFactory factory)
Determines the class of the bean to be created. |
static BeanFactory | fetchBeanFactory(BeanDeclaration data)
Obtains the bean factory to use for creating the specified bean. |
static BeanFactory | getDefaultBeanFactory()
Returns the default bean factory.
|
static void | initBean(Object bean, BeanDeclaration data)
Initializes the passed in bean. |
static void | initProperty(Object bean, String propName, Object value)
Sets a property on the given bean using Common Beanutils.
|
static Class | loadClass(String name, Class callingClass)
Returns a java.lang.Class object for the specified name.
|
static void | registerBeanFactory(String name, BeanFactory factory)
Register a bean factory under a symbolic name. |
static Set | registeredFactoryNames()
Returns a set with the names of all currently registered bean factories.
|
static void | setDefaultBeanFactory(BeanFactory factory)
Sets the default bean factory. |
Parameters: data the bean declaration defaultClass the default class to use param an additional parameter that will be passed to the bean factory; some factories may support parameters and behave different depending on the value passed in here
Returns: the new bean
Throws: ConfigurationRuntimeException if an error occurs
createBean(data, null, null);
.
Parameters: data the bean declaration defaultClass the class to be used when in the declation no class is specified
Returns: the new bean
Throws: ConfigurationRuntimeException if an error occurs
createBean(data, null);
.
Parameters: data the bean declaration
Returns: the new bean
Throws: ConfigurationRuntimeException if an error occurs
Parameters: name the name of the factory to be deregistered
Returns: the factory that was registered under this name; null if there was no such factory
Parameters: data the bean declaration defaultClass the default class factory the bean factory to use
Returns: the class of the bean to be created
Throws: ConfigurationRuntimeException if the class cannot be determined
Parameters: data the bean declaration
Returns: the bean factory to use
Throws: ConfigurationRuntimeException if the factory cannot be determined
Returns: the default bean factory
Parameters: bean the bean to be initialized data the bean declaration
Throws: ConfigurationRuntimeException if a property cannot be set
Parameters: bean the bean propName the name of the property value the property's value
Throws: ConfigurationRuntimeException if the property is not writeable or an error occurred
java.lang.Class
object for the specified name.
This method and the helper method it invokes are very similar to code
extracted from the ClassLoaderUtils
class of Commons
Jelly. It should be replaced if Commons Lang provides a generic version.
Parameters: name the name of the class to be loaded callingClass the calling class
Returns: the class object for the specified name
Throws: ClassNotFoundException if the class cannot be loaded
Parameters: name the name of the factory factory the factory to be registered
Returns: a set with the names of the registered bean factories
Parameters: factory the default bean factory (must not be null)