org.apache.commons.configuration.beanutils

Class DefaultBeanFactory

public class DefaultBeanFactory extends Object implements BeanFactory

The default implementation of the BeanFactory interface.

This class creates beans of arbitrary types using reflection. Each time the createBean() method is invoked, a new bean instance is created. A default bean class is not supported.

An instance of this factory class will be set as the default bean factory for the BeanHelper class. This means that if not bean factory is specified in a BeanDeclaration, this default instance will be used.

Since: 1.3

Version: $Id: DefaultBeanFactory.java 439648 2006-09-02 20:42:10Z oheger $

Author: Oliver Heger

Field Summary
static DefaultBeanFactoryINSTANCE
Stores the default instance of this class.
Method Summary
ObjectcreateBean(Class beanClass, BeanDeclaration data, Object parameter)
Creates a new bean instance.
protected ObjectcreateBeanInstance(Class beanClass, BeanDeclaration data)
Creates the bean instance.
ClassgetDefaultBeanClass()
Returns the default bean class used by this factory.
protected voidinitBeanInstance(Object bean, BeanDeclaration data)
Initializes the newly created bean instance.

Field Detail

INSTANCE

public static final DefaultBeanFactory INSTANCE
Stores the default instance of this class.

Method Detail

createBean

public Object createBean(Class beanClass, BeanDeclaration data, Object parameter)
Creates a new bean instance. This implementation delegates to the protected methods createBeanInstance() and initBeanInstance() for creating and initializing the bean. This makes it easier for derived classes that need to change specific functionality of the base class.

Parameters: beanClass the class of the bean, from which an instance is to be created data the bean declaration object parameter an additional parameter (ignored by this implementation)

Returns: the new bean instance

Throws: Exception if an error occurs

createBeanInstance

protected Object createBeanInstance(Class beanClass, BeanDeclaration data)
Creates the bean instance. This method is called by createBean(). It uses reflection to create a new instance of the specified class.

Parameters: beanClass the class of the bean to be created data the bean declaration

Returns: the new bean instance

Throws: Exception if an error occurs

getDefaultBeanClass

public Class getDefaultBeanClass()
Returns the default bean class used by this factory. This is always null for this implementation.

Returns: the default bean class

initBeanInstance

protected void initBeanInstance(Object bean, BeanDeclaration data)
Initializes the newly created bean instance. This method is called by createBean(). It calls the initBean() of BeanHelper for performing the initialization.

Parameters: bean the newly created bean instance data the bean declaration object

Throws: Exception if an error occurs