org.picocontainer.defaults
Class BasicComponentParameter

java.lang.Object
  extended by org.picocontainer.defaults.BasicComponentParameter
All Implemented Interfaces:
java.io.Serializable, Parameter
Direct Known Subclasses:
ComponentParameter

public class BasicComponentParameter
extends java.lang.Object
implements Parameter, java.io.Serializable

A BasicComponentParameter should be used to pass in a particular component as argument to a different component's constructor. This is particularly useful in cases where several components of the same type have been registered, but with a different key. Passing a ComponentParameter as a parameter when registering a component will give PicoContainer a hint about what other component to use in the constructor. This Parameter will never resolve against a collecting type, that is not directly registered in the PicoContainer itself.

Version:
$Revision: 2817 $
Author:
Jon Tirsén, Aslak Hellesøy, Jörg Schaible, Thomas Heller
See Also:
Serialized Form

Field Summary
static BasicComponentParameter BASIC_DEFAULT
          BASIC_DEFAULT is an instance of BasicComponentParameter using the default constructor.
private  java.lang.Object componentKey
           
 
Constructor Summary
BasicComponentParameter()
          Expect any paramter of the appropriate type.
BasicComponentParameter(java.lang.Object componentKey)
          Expect a parameter matching a component of a specific key.
 
Method Summary
 void accept(PicoVisitor visitor)
          Visit the current Parameter.
private  ComponentAdapter getTargetAdapter(PicoContainer container, java.lang.Class expectedType, ComponentAdapter excludeAdapter)
           
 boolean isResolvable(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
          Check wether the given Parameter can be statisfied by the container.
private  ComponentAdapter resolveAdapter(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
           
 java.lang.Object resolveInstance(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
          Retrieve the object from the Parameter that statisfies the expected type.
 void verify(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
          Verify that the Parameter can statisfied the expected type using the container
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASIC_DEFAULT

public static final BasicComponentParameter BASIC_DEFAULT
BASIC_DEFAULT is an instance of BasicComponentParameter using the default constructor.


componentKey

private java.lang.Object componentKey
Constructor Detail

BasicComponentParameter

public BasicComponentParameter(java.lang.Object componentKey)
Expect a parameter matching a component of a specific key.

Parameters:
componentKey - the key of the desired component

BasicComponentParameter

public BasicComponentParameter()
Expect any paramter of the appropriate type.

Method Detail

isResolvable

public boolean isResolvable(PicoContainer container,
                            ComponentAdapter adapter,
                            java.lang.Class expectedType)
Check wether the given Parameter can be statisfied by the container.

Specified by:
isResolvable in interface Parameter
Parameters:
container - the container from which dependencies are resolved.
adapter - the ComponentAdapter that is asking for the instance
expectedType - the required type
Returns:
true if the Parameter can be verified.
Throws:
PicoInitializationException
See Also:
Parameter.isResolvable(org.picocontainer.PicoContainer, org.picocontainer.ComponentAdapter, java.lang.Class)

resolveInstance

public java.lang.Object resolveInstance(PicoContainer container,
                                        ComponentAdapter adapter,
                                        java.lang.Class expectedType)
Description copied from interface: Parameter
Retrieve the object from the Parameter that statisfies the expected type.

Specified by:
resolveInstance in interface Parameter
Parameters:
container - the container from which dependencies are resolved.
adapter - the ComponentAdapter that is asking for the instance
expectedType - the type that the returned instance needs to match.
Returns:
the instance or null if no suitable instance can be found.

verify

public void verify(PicoContainer container,
                   ComponentAdapter adapter,
                   java.lang.Class expectedType)
Description copied from interface: Parameter
Verify that the Parameter can statisfied the expected type using the container

Specified by:
verify in interface Parameter
Parameters:
container - the container from which dependencies are resolved.
adapter - the ComponentAdapter that is asking for the verification
expectedType - the required type

accept

public void accept(PicoVisitor visitor)
Visit the current Parameter.

Specified by:
accept in interface Parameter
Parameters:
visitor - the visitor.
See Also:
Parameter.accept(org.picocontainer.PicoVisitor)

resolveAdapter

private ComponentAdapter resolveAdapter(PicoContainer container,
                                        ComponentAdapter adapter,
                                        java.lang.Class expectedType)

getTargetAdapter

private ComponentAdapter getTargetAdapter(PicoContainer container,
                                          java.lang.Class expectedType,
                                          ComponentAdapter excludeAdapter)