org.picocontainer.defaults
Class ConstructorInjectionComponentAdapter

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.ConstructorInjectionComponentAdapter
All Implemented Interfaces:
java.io.Serializable, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy

public class ConstructorInjectionComponentAdapter
extends InstantiatingComponentAdapter

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

Version:
$Revision: 2971 $
Author:
Paul Hammant, Aslak Hellesøy, Jon Tirsén, Zohar Melamed, Jörg Schaible, Mauro Talevi
See Also:
Serialized Form

Nested Class Summary
private static class ConstructorInjectionComponentAdapter.Guard
           
 
Field Summary
private  ConstructorInjectionComponentAdapter.Guard instantiationGuard
           
private  java.util.List sortedMatchingConstructors
           
 
Fields inherited from class org.picocontainer.defaults.InstantiatingComponentAdapter
allowNonPublicClasses, lifecycleStrategy, parameters, verifyingGuard
 
Constructor Summary
ConstructorInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation)
          Creates a ConstructorInjectionComponentAdapter with key and implementation
ConstructorInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters)
          Creates a ConstructorInjectionComponentAdapter with key, implementation and parameters
ConstructorInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses)
          Creates a ConstructorInjectionComponentAdapter
ConstructorInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses, ComponentMonitor monitor)
          Creates a ConstructorInjectionComponentAdapter
ConstructorInjectionComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses, ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy)
          Creates a ConstructorInjectionComponentAdapter
 
Method Summary
 java.lang.Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
protected  java.lang.Object[] getConstructorArguments(PicoContainer container, java.lang.reflect.Constructor ctor)
           
private  java.lang.reflect.Constructor[] getConstructors()
           
protected  java.lang.reflect.Constructor getGreediestSatisfiableConstructor(PicoContainer container)
          Find and return the greediest satisfiable constructor.
private  java.util.List getSortedMatchingConstructors()
           
 
Methods inherited from class org.picocontainer.defaults.InstantiatingComponentAdapter
accept, createDefaultParameters, dispose, hasLifecycle, newInstance, start, stop, verify
 
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

sortedMatchingConstructors

private transient java.util.List sortedMatchingConstructors

instantiationGuard

private transient ConstructorInjectionComponentAdapter.Guard instantiationGuard
Constructor Detail

ConstructorInjectionComponentAdapter

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

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

ConstructorInjectionComponentAdapter

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

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

ConstructorInjectionComponentAdapter

public ConstructorInjectionComponentAdapter(java.lang.Object componentKey,
                                            java.lang.Class componentImplementation,
                                            Parameter[] parameters,
                                            boolean allowNonPublicClasses)
                                     throws AssignabilityRegistrationException,
                                            NotConcreteRegistrationException
Creates a ConstructorInjectionComponentAdapter

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

ConstructorInjectionComponentAdapter

public ConstructorInjectionComponentAdapter(java.lang.Object componentKey,
                                            java.lang.Class componentImplementation,
                                            Parameter[] parameters)
Creates a ConstructorInjectionComponentAdapter 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

ConstructorInjectionComponentAdapter

public ConstructorInjectionComponentAdapter(java.lang.Object componentKey,
                                            java.lang.Class componentImplementation)
                                     throws AssignabilityRegistrationException,
                                            NotConcreteRegistrationException
Creates a ConstructorInjectionComponentAdapter with key and implementation

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
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

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

getConstructorArguments

protected java.lang.Object[] getConstructorArguments(PicoContainer container,
                                                     java.lang.reflect.Constructor ctor)

getSortedMatchingConstructors

private java.util.List getSortedMatchingConstructors()

getConstructors

private java.lang.reflect.Constructor[] getConstructors()