Package org.picocontainer.adapters
Class AbstractAdapter<T>
- java.lang.Object
-
- org.picocontainer.adapters.AbstractAdapter<T>
-
- All Implemented Interfaces:
java.io.Serializable
,ComponentAdapter<T>
,ComponentMonitorStrategy
- Direct Known Subclasses:
AbstractInjector
,DefaultPicoContainer.LateInstance
,InstanceAdapter
public abstract class AbstractAdapter<T> extends java.lang.Object implements ComponentAdapter<T>, ComponentMonitorStrategy, java.io.Serializable
Base class for a ComponentAdapter with general functionality. This implementation provides basic checks for a healthy implementation of a ComponentAdapter. It does not allow to usenull
for the component key or the implementation, ensures that the implementation is a concrete class and that the key is assignable from the implementation if the key represents a type.- Author:
- Paul Hammant, Aslak Hellesøy, Jon Tirsén
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
-
-
Constructor Summary
Constructors Constructor Description AbstractAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation)
Constructs a new ComponentAdapter for the given key and implementation.AbstractAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, ComponentMonitor monitor)
Constructs a new ComponentAdapter for the given key and implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(PicoVisitor visitor)
Accepts a visitor for this ComponentAdapter.void
changeMonitor(ComponentMonitor monitor)
Changes the component monitor usedprotected void
checkTypeCompatibility()
ComponentMonitor
currentMonitor()
Returns the monitor currently used<U extends ComponentAdapter>
UfindAdapterOfType(java.lang.Class<U> adapterType)
Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.java.lang.Class<? extends T>
getComponentImplementation()
Retrieve the class of the component.T
getComponentInstance(PicoContainer container)
Retrieve the component instance.java.lang.Object
getComponentKey()
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.String
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
getComponentInstance, getDescriptor, verify
-
-
-
-
Constructor Detail
-
AbstractAdapter
public AbstractAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation)
Constructs a new ComponentAdapter for the given key and implementation.- Parameters:
componentKey
- the search key for this implementationcomponentImplementation
- the concrete implementation
-
AbstractAdapter
public AbstractAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, ComponentMonitor monitor)
Constructs a new ComponentAdapter for the given key and implementation.- Parameters:
componentKey
- the search key for this implementationcomponentImplementation
- the concrete implementationmonitor
- the component monitor used by this ComponentAdapter
-
-
Method Detail
-
getComponentKey
public java.lang.Object getComponentKey()
Retrieve the key associated with the component.- Specified by:
getComponentKey
in 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).
- See Also:
ComponentAdapter.getComponentKey()
-
getComponentImplementation
public java.lang.Class<? extends T> getComponentImplementation()
Retrieve the class of the component.- Specified by:
getComponentImplementation
in interfaceComponentAdapter<T>
- Returns:
- the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
- See Also:
ComponentAdapter.getComponentImplementation()
-
checkTypeCompatibility
protected void checkTypeCompatibility()
-
getComponentInstance
public T getComponentInstance(PicoContainer container) 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<T>
- 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- Returns the ComponentAdapter's class name and the component's key.
- See Also:
Object.toString()
-
accept
public void accept(PicoVisitor visitor)
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<T>
- Parameters:
visitor
- the visitor.
-
changeMonitor
public void changeMonitor(ComponentMonitor monitor)
Description copied from interface:ComponentMonitorStrategy
Changes the component monitor used- Specified by:
changeMonitor
in interfaceComponentMonitorStrategy
- Parameters:
monitor
- the new ComponentMonitor to use
-
currentMonitor
public ComponentMonitor currentMonitor()
Returns the monitor currently used- Specified by:
currentMonitor
in interfaceComponentMonitorStrategy
- Returns:
- The ComponentMonitor currently used
-
getDelegate
public final ComponentAdapter<T> 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<T>
- Returns:
- the next component adapter in line or null if there is no delegate ComponentAdapter.
-
findAdapterOfType
public final <U extends ComponentAdapter> U findAdapterOfType(java.lang.Class<U> adapterType)
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<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.
-
-