Package org.picocontainer.behaviors
Class PropertyApplicator<T>
- java.lang.Object
-
- org.picocontainer.behaviors.AbstractBehavior<T>
-
- org.picocontainer.behaviors.PropertyApplicator<T>
-
- All Implemented Interfaces:
java.io.Serializable
,Behavior<T>
,ComponentAdapter<T>
,ComponentLifecycle<T>
,ComponentMonitorStrategy
,LifecycleStrategy
public class PropertyApplicator<T> extends AbstractBehavior<T>
Decorating component adapter that can be used to set additional properties on a component in a bean style. These properties must be managed manually by the user of the API, and will not be managed by PicoContainer. This class is therefore not the same asSetterInjector
, 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 appropriatePropertyEditor
and using itssetAsText
method. Note that this class doesn't cache instances. If you want caching, use aCached
around this one.- Author:
- Aslak Hellesøy, Mauro Talevi
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
-
-
Field Summary
-
Fields inherited from class org.picocontainer.behaviors.AbstractBehavior
delegate
-
-
Constructor Summary
Constructors Constructor Description PropertyApplicator(ComponentAdapter<T> delegate)
Construct a PropertyApplicator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.T
getComponentInstance(PicoContainer container, java.lang.reflect.Type into)
Get a component instance and set given property values.java.lang.String
getDescriptor()
Get a string key descriptor of the component adapter for use in toString()void
setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Sets the bean property values that should be set upon creation.void
setProperty(java.lang.String name, java.lang.String value)
-
Methods inherited from class org.picocontainer.behaviors.AbstractBehavior
accept, changeMonitor, componentHasLifecycle, currentMonitor, dispose, dispose, findAdapterOfType, getComponentImplementation, getComponentInstance, getComponentKey, getDelegate, hasLifecycle, isLazy, isStarted, start, start, stop, stop, toString, verify
-
-
-
-
Constructor Detail
-
PropertyApplicator
public PropertyApplicator(ComponentAdapter<T> delegate) throws PicoCompositionException
Construct a PropertyApplicator.- Parameters:
delegate
- the wrappedComponentAdapter
- Throws:
PicoCompositionException
-
-
Method Detail
-
getComponentInstance
public T getComponentInstance(PicoContainer container, java.lang.reflect.Type into) throws PicoCompositionException
Get a component instance and set given property values.- Specified by:
getComponentInstance
in interfaceComponentAdapter<T>
- Overrides:
getComponentInstance
in classAbstractBehavior<T>
- Parameters:
container
- thePicoContainer
, that is used to resolve any possible dependencies of the instance.into
- the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.- Returns:
- the component instance with any properties of the properties map set.
- Throws:
PicoCompositionException
- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.PicoCompositionException
- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.PicoCompositionException
- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.- See Also:
setProperties(Map)
-
getDescriptor
public java.lang.String getDescriptor()
Description copied from interface:ComponentAdapter
Get a string key descriptor of the component adapter for use in toString()- Returns:
- the descriptor
-
convert
public 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. Works with primitive wrappers, String, File, URL types, or any type that has an appropriatePropertyEditor
.- Parameters:
typeName
- name of the typevalue
- its valueclassLoader
- used to load a class if typeName is "class" or "java.lang.Class" (ignored otherwise)- Returns:
- instantiated object or null if the type was unknown/unsupported
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Sets the bean property values that should be set upon creation.- Parameters:
properties
- bean properties
-
setProperty
public void setProperty(java.lang.String name, java.lang.String value)
-
-