public class CustomizableBeanWrapperFactory extends Object implements BeanWrapperFactory
A BeanWrapper uses the same BeanWrapperFactory to create the BeanWrapperContexts for its nested BeanWrappers. BeanWrapperFactory can also be used as an umbrella to create BeanWrappers in a more performant way as it caches the introspection information and re-uses it whenever possible.
Constructor and Description |
---|
CustomizableBeanWrapperFactory() |
Modifier and Type | Method and Description |
---|---|
BeanInstanceBuilder |
getBeanInstanceBuilder()
Obtains the builder that will be used to create bean instances every time a bean instantiation is needed.
|
JuffrouBeanWrapper |
getBeanWrapper(Class clazz)
Construct a bean wrapper around a class.
|
JuffrouBeanWrapper |
getBeanWrapper(Object instance)
Construct a bean wrapper around an existing bean instance.
|
BeanWrapperContext |
getBeanWrapperContext(Class clazz)
Retrieves a BeanWrapperContext for java bean class.
|
BeanWrapperContext |
getBeanWrapperContext(Class clazz,
Type... types)
Retrieves a BeanWrapperContext for a parameterized (generic) java bean
class.
|
void |
setBeanContextBuilder(BeanContextBuilder beanContextBuilder)
Control the creation of BeanWrapperContexts.
|
void |
setBeanInstanceBuilder(BeanInstanceBuilder beanInstanceBuilder)
Control the instantiation of beans and wrapped beans.
|
public BeanWrapperContext getBeanWrapperContext(Class clazz)
If the BeanWrapperContext is not in cache then creates a new one.
getBeanWrapperContext
in interface BeanWrapperFactory
clazz
- the bean class to inspectpublic BeanWrapperContext getBeanWrapperContext(Class clazz, Type... types)
If the BeanWrapperContext is not in cache then creates a new one.
getBeanWrapperContext
in interface BeanWrapperFactory
clazz
- the generic bean class to inspect.types
- the parameters that defined the generic bean class.public JuffrouBeanWrapper getBeanWrapper(Class clazz)
Bean instances will be instances of that class and will be created only
when necessary.
Try to use a cached BeanWrapperContext to save introspection time.
getBeanWrapper
in interface BeanWrapperFactory
clazz
- class to instantiate the wrapped beanJuffrouBeanWrapper.setValue(String, Object)
or JuffrouBeanWrapper.getBean()
public JuffrouBeanWrapper getBeanWrapper(Object instance)
Will try to use a cached BeanWrapperContext to save introspection time.
getBeanWrapper
in interface BeanWrapperFactory
instance
- the bean object to be wrappedpublic BeanInstanceBuilder getBeanInstanceBuilder()
BeanWrapperFactory
getBeanInstanceBuilder
in interface BeanWrapperFactory
public void setBeanInstanceBuilder(BeanInstanceBuilder beanInstanceBuilder)
The bean wrapper creates new instances using Class.newIntance() by default. You can use this this if you want to create class instances yourself.
beanInstanceBuilder
- the builder that will be used to create bean instances every time a bean instantiation is needed.public void setBeanContextBuilder(BeanContextBuilder beanContextBuilder)
Provide a custom BeanContextBuilder that will instantiate your custom BeanWrapperContext. This way you can extend the BeanWrapperContext class and attach more information to a bean.
beanContextBuilder
- an instance of BeanContextBuilder to be called when a new bean
instance is requiredCopyright © 2011–2020 Juffrou. All rights reserved.