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
interface can be
registered under a symbolic name using the BeanFactory
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.
Modifier and Type | Method and Description |
---|---|
static Object |
createBean(BeanDeclaration data)
Returns a bean instance for the specified declaration.
|
static Object |
createBean(BeanDeclaration data,
Class defaultClass)
Returns a bean instance for the specified declaration.
|
static Object |
createBean(BeanDeclaration data,
Class defaultClass,
Object param)
The main method for creating and initializing beans from a configuration.
|
static BeanFactory |
deregisterBeanFactory(String name)
Deregisters the bean factory with the given name.
|
static BeanFactory |
getDefaultBeanFactory()
Returns the default bean factory.
|
static void |
initBean(Object bean,
BeanDeclaration data)
Initializes the passed in bean.
|
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.
|
public static void registerBeanFactory(String name, BeanFactory factory)
name
- the name of the factoryfactory
- the factory to be registeredpublic static BeanFactory deregisterBeanFactory(String name)
name
- the name of the factory to be deregisteredpublic static Set registeredFactoryNames()
public static BeanFactory getDefaultBeanFactory()
public static void setDefaultBeanFactory(BeanFactory factory)
factory
- the default bean factory (must not be null)public static void initBean(Object bean, BeanDeclaration data) throws ConfigurationRuntimeException
bean
- the bean to be initializeddata
- the bean declarationConfigurationRuntimeException
- if a property cannot be setpublic static Object createBean(BeanDeclaration data, Class defaultClass, Object param) throws ConfigurationRuntimeException
data
- the bean declarationdefaultClass
- the default class to useparam
- 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 hereConfigurationRuntimeException
- if an error occurspublic static Object createBean(BeanDeclaration data, Class defaultClass) throws ConfigurationRuntimeException
createBean(data, null, null);
.data
- the bean declarationdefaultClass
- the class to be used when in the declation no class
is specifiedConfigurationRuntimeException
- if an error occurspublic static Object createBean(BeanDeclaration data) throws ConfigurationRuntimeException
createBean(data, null);
.data
- the bean declarationConfigurationRuntimeException
- if an error occursCopyright © 2018 JBoss by Red Hat. All rights reserved.