Package org.picocontainer.injectors
Class ProviderAdapter
java.lang.Object
org.picocontainer.injectors.ProviderAdapter
- All Implemented Interfaces:
ComponentAdapter
,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
ConstructorsModifierConstructorDescriptionprotected
ProviderAdapter
(Provider provider) ProviderAdapter
(Provider provider, boolean useNames) ProviderAdapter
(LifecycleStrategy lifecycleStrategy, Provider provider) ProviderAdapter
(LifecycleStrategy lifecycleStrategy, Provider provider, boolean useNames) -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(PicoVisitor visitor) Accepts a visitor for this ComponentAdapter.decorateComponentInstance
(PicoContainer container, Type into, Object instance) A preexiting component instance can be injected into after instantiationvoid
Invoke the "dispose" method on the component instance if this is disposable.findAdapterOfType
(Class adapterType) Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.Retrieve the class of the component.getComponentInstance
(PicoContainer container) Deprecated.getComponentInstance
(PicoContainer container, Type into) Retrieve the component instance.Retrieve the key associated with the component.Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.Get a string key descriptor of the component adapter for use in toString()static Method
getProvideMethod
(Class clazz) boolean
hasLifecycle
(Class<?> type) Test if a component instance has a lifecycle.boolean
isLazy
(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() ).void
Invoke the "start" method on the component instance if this is startable.void
Invoke the "stop" method on the component instance if this is stoppable.protected boolean
useNames()
void
verify
(PicoContainer container) Verify that all dependencies for this adapter can be satisfied.
-
Constructor Details
-
ProviderAdapter
protected ProviderAdapter() -
ProviderAdapter
-
ProviderAdapter
-
ProviderAdapter
-
ProviderAdapter
-
-
Method Details
-
useNames
protected boolean useNames() -
decorateComponentInstance
Description copied from interface:Injector
A preexiting component instance can be injected into after instantiation- Specified by:
decorateComponentInstance
in interfaceInjector
- Parameters:
container
- the container that can provide injectable dependenciesinto
-instance
- the instance to- Returns:
-
getComponentKey
Description copied from interface:ComponentAdapter
Retrieve the key associated with the component.- Specified by:
getComponentKey
in 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
Description copied from interface:ComponentAdapter
Retrieve the class of the component.- Specified by:
getComponentImplementation
in interfaceComponentAdapter
- Returns:
- the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
-
getComponentInstance
@Deprecated public Object getComponentInstance(PicoContainer container) throws PicoCompositionException Deprecated.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 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 Object 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 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
-
verify
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 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
Description copied from interface:ComponentAdapter
Accepts 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:
accept
in interfaceComponentAdapter
- Parameters:
visitor
- the visitor.
-
getDelegate
Description copied from interface:ComponentAdapter
Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.- Specified by:
getDelegate
in interfaceComponentAdapter
- Returns:
- the next component adapter in line or null if there is no delegate ComponentAdapter.
-
findAdapterOfType
Description copied from interface:ComponentAdapter
Locates a component adapter of type componentAdapterType in the ComponentAdapter chain. Will return null if there is no adapter of the given type.- Specified by:
findAdapterOfType
in 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
Description copied from interface:ComponentAdapter
Get a string key descriptor of the component adapter for use in toString()- Specified by:
getDescriptor
in interfaceComponentAdapter
- Returns:
- the descriptor
-
start
Description copied from interface:LifecycleStrategy
Invoke 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:
start
in interfaceLifecycleStrategy
- Parameters:
component
- the instance of the component to start
-
stop
Description copied from interface:LifecycleStrategy
Invoke 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:
stop
in interfaceLifecycleStrategy
- Parameters:
component
- the instance of the component to stop
-
dispose
Description copied from interface:LifecycleStrategy
Invoke 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:
dispose
in interfaceLifecycleStrategy
- Parameters:
component
- the instance of the component to dispose
-
hasLifecycle
Description copied from interface:LifecycleStrategy
Test if a component instance has a lifecycle.- Specified by:
hasLifecycle
in interfaceLifecycleStrategy
- Parameters:
type
- the component's type- Returns:
true
if the component has a lifecycle
-
isLazy
Description copied from interface:LifecycleStrategy
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() ). The default is the first of those two.- Specified by:
isLazy
in interfaceLifecycleStrategy
- Parameters:
adapter
-- Returns:
- true if lazy, false if not lazy
-