org.picocontainer.defaults
Class BeanPropertyComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.DecoratingComponentAdapter
      extended by org.picocontainer.defaults.BeanPropertyComponentAdapter
All Implemented Interfaces:
Serializable, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy, LifecycleManager

public class BeanPropertyComponentAdapter
extends DecoratingComponentAdapter

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 as 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.

Since:
1.0
Version:
$Revision: 2793 $
Author:
Aslak Hellesøy
See Also:
Serialized Form

Constructor Summary
BeanPropertyComponentAdapter(ComponentAdapter delegate)
          Construct a BeanPropertyComponentAdapter.
 
Method Summary
static Object convert(String typeName, String value, ClassLoader classLoader)
          Converts a String value of a named type to an object.
 Object getComponentInstance(PicoContainer container)
          Get a component instance and set given property values.
 void setProperties(Map properties)
          Sets the bean property values that should be set upon creation.
 
Methods inherited from class org.picocontainer.defaults.DecoratingComponentAdapter
accept, changeMonitor, currentMonitor, dispose, dispose, getComponentImplementation, getComponentKey, getDelegate, hasLifecycle, hasLifecycle, start, start, stop, stop, toString, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeanPropertyComponentAdapter

public BeanPropertyComponentAdapter(ComponentAdapter delegate)
                             throws PicoInitializationException
Construct a BeanPropertyComponentAdapter.

Parameters:
delegate - the wrapped ComponentAdapter
Throws:
PicoInitializationException
Method Detail

getComponentInstance

public Object getComponentInstance(PicoContainer container)
                            throws PicoInitializationException,
                                   PicoIntrospectionException,
                                   AssignabilityRegistrationException,
                                   NotConcreteRegistrationException
Get a component instance and set given property values.

Specified by:
getComponentInstance in interface ComponentAdapter
Overrides:
getComponentInstance in class DecoratingComponentAdapter
Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Returns:
the component instance with any properties of the properties map set.
Throws:
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
See Also:
setProperties(Map)

convert

public static Object convert(String typeName,
                             String value,
                             ClassLoader classLoader)
                      throws ClassNotFoundException
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 appropriate PropertyEditor.

Parameters:
typeName - name of the type
value - its value
classLoader - 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
Throws:
ClassNotFoundException - if typeName is "class" or "java.lang.Class" and class couldn't be loaded.

setProperties

public void setProperties(Map properties)
Sets the bean property values that should be set upon creation.

Parameters:
properties - bean properties


Copyright © 2003-2007 Codehaus. All Rights Reserved.