org.picocontainer.defaults
Class SetterInjectionComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.MonitoringComponentAdapter
      extended by org.picocontainer.defaults.AbstractComponentAdapter
          extended by org.picocontainer.defaults.InstantiatingComponentAdapter
              extended by org.picocontainer.defaults.SetterInjectionComponentAdapter
All Implemented Interfaces:
java.io.Serializable, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy

public class SetterInjectionComponentAdapter
extends InstantiatingComponentAdapter

Instantiates components using empty constructors and Setter Injection. For easy setting of primitive properties, also see BeanPropertyComponentAdapter.

Note that this class doesn't cache instances. If you want caching, use a CachingComponentAdapter around this one.

Version:
$Revision: 2971 $
Author:
Aslak Hellesøy, Jörg Schaible, Mauro Talevi
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.picocontainer.defaults.InstantiatingComponentAdapter
InstantiatingComponentAdapter.Guard
 
Field Summary
private  InstantiatingComponentAdapter.Guard instantiationGuard
           
private  java.util.List setterNames
           
private  java.util.List setters
           
private  java.lang.Class[] setterTypes
           
 
Fields inherited from class org.picocontainer.defaults.InstantiatingComponentAdapter
allowNonPublicClasses, lifecycleStrategy, parameters, verifyingGuard
 
Constructor Summary
SetterInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters)
          Constructs a SetterInjectionComponentAdapter with key, implementation and parameters.
SetterInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses)
          Constructs a SetterInjectionComponentAdapter with a DelegatingComponentMonitor as default.
SetterInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses, ComponentMonitor monitor)
          Constructs a SetterInjectionComponentAdapter
SetterInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses, ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy)
          Constructs a SetterInjectionComponentAdapter
 
Method Summary
 java.lang.Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
private  java.lang.reflect.Constructor getConstructor()
           
protected  java.lang.reflect.Constructor getGreediestSatisfiableConstructor(PicoContainer container)
          Find and return the greediest satisfiable constructor.
private  Parameter[] getMatchingParameterListForSetters(PicoContainer container)
           
private  java.lang.reflect.Method[] getMethods()
           
private  void initializeSetterAndTypeLists()
           
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisifed.
 
Methods inherited from class org.picocontainer.defaults.InstantiatingComponentAdapter
accept, createDefaultParameters, dispose, hasLifecycle, newInstance, start, stop
 
Methods inherited from class org.picocontainer.defaults.AbstractComponentAdapter
checkTypeCompatibility, getComponentImplementation, getComponentKey, toString
 
Methods inherited from class org.picocontainer.defaults.MonitoringComponentAdapter
changeMonitor, currentMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

instantiationGuard

private transient InstantiatingComponentAdapter.Guard instantiationGuard

setters

private transient java.util.List setters

setterNames

private transient java.util.List setterNames

setterTypes

private transient java.lang.Class[] setterTypes
Constructor Detail

SetterInjectionComponentAdapter

public SetterInjectionComponentAdapter(java.lang.Object componentKey,
                                       java.lang.Class componentImplementation,
                                       Parameter[] parameters,
                                       boolean allowNonPublicClasses,
                                       ComponentMonitor monitor,
                                       LifecycleStrategy lifecycleStrategy)
                                throws AssignabilityRegistrationException,
                                       NotConcreteRegistrationException
Constructs a SetterInjectionComponentAdapter

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
allowNonPublicClasses - flag to allow instantiation of non-public classes.
monitor - the component monitor used by this adapter
lifecycleStrategy - the component lifecycle strategy used by this adapter
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
NotConcreteRegistrationException - if the implementation is not a concrete class.
java.lang.NullPointerException - if one of the parameters is null

SetterInjectionComponentAdapter

public SetterInjectionComponentAdapter(java.lang.Object componentKey,
                                       java.lang.Class componentImplementation,
                                       Parameter[] parameters,
                                       boolean allowNonPublicClasses,
                                       ComponentMonitor monitor)
                                throws AssignabilityRegistrationException,
                                       NotConcreteRegistrationException
Constructs a SetterInjectionComponentAdapter

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
allowNonPublicClasses - flag to allow instantiation of non-public classes.
monitor - the component monitor used by this adapter
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
NotConcreteRegistrationException - if the implementation is not a concrete class.
java.lang.NullPointerException - if one of the parameters is null

SetterInjectionComponentAdapter

public SetterInjectionComponentAdapter(java.lang.Object componentKey,
                                       java.lang.Class componentImplementation,
                                       Parameter[] parameters,
                                       boolean allowNonPublicClasses)
                                throws AssignabilityRegistrationException,
                                       NotConcreteRegistrationException
Constructs a SetterInjectionComponentAdapter with a DelegatingComponentMonitor as default.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
allowNonPublicClasses - flag to allow instantiation of non-public classes.
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
NotConcreteRegistrationException - if the implementation is not a concrete class.
java.lang.NullPointerException - if one of the parameters is null

SetterInjectionComponentAdapter

public SetterInjectionComponentAdapter(java.lang.Object componentKey,
                                       java.lang.Class componentImplementation,
                                       Parameter[] parameters)
                                throws AssignabilityRegistrationException,
                                       NotConcreteRegistrationException
Constructs a SetterInjectionComponentAdapter with key, implementation and parameters.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
NotConcreteRegistrationException - if the implementation is not a concrete class.
java.lang.NullPointerException - if one of the parameters is null
Method Detail

getGreediestSatisfiableConstructor

protected java.lang.reflect.Constructor getGreediestSatisfiableConstructor(PicoContainer container)
                                                                    throws PicoIntrospectionException,
                                                                           UnsatisfiableDependenciesException,
                                                                           AmbiguousComponentResolutionException,
                                                                           AssignabilityRegistrationException,
                                                                           NotConcreteRegistrationException
Description copied from class: InstantiatingComponentAdapter
Find and return the greediest satisfiable constructor.

Specified by:
getGreediestSatisfiableConstructor in class InstantiatingComponentAdapter
Parameters:
container - the PicoContainer to resolve dependencies.
Returns:
the found constructor.
Throws:
PicoIntrospectionException
UnsatisfiableDependenciesException
AmbiguousComponentResolutionException
AssignabilityRegistrationException
NotConcreteRegistrationException

getConstructor

private java.lang.reflect.Constructor getConstructor()
                                              throws PicoInvocationTargetInitializationException
Throws:
PicoInvocationTargetInitializationException

getMatchingParameterListForSetters

private Parameter[] getMatchingParameterListForSetters(PicoContainer container)
                                                throws PicoInitializationException,
                                                       UnsatisfiableDependenciesException
Throws:
PicoInitializationException
UnsatisfiableDependenciesException

getComponentInstance

public java.lang.Object getComponentInstance(PicoContainer container)
                                      throws PicoInitializationException,
                                             PicoIntrospectionException,
                                             AssignabilityRegistrationException,
                                             NotConcreteRegistrationException
Description copied from interface: ComponentAdapter
Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, CachingComponentAdapter will always return the same instance.

Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Returns:
the component instance.
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

verify

public void verify(PicoContainer container)
            throws PicoIntrospectionException
Description copied from interface: ComponentAdapter
Verify that all dependencies for this adapter can be satisifed. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependnecies.

Specified by:
verify in interface ComponentAdapter
Overrides:
verify in class InstantiatingComponentAdapter
Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Throws:
PicoIntrospectionException - if one or more dependencies cannot be resolved.

initializeSetterAndTypeLists

private void initializeSetterAndTypeLists()

getMethods

private java.lang.reflect.Method[] getMethods()