org.picocontainer.defaults
Class ComponentParameter

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

public class ComponentParameter
extends BasicComponentParameter

A ComponentParameter 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. Collecting parameter types are supported for Array,Collectionand Map.

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

Field Summary
static ComponentParameter ARRAY
          Use ARRAY as Parameterfor an Array that must have elements.
static ComponentParameter ARRAY_ALLOW_EMPTY
          Use ARRAY_ALLOW_EMPTY as Parameterfor an Array that may have no elements.
private  Parameter collectionParameter
           
static ComponentParameter DEFAULT
          DEFAULT is an instance of ComponentParameter using the default constructor.
 
Fields inherited from class org.picocontainer.defaults.BasicComponentParameter
BASIC_DEFAULT
 
Constructor Summary
  ComponentParameter()
          Expect any scalar paramter of the appropriate type or an Array.
  ComponentParameter(boolean emptyCollection)
          Expect any scalar paramter of the appropriate type or an Array.
  ComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)
          Expect any scalar paramter of the appropriate type or the collecting type Array,Collectionor Map.
  ComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)
          Expect any scalar paramter of the appropriate type or the collecting type Array,Collectionor Map.
  ComponentParameter(java.lang.Object componentKey)
          Expect a parameter matching a component of a specific key.
private ComponentParameter(java.lang.Object componentKey, Parameter collectionParameter)
           
 
Method Summary
 void accept(PicoVisitor visitor)
          Accept the visitor for the current Parameter.
 boolean isResolvable(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
          Check wether the given Parameter can be statisfied by the container.
 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

DEFAULT

public static final ComponentParameter DEFAULT
DEFAULT is an instance of ComponentParameter using the default constructor.


ARRAY

public static final ComponentParameter ARRAY
Use ARRAY as Parameterfor an Array that must have elements.


ARRAY_ALLOW_EMPTY

public static final ComponentParameter ARRAY_ALLOW_EMPTY
Use ARRAY_ALLOW_EMPTY as Parameterfor an Array that may have no elements.


collectionParameter

private final Parameter collectionParameter
Constructor Detail

ComponentParameter

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

Parameters:
componentKey - the key of the desired component

ComponentParameter

public ComponentParameter()
Expect any scalar paramter of the appropriate type or an Array.


ComponentParameter

public ComponentParameter(boolean emptyCollection)
Expect any scalar paramter of the appropriate type or an Array. Resolve the parameter even if no compoennt is of the array's component type.

Parameters:
emptyCollection - true allows an Array to be empty
Since:
1.1

ComponentParameter

public ComponentParameter(java.lang.Class componentValueType,
                          boolean emptyCollection)
Expect any scalar paramter of the appropriate type or the collecting type Array,Collectionor Map. The components in the collection will be of the specified type.

Parameters:
componentValueType - the component's type (ignored for an Array)
emptyCollection - true allows the collection to be empty
Since:
1.1

ComponentParameter

public ComponentParameter(java.lang.Class componentKeyType,
                          java.lang.Class componentValueType,
                          boolean emptyCollection)
Expect any scalar paramter of the appropriate type or the collecting type Array,Collectionor Map. The components in the collection will be of the specified type and their adapter's key must have a particular type.

Parameters:
componentKeyType - the component adapter's key type
componentValueType - the component's type (ignored for an Array)
emptyCollection - true allows the collection to be empty
Since:
1.1

ComponentParameter

private ComponentParameter(java.lang.Object componentKey,
                           Parameter collectionParameter)
Method Detail

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
Overrides:
resolveInstance in class BasicComponentParameter
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.

isResolvable

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

Specified by:
isResolvable in interface Parameter
Overrides:
isResolvable in class BasicComponentParameter
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.
See Also:
Parameter.isResolvable(org.picocontainer.PicoContainer, org.picocontainer.ComponentAdapter, java.lang.Class)

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
Overrides:
verify in class BasicComponentParameter
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)
Accept the visitor for the current Parameter. If internally a CollectionComponentParameteris used, it is visited also.

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