Package org.picocontainer.injectors
Class FactoryInjector<T>
- java.lang.Object
-
- org.picocontainer.injectors.FactoryInjector<T>
-
- All Implemented Interfaces:
ComponentAdapter<T>,Injector<T>
public abstract class FactoryInjector<T> extends java.lang.Object implements Injector<T>
An Injector which provides an custom instance in a factory style
- Author:
- Paul Hammant
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFactoryInjector.CantWorkItOut-
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
-
-
Constructor Summary
Constructors Constructor Description FactoryInjector()FactoryInjector(java.lang.Class<T> key)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaccept(PicoVisitor visitor)Accepts a visitor for this ComponentAdapter.booleancomponentHasLifecycle()java.lang.ObjectdecorateComponentInstance(PicoContainer container, java.lang.reflect.Type into, T instance)A preexiting component instance can be injected into after instantiationvoiddispose(PicoContainer container)<U extends ComponentAdapter>
UfindAdapterOfType(java.lang.Class<U> adapterType)Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.static java.lang.Class<?>getClass(java.lang.reflect.Type type)java.lang.Class<? extends T>getComponentImplementation()Retrieve the class of the component.TgetComponentInstance(PicoContainer container)Retrieve the component instance.abstract TgetComponentInstance(PicoContainer container, java.lang.reflect.Type into)Retrieve the component instance.java.lang.ObjectgetComponentKey()Retrieve the key associated with the component.ComponentAdapter<T>getDelegate()Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.java.lang.StringgetDescriptor()Get a string key descriptor of the component adapter for use in toString()static <T> java.util.List<java.lang.Class<?>>getTypeArguments(java.lang.Class<FactoryInjector> class1, java.lang.Class<? extends java.lang.Object> class2)Get the actual type arguments a child class has used to extend a generic base class.voidstart(PicoContainer container)voidstop(PicoContainer container)voidverify(PicoContainer container)Verify that all dependencies for this adapter can be satisfied.
-
-
-
Constructor Detail
-
FactoryInjector
public FactoryInjector() throws PicoCompositionException- Throws:
PicoCompositionException
-
FactoryInjector
public FactoryInjector(java.lang.Class<T> key)
-
-
Method Detail
-
getClass
public static java.lang.Class<?> getClass(java.lang.reflect.Type type)
-
getTypeArguments
public static <T> java.util.List<java.lang.Class<?>> getTypeArguments(java.lang.Class<FactoryInjector> class1, java.lang.Class<? extends java.lang.Object> class2)
Get the actual type arguments a child class has used to extend a generic base class.- Parameters:
class1- the base classclass2- the child class- Returns:
- a list of the raw classes for the actual type arguments.
-
getComponentKey
public java.lang.Object getComponentKey()
Description copied from interface:ComponentAdapterRetrieve the key associated with the component.- Specified by:
getComponentKeyin interfaceComponentAdapter<T>- Returns:
- the component's key. Should either be a class type (normally an interface) or an identifier that is unique (within the scope of the current PicoContainer).
-
getComponentImplementation
public java.lang.Class<? extends T> getComponentImplementation()
Description copied from interface:ComponentAdapterRetrieve the class of the component.- Specified by:
getComponentImplementationin interfaceComponentAdapter<T>- Returns:
- the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
-
accept
public void accept(PicoVisitor visitor)
Description copied from interface:ComponentAdapterAccepts a visitor for this ComponentAdapter. The method is normally called by visiting aPicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.- Specified by:
acceptin interfaceComponentAdapter<T>- Parameters:
visitor- the visitor.
-
getDelegate
public ComponentAdapter<T> getDelegate()
Description copied from interface:ComponentAdapterComponent adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.- Specified by:
getDelegatein interfaceComponentAdapter<T>- Returns:
- the next component adapter in line or null if there is no delegate ComponentAdapter.
-
findAdapterOfType
public <U extends ComponentAdapter> U findAdapterOfType(java.lang.Class<U> adapterType)
Description copied from interface:ComponentAdapterLocates a component adapter of type componentAdapterType in the ComponentAdapter chain. Will return null if there is no adapter of the given type.- Specified by:
findAdapterOfTypein interfaceComponentAdapter<T>- Type Parameters:
U- the type of ComponentAdapter being located.- Parameters:
adapterType- the class of the adapter type being located. Never null.- Returns:
- the appropriate component adapter of type U. May return null if the component adapter type is not returned.
-
getComponentInstance
public T getComponentInstance(PicoContainer container)
Description copied from interface:ComponentAdapterRetrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example,Cachedwill always return the same instance.- Specified by:
getComponentInstancein interfaceComponentAdapter<T>- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.- Returns:
- the component instance.
-
getComponentInstance
public abstract T getComponentInstance(PicoContainer container, java.lang.reflect.Type into)
Description copied from interface:ComponentAdapterRetrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example,Cachedwill always return the same instance.- Specified by:
getComponentInstancein interfaceComponentAdapter<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.
-
decorateComponentInstance
public java.lang.Object decorateComponentInstance(PicoContainer container, java.lang.reflect.Type into, T instance)
Description copied from interface:InjectorA preexiting component instance can be injected into after instantiation- Specified by:
decorateComponentInstancein interfaceInjector<T>- Parameters:
container- the container that can provide injectable dependenciesinstance- the instance to- Returns:
-
verify
public void verify(PicoContainer container)
Description copied from interface:ComponentAdapterVerify 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:
verifyin interfaceComponentAdapter<T>- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.
-
getDescriptor
public java.lang.String getDescriptor()
Description copied from interface:ComponentAdapterGet a string key descriptor of the component adapter for use in toString()- Specified by:
getDescriptorin interfaceComponentAdapter<T>- Returns:
- the descriptor
-
start
public void start(PicoContainer container)
-
stop
public void stop(PicoContainer container)
-
dispose
public void dispose(PicoContainer container)
-
componentHasLifecycle
public boolean componentHasLifecycle()
-
-