public class BeanPropertyComponentAdapter extends DecoratingComponentAdapter
SetterInjectionComponentAdapter
,
which is a true Setter Injection adapter.
This adapter is mostly handy for setting various primitive properties via setters;
it is also able to set javabean properties by discovering an appropriate
PropertyEditor
and using its setAsText
method.
Note that this class doesn't cache instances. If you want caching,
use a CachingComponentAdapter
around this one.
Modifier and Type | Field and Description |
---|---|
private java.util.Map |
properties |
private java.util.Map |
setters |
Constructor and Description |
---|
BeanPropertyComponentAdapter(ComponentAdapter delegate)
Construct a BeanPropertyComponentAdapter.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
convert(java.lang.String typeName,
java.lang.String value,
java.lang.ClassLoader classLoader)
Converts a String value of a named type to an object.
|
private java.lang.Object |
convertType(PicoContainer container,
java.lang.reflect.Method setter,
java.lang.String propertyValue) |
java.lang.Object |
getComponentInstance(PicoContainer container)
Get a component instance and set given property values.
|
private java.lang.reflect.Method[] |
getMethods(java.lang.Class clazz) |
private java.lang.String |
getPropertyName(java.lang.reflect.Method method) |
private java.lang.Object |
getSetterParameter(java.lang.String propertyName,
java.lang.Object propertyValue,
java.lang.Object componentInstance,
PicoContainer container)
Converts and validates the given property value to an appropriate object
for calling the bean's setter.
|
private java.util.Map |
getSetters(java.lang.Class clazz) |
private boolean |
isSetter(java.lang.reflect.Method method) |
void |
setProperties(java.util.Map properties)
Sets the bean property values that should be set upon creation.
|
accept, changeMonitor, currentMonitor, dispose, dispose, getComponentImplementation, getComponentKey, getDelegate, hasLifecycle, hasLifecycle, start, start, stop, stop, toString, verify
private java.util.Map properties
private transient java.util.Map setters
public BeanPropertyComponentAdapter(ComponentAdapter delegate) throws PicoInitializationException
delegate
- the wrapped ComponentAdapter
PicoInitializationException
public java.lang.Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException
getComponentInstance
in interface ComponentAdapter
getComponentInstance
in class DecoratingComponentAdapter
container
- the PicoContainer
, that is used to resolve any possible dependencies of the instance.PicoInitializationException
- if the component could not be instantiated.PicoIntrospectionException
- if the component has dependencies which could not be resolved, or
instantiation of the component lead to an ambigous situation within the
container.AssignabilityRegistrationException
NotConcreteRegistrationException
setProperties(Map)
private java.util.Map getSetters(java.lang.Class clazz)
private java.lang.reflect.Method[] getMethods(java.lang.Class clazz)
private java.lang.String getPropertyName(java.lang.reflect.Method method)
private boolean isSetter(java.lang.reflect.Method method)
private java.lang.Object convertType(PicoContainer container, java.lang.reflect.Method setter, java.lang.String propertyValue) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public static java.lang.Object convert(java.lang.String typeName, java.lang.String value, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
PropertyEditor
.typeName
- name of the typevalue
- its valueclassLoader
- used to load a class if typeName is "class" or "java.lang.Class" (ignored otherwise)java.lang.ClassNotFoundException
- if typeName is "class" or "java.lang.Class" and class couldn't be loaded.public void setProperties(java.util.Map properties)
properties
- bean propertiesprivate java.lang.Object getSetterParameter(java.lang.String propertyName, java.lang.Object propertyValue, java.lang.Object componentInstance, PicoContainer container) throws PicoInitializationException, java.lang.ClassCastException
propertyName
- String the property name on the component that
we will be setting the value to.propertyValue
- Object the property value that we've been given. It
may need conversion to be formed into the value we need for the
component instance setter.componentInstance
- the component that we're looking to provide
the setter to.PicoInitializationException
java.lang.ClassCastException