org.picocontainer
Interface ComponentAdapter<T>

All Known Subinterfaces:
Behavior<T>, Injector<T>
All Known Implementing Classes:
AbstractAdapter, AbstractBehavior, AbstractInjector, AnnotatedFieldInjector, AnnotatedMethodInjector, Automated, Cached, CompositeInjector, ConstructorInjector, Decorated, DefaultPicoContainer.KnowsContainerAdapter, DefaultPicoContainer.LateInstance, FactoryInjector, FieldDecorated, Guarded, HiddenImplementation, InstanceAdapter, Intercepted, IterativeInjector, Locked, MethodInjector, MethodInjector.ByReflectionMethod, MultiInjector, NamedFieldInjector, NamedMethodInjector, PropertyApplicator, ProviderAdapter, SetterInjector, SingleMemberInjector, Stored, Synchronized, ThreadCached, TypedFieldInjector

public interface ComponentAdapter<T>

A component adapter is responsible for providing a specific component instance of type <T>. An instance of an implementation of this interface is used inside a PicoContainer for every registered component or instance. Each ComponentAdapter instance has to have a key which is unique within that container. The key itself is either a class type (normally an interface) or an identifier.

In a overly simplistic sense, the ComponentAdapter can be thought of us a type of an object factory. If you need to modify how your object is constructed, use and appropriate ComponentAdapter or roll your own since the API is purposely kept rather simple. See http://www.picocontainer.org/adapters.html for more information.

Author:
Jon Tirsén, Paul Hammant, Aslak Hellesøy

Nested Class Summary
static class ComponentAdapter.NOTHING
           
 
Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor for this ComponentAdapter.
<U extends ComponentAdapter>
U
findAdapterOfType(Class<U> adapterType)
          Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.
 Class<T> getComponentImplementation()
          Retrieve the class of the component.
 T getComponentInstance(PicoContainer container)
          Deprecated. since PicoContainer 2.2. Use getComponentInstance(PicoContainer,Type) with ComponentAdapter.NOTHING.class as type if no type available.
 T getComponentInstance(PicoContainer container, Type into)
          Retrieve the component instance.
 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.
 String getDescriptor()
          Get a string key descriptor of the component adapter for use in toString()
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisfied.
 

Method Detail

getComponentKey

Object getComponentKey()
Retrieve the key associated with the component.

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

Class<T> getComponentImplementation()
Retrieve the class of the component.

Returns:
the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).

getComponentInstance

T getComponentInstance(PicoContainer container)
                       throws PicoCompositionException
Deprecated. since PicoContainer 2.2. Use getComponentInstance(PicoContainer,Type) with ComponentAdapter.NOTHING.class as type if no type available.

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.

Parameters:
container - the PicoContainer, 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

T getComponentInstance(PicoContainer container,
                       Type into)
                       throws PicoCompositionException
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.

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

void verify(PicoContainer container)
            throws PicoCompositionException
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.

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.

accept

void accept(PicoVisitor visitor)
Accepts a visitor for this ComponentAdapter. The method is normally called by visiting a PicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.

Parameters:
visitor - the visitor.

getDelegate

ComponentAdapter<T> getDelegate()
Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.

Returns:
the next component adapter in line or null if there is no delegate ComponentAdapter.

findAdapterOfType

<U extends ComponentAdapter> U findAdapterOfType(Class<U> adapterType)
Locates a component adapter of type componentAdapterType in the ComponentAdapter chain. Will return null if there is no adapter of the given type.

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.

getDescriptor

String getDescriptor()
Get a string key descriptor of the component adapter for use in toString()

Returns:
the descriptor


Copyright © 2003-2010 Codehaus. All Rights Reserved.