Class DefaultBeanFactory
- java.lang.Object
-
- org.apache.commons.configuration.beanutils.DefaultBeanFactory
-
- All Implemented Interfaces:
BeanFactory
- Direct Known Subclasses:
DefaultConfigurationBuilder.ConfigurationProvider
public class DefaultBeanFactory extends java.lang.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 aBeanDeclaration
, this default instance will be used.- Since:
- 1.3
- Version:
- $Id: DefaultBeanFactory.java 1208758 2011-11-30 20:38:59Z oheger $
- Author:
- Commons Configuration team
-
-
Field Summary
Fields Modifier and Type Field Description static DefaultBeanFactory
INSTANCE
Stores the default instance of this class.
-
Constructor Summary
Constructors Constructor Description DefaultBeanFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
createBean(java.lang.Class<?> beanClass, BeanDeclaration data, java.lang.Object parameter)
Creates a new bean instance.protected java.lang.Object
createBeanInstance(java.lang.Class<?> beanClass, BeanDeclaration data)
Creates the bean instance.java.lang.Class<?>
getDefaultBeanClass()
Returns the default bean class used by this factory.protected void
initBeanInstance(java.lang.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.
-
-
Constructor Detail
-
DefaultBeanFactory
public DefaultBeanFactory()
-
-
Method Detail
-
createBean
public java.lang.Object createBean(java.lang.Class<?> beanClass, BeanDeclaration data, java.lang.Object parameter) throws java.lang.Exception
Creates a new bean instance. This implementation delegates to the protected methodscreateBeanInstance()
andinitBeanInstance()
for creating and initializing the bean. This makes it easier for derived classes that need to change specific functionality of the base class.- Specified by:
createBean
in interfaceBeanFactory
- Parameters:
beanClass
- the class of the bean, from which an instance is to be createddata
- the bean declaration objectparameter
- an additional parameter (ignored by this implementation)- Returns:
- the new bean instance
- Throws:
java.lang.Exception
- if an error occurs
-
getDefaultBeanClass
public java.lang.Class<?> getDefaultBeanClass()
Returns the default bean class used by this factory. This is always null for this implementation.- Specified by:
getDefaultBeanClass
in interfaceBeanFactory
- Returns:
- the default bean class
-
createBeanInstance
protected java.lang.Object createBeanInstance(java.lang.Class<?> beanClass, BeanDeclaration data) throws java.lang.Exception
Creates the bean instance. This method is called bycreateBean()
. It uses reflection to create a new instance of the specified class.- Parameters:
beanClass
- the class of the bean to be createddata
- the bean declaration- Returns:
- the new bean instance
- Throws:
java.lang.Exception
- if an error occurs
-
initBeanInstance
protected void initBeanInstance(java.lang.Object bean, BeanDeclaration data) throws java.lang.Exception
Initializes the newly created bean instance. This method is called bycreateBean()
. It calls theinitBean()
ofBeanHelper
for performing the initialization.- Parameters:
bean
- the newly created bean instancedata
- the bean declaration object- Throws:
java.lang.Exception
- if an error occurs
-
-