org.picocontainer.injectors
Class ConstructorInjector<T>

java.lang.Object
  extended by org.picocontainer.adapters.AbstractAdapter<T>
      extended by org.picocontainer.injectors.AbstractInjector<T>
          extended by org.picocontainer.injectors.SingleMemberInjector<T>
              extended by org.picocontainer.injectors.ConstructorInjector<T>
All Implemented Interfaces:
Serializable, ComponentAdapter<T>, ComponentMonitorStrategy, Injector<T>

public class ConstructorInjector<T>
extends SingleMemberInjector<T>

Injection will happen through a constructor for the component.

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

Nested Class Summary
protected  class ConstructorInjector.CtorAndAdapters<TYPE>
           
 
Nested classes/interfaces inherited from class org.picocontainer.injectors.SingleMemberInjector
SingleMemberInjector.ParameterCannotBeNullException
 
Nested classes/interfaces inherited from class org.picocontainer.injectors.AbstractInjector
AbstractInjector.AmbiguousComponentResolutionException, AbstractInjector.CyclicDependencyException, AbstractInjector.NotConcreteRegistrationException, AbstractInjector.UnsatisfiableDependenciesException
 
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
 
Field Summary
 
Fields inherited from class org.picocontainer.injectors.AbstractInjector
parameters, verifyingGuard
 
Constructor Summary
ConstructorInjector(Object componentKey, Class<?> componentImplementation, Parameter... parameters)
          Constructor injector that uses no monitor and no lifecycle adapter.
ConstructorInjector(Object componentKey, Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, boolean useNames)
          Creates a ConstructorInjector
ConstructorInjector(Object componentKey, Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, boolean useNames, boolean rememberChosenCtor)
          Creates a ConstructorInjector
 
Method Summary
 void enableEmjection(boolean enableEmjection)
           
 T getComponentInstance(PicoContainer container, Type into)
          Retrieve the component instance.
 String getDescriptor()
          Get a string key descriptor of the component adapter for use in toString()
protected  ConstructorInjector.CtorAndAdapters<T> getGreediestSatisfiableConstructor(PicoContainer container)
           
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisfied.
 
Methods inherited from class org.picocontainer.injectors.SingleMemberInjector
boxParameters, getBindings, getMemberArguments, getParameter, getParanamer, isNullParamAllowed, nullCheck
 
Methods inherited from class org.picocontainer.injectors.AbstractInjector
accept, box, caughtIllegalAccessException, caughtIllegalAccessException, caughtInstantiationException, caughtInvocationTargetException, createDefaultParameters, decorateComponentInstance, getComponentInstance, newInstance, useNames
 
Methods inherited from class org.picocontainer.adapters.AbstractAdapter
changeMonitor, checkTypeCompatibility, currentMonitor, findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.picocontainer.ComponentAdapter
findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate
 

Constructor Detail

ConstructorInjector

public ConstructorInjector(Object componentKey,
                           Class<?> componentImplementation,
                           Parameter... parameters)
Constructor injector that uses no monitor and no lifecycle adapter. This is a more convenient constructor for use when instantiating a constructor injector directly.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters used for initialization

ConstructorInjector

public ConstructorInjector(Object componentKey,
                           Class componentImplementation,
                           Parameter[] parameters,
                           ComponentMonitor monitor,
                           boolean useNames)
                    throws AbstractInjector.NotConcreteRegistrationException
Creates a ConstructorInjector

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
monitor - the component monitor used by this addAdapter
useNames - use argument names when looking up dependencies
Throws:
AbstractInjector.NotConcreteRegistrationException - if the implementation is not a concrete class.
NullPointerException - if one of the parameters is null

ConstructorInjector

public ConstructorInjector(Object componentKey,
                           Class componentImplementation,
                           Parameter[] parameters,
                           ComponentMonitor monitor,
                           boolean useNames,
                           boolean rememberChosenCtor)
                    throws AbstractInjector.NotConcreteRegistrationException
Creates a ConstructorInjector

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
monitor - the component monitor used by this addAdapter
useNames - use argument names when looking up dependencies
rememberChosenCtor - remember the chosen constructor (to speed up second/subsequent calls)
Throws:
AbstractInjector.NotConcreteRegistrationException - if the implementation is not a concrete class.
NullPointerException - if one of the parameters is null
Method Detail

getGreediestSatisfiableConstructor

protected ConstructorInjector.CtorAndAdapters<T> getGreediestSatisfiableConstructor(PicoContainer container)
                                                                             throws PicoCompositionException
Throws:
PicoCompositionException

enableEmjection

public void enableEmjection(boolean enableEmjection)

getComponentInstance

public T getComponentInstance(PicoContainer container,
                              Type into)
                       throws PicoCompositionException
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, Cached will always return the same instance.

Specified by:
getComponentInstance in interface ComponentAdapter<T>
Specified by:
getComponentInstance in class AbstractInjector<T>
Parameters:
container - the PicoContainer, 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.
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.

verify

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

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

getDescriptor

public String getDescriptor()
Description copied from interface: ComponentAdapter
Get a string key descriptor of the component adapter for use in toString()

Specified by:
getDescriptor in interface ComponentAdapter<T>
Overrides:
getDescriptor in class AbstractInjector<T>
Returns:
the descriptor


Copyright © 2003-2010 Codehaus. All Rights Reserved.