Package org.picocontainer.parameters
Class ComponentParameter
- java.lang.Object
-
- org.picocontainer.parameters.AbstractParameter
-
- org.picocontainer.parameters.BasicComponentParameter
-
- org.picocontainer.parameters.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 forArray,CollectionandMap.- Author:
- Jon Tirsén, Aslak Hellesøy, Jörg Schaible, Thomas Heller
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.picocontainer.Parameter
Parameter.DelegateResolver, Parameter.NotResolved, Parameter.Resolver, Parameter.ValueResolver
-
-
Field Summary
Fields Modifier and Type Field Description static ComponentParameterARRAYUseARRAYasParameterfor an Array that must have elements.static ComponentParameterARRAY_ALLOW_EMPTYUseARRAY_ALLOW_EMPTYasParameterfor an Array that may have no elements.static ComponentParameterDEFAULTDEFAULTis an instance of ComponentParameter using the default constructor.-
Fields inherited from class org.picocontainer.parameters.BasicComponentParameter
BASIC_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description ComponentParameter()Expect any scalar parameter of the appropriate type or anArray.ComponentParameter(boolean emptyCollection)Expect any scalar parameter of the appropriate type or anArray.ComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)Expect any scalar parameter of the appropriate type or the collecting typeArray,CollectionorMap.ComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)Expect any scalar parameter of the appropriate type or the collecting typeArray,CollectionorMap.ComponentParameter(java.lang.Object componentKey)Expect a parameter matching a component of a specific key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(PicoVisitor visitor)Accept the visitor for the currentParameter.Parameter.Resolverresolve(PicoContainer container, ComponentAdapter<?> forAdapter, ComponentAdapter<?> injecteeAdapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)Check whether the given Parameter can be satisfied by the container.voidverify(PicoContainer container, ComponentAdapter<?> adapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)Verify that the Parameter can satisfy the expected type using the container-
Methods inherited from class org.picocontainer.parameters.BasicComponentParameter
findInjectorOrInstanceAdapter, makeFoundAmbiguousStrings, resolveAdapter
-
Methods inherited from class org.picocontainer.parameters.AbstractParameter
isResolvable, resolveInstance
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.picocontainer.Parameter
isResolvable, resolveInstance
-
-
-
-
Field Detail
-
DEFAULT
public static final ComponentParameter DEFAULT
DEFAULTis an instance of ComponentParameter using the default constructor.
-
ARRAY
public static final ComponentParameter ARRAY
UseARRAYasParameterfor an Array that must have elements.
-
ARRAY_ALLOW_EMPTY
public static final ComponentParameter ARRAY_ALLOW_EMPTY
UseARRAY_ALLOW_EMPTYasParameterfor an Array that may have no elements.
-
-
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 addComponent
-
ComponentParameter
public ComponentParameter()
Expect any scalar parameter of the appropriate type or anArray.
-
ComponentParameter
public ComponentParameter(boolean emptyCollection)
Expect any scalar parameter of the appropriate type or anArray. Resolve the parameter even if no compnoent is of the array's component type.- Parameters:
emptyCollection-trueallows an Array to be empty
-
ComponentParameter
public ComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)Expect any scalar parameter of the appropriate type or the collecting typeArray,CollectionorMap. The components in the collection will be of the specified type.- Parameters:
componentValueType- the component's type (ignored for an Array)emptyCollection-trueallows the collection to be empty
-
ComponentParameter
public ComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)Expect any scalar parameter of the appropriate type or the collecting typeArray,CollectionorMap. 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 typecomponentValueType- the component's type (ignored for an Array)emptyCollection-trueallows the collection to be empty
-
-
Method Detail
-
resolve
public Parameter.Resolver resolve(PicoContainer container, ComponentAdapter<?> forAdapter, ComponentAdapter<?> injecteeAdapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)
Description copied from class:BasicComponentParameterCheck whether the given Parameter can be satisfied by the container.- Specified by:
resolvein interfaceParameter- Overrides:
resolvein classBasicComponentParameter- Parameters:
container- the container from which dependencies are resolved.forAdapter- theComponentAdapterthat is asking for the instanceinjecteeAdapter- the adapter to be injected into (null for N/A)expectedType- the required typeexpectedNameBinding- Expected parameter nameuseNames- should use parameter names for disambiguation- Returns:
trueif the Parameter can be verified.- See Also:
Parameter#isResolvable(PicoContainer, ComponentAdapter, Class, NameBinding ,boolean, Annotation)
-
verify
public void verify(PicoContainer container, ComponentAdapter<?> adapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)
Description copied from interface:ParameterVerify that the Parameter can satisfy the expected type using the container- Specified by:
verifyin interfaceParameter- Overrides:
verifyin classBasicComponentParameter- Parameters:
container- the container from which dependencies are resolved.adapter- theComponentAdapterthat is asking for the verificationexpectedType- the required typeexpectedNameBinding- Expected parameter name
-
accept
public void accept(PicoVisitor visitor)
Accept the visitor for the currentParameter. If internally aCollectionComponentParameteris used, it is visited also.- Specified by:
acceptin interfaceParameter- Overrides:
acceptin classBasicComponentParameter- Parameters:
visitor- the visitor.- See Also:
BasicComponentParameter.accept(org.picocontainer.PicoVisitor)
-
-