Package org.picocontainer.injectors
Class ProviderAdapter
- java.lang.Object
-
- org.picocontainer.injectors.ProviderAdapter
-
- All Implemented Interfaces:
ComponentAdapter,Injector,Provider,LifecycleStrategy
public class ProviderAdapter extends java.lang.Object implements Injector, Provider, LifecycleStrategy
Providers are a type of Injector that can participate in Injection via a custom method. Implementers of this class must implement a single method called provide. That method must return the component type intended to be provided. The method can accept parameters that PicoContainer will satisfy.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedProviderAdapter()ProviderAdapter(Provider provider)ProviderAdapter(Provider provider, boolean useNames)ProviderAdapter(LifecycleStrategy lifecycleStrategy, Provider provider)ProviderAdapter(LifecycleStrategy lifecycleStrategy, Provider provider, boolean useNames)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(PicoVisitor visitor)Accepts a visitor for this ComponentAdapter.java.lang.ObjectdecorateComponentInstance(PicoContainer container, java.lang.reflect.Type into, java.lang.Object instance)A preexiting component instance can be injected into after instantiationvoiddispose(java.lang.Object component)Invoke the "dispose" method on the component instance if this is disposable.ComponentAdapterfindAdapterOfType(java.lang.Class adapterType)Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.java.lang.ClassgetComponentImplementation()Retrieve the class of the component.java.lang.ObjectgetComponentInstance(PicoContainer container)Deprecated.java.lang.ObjectgetComponentInstance(PicoContainer container, java.lang.reflect.Type into)Retrieve the component instance.java.lang.ObjectgetComponentKey()Retrieve the key associated with the component.ComponentAdaptergetDelegate()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 java.lang.reflect.MethodgetProvideMethod(java.lang.Class clazz)booleanhasLifecycle(java.lang.Class<?> type)Test if a component instance has a lifecycle.booleanisLazy(ComponentAdapter<?> adapter)Is a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ).voidstart(java.lang.Object component)Invoke the "start" method on the component instance if this is startable.voidstop(java.lang.Object component)Invoke the "stop" method on the component instance if this is stoppable.protected booleanuseNames()voidverify(PicoContainer container)Verify that all dependencies for this adapter can be satisfied.
-
-
-
Constructor Detail
-
ProviderAdapter
protected ProviderAdapter()
-
ProviderAdapter
public ProviderAdapter(LifecycleStrategy lifecycleStrategy, Provider provider)
-
ProviderAdapter
public ProviderAdapter(Provider provider)
-
ProviderAdapter
public ProviderAdapter(Provider provider, boolean useNames)
-
ProviderAdapter
public ProviderAdapter(LifecycleStrategy lifecycleStrategy, Provider provider, boolean useNames)
-
-
Method Detail
-
useNames
protected boolean useNames()
-
decorateComponentInstance
public java.lang.Object decorateComponentInstance(PicoContainer container, java.lang.reflect.Type into, java.lang.Object instance)
Description copied from interface:InjectorA preexiting component instance can be injected into after instantiation- Specified by:
decorateComponentInstancein interfaceInjector- Parameters:
container- the container that can provide injectable dependenciesinstance- the instance to- Returns:
-
getComponentKey
public java.lang.Object getComponentKey()
Description copied from interface:ComponentAdapterRetrieve the key associated with the component.- Specified by:
getComponentKeyin interfaceComponentAdapter- 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 getComponentImplementation()
Description copied from interface:ComponentAdapterRetrieve the class of the component.- Specified by:
getComponentImplementationin interfaceComponentAdapter- Returns:
- the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
-
getComponentInstance
@Deprecated public java.lang.Object getComponentInstance(PicoContainer container) throws PicoCompositionException
Deprecated.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- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.- Returns:
- the component instance.
- Throws:
PicoCompositionException- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambigous situation within the container.
-
getComponentInstance
public java.lang.Object getComponentInstance(PicoContainer container, java.lang.reflect.Type into) throws PicoCompositionException
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- 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.
- 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.
-
getProvideMethod
public static java.lang.reflect.Method getProvideMethod(java.lang.Class clazz)
-
verify
public void verify(PicoContainer container) throws PicoCompositionException
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- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.- Throws:
PicoCompositionException- if one or more dependencies cannot be resolved.
-
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- Parameters:
visitor- the visitor.
-
getDelegate
public ComponentAdapter 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- Returns:
- the next component adapter in line or null if there is no delegate ComponentAdapter.
-
findAdapterOfType
public ComponentAdapter findAdapterOfType(java.lang.Class 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- 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.
-
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- Returns:
- the descriptor
-
start
public void start(java.lang.Object component)
Description copied from interface:LifecycleStrategyInvoke the "start" method on the component instance if this is startable. It is up to the implementation of the strategy what "start" and "startable" means.- Specified by:
startin interfaceLifecycleStrategy- Parameters:
component- the instance of the component to start
-
stop
public void stop(java.lang.Object component)
Description copied from interface:LifecycleStrategyInvoke the "stop" method on the component instance if this is stoppable. It is up to the implementation of the strategy what "stop" and "stoppable" means.- Specified by:
stopin interfaceLifecycleStrategy- Parameters:
component- the instance of the component to stop
-
dispose
public void dispose(java.lang.Object component)
Description copied from interface:LifecycleStrategyInvoke the "dispose" method on the component instance if this is disposable. It is up to the implementation of the strategy what "dispose" and "disposable" means.- Specified by:
disposein interfaceLifecycleStrategy- Parameters:
component- the instance of the component to dispose
-
hasLifecycle
public boolean hasLifecycle(java.lang.Class<?> type)
Description copied from interface:LifecycleStrategyTest if a component instance has a lifecycle.- Specified by:
hasLifecyclein interfaceLifecycleStrategy- Parameters:
type- the component's type- Returns:
trueif the component has a lifecycle
-
isLazy
public boolean isLazy(ComponentAdapter<?> adapter)
Description copied from interface:LifecycleStrategyIs a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ). The default is the first of those two.- Specified by:
isLazyin interfaceLifecycleStrategy- Returns:
- true if lazy, false if not lazy
-
-