Package org.picocontainer.parameters
Class CollectionComponentParameter
- java.lang.Object
-
- org.picocontainer.parameters.AbstractParameter
-
- org.picocontainer.parameters.CollectionComponentParameter
-
- All Implemented Interfaces:
java.io.Serializable
,Parameter
public class CollectionComponentParameter extends AbstractParameter implements Parameter, java.io.Serializable
A CollectionComponentParameter should be used to support inject anArray
, aCollection
orMap
of components automatically. The collection will contain all components of a special type and additionally the type of the key may be specified. In case of a map, the map's keys are the one of the component adapter.- Author:
- Aslak Hellesøy, Jörg Schaible
- 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 CollectionComponentParameter
ARRAY
UseARRAY
asParameter
for an Array that must have elements.static CollectionComponentParameter
ARRAY_ALLOW_EMPTY
UseARRAY_ALLOW_EMPTY
asParameter
for an Array that may have no elements.
-
Constructor Summary
Constructors Constructor Description CollectionComponentParameter()
Expect anArray
of an appropriate type as parameter.CollectionComponentParameter(boolean emptyCollection)
Expect anArray
of an appropriate type as parameter.CollectionComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)
Expect any of the collection typesArray
,Collection
orMap
as parameter.CollectionComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)
Expect any of the collection typesArray
,Collection
orMap
as parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(PicoVisitor visitor)
Visit the currentParameter
.protected boolean
evaluate(ComponentAdapter adapter)
Evaluate whether the given component adapter will be part of the collective type.protected java.util.Map<java.lang.Object,ComponentAdapter<?>>
getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, java.lang.Class keyType, java.lang.Class valueType)
Collect the matching ComponentAdapter instances.Parameter.Resolver
resolve(PicoContainer container, ComponentAdapter<?> forAdapter, ComponentAdapter<?> injecteeAdapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)
Check for a successful dependency resolution of the parameter for the expected type.void
verify(PicoContainer container, ComponentAdapter<?> adapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)
Verify a successful dependency resolution of the parameter for the expected type.-
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
-
ARRAY
public static final CollectionComponentParameter ARRAY
UseARRAY
asParameter
for an Array that must have elements.
-
ARRAY_ALLOW_EMPTY
public static final CollectionComponentParameter ARRAY_ALLOW_EMPTY
UseARRAY_ALLOW_EMPTY
asParameter
for an Array that may have no elements.
-
-
Constructor Detail
-
CollectionComponentParameter
public CollectionComponentParameter()
Expect anArray
of an appropriate type as parameter. At least one component of the array's component type must exist.
-
CollectionComponentParameter
public CollectionComponentParameter(boolean emptyCollection)
Expect anArray
of an appropriate type as parameter.- Parameters:
emptyCollection
-true
if an empty array also is a valid dependency resolution.
-
CollectionComponentParameter
public CollectionComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)
Expect any of the collection typesArray
,Collection
orMap
as parameter.- Parameters:
componentValueType
- the type of the components (ignored in case of an Array)emptyCollection
-true
if an empty collection resolves the dependency.
-
CollectionComponentParameter
public CollectionComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)
Expect any of the collection typesArray
,Collection
orMap
as parameter.- Parameters:
componentKeyType
- the type of the component's keycomponentValueType
- the type of the components (ignored in case of an Array)emptyCollection
-true
if an empty collection resolves the dependency.
-
-
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)
Check for a successful dependency resolution of the parameter for the expected type. The dependency can only be satisfied if the expected type is one of the collection typesArray
,Collection
orMap
. An empty collection is only a valid resolution, if theemptyCollection
flag was set.- Specified by:
resolve
in interfaceParameter
- Parameters:
container
- the container from which dependencies are resolved.injecteeAdapter
-expectedType
- the required typeexpectedNameBinding
- Expected parameter nameuseNames
-binding
-forAdapter
- theComponentAdapter
that is asking for the instance- Returns:
true
if matching components were found or an empty collective type is allowed
-
verify
public void verify(PicoContainer container, ComponentAdapter<?> adapter, java.lang.reflect.Type expectedType, NameBinding expectedNameBinding, boolean useNames, java.lang.annotation.Annotation binding)
Verify a successful dependency resolution of the parameter for the expected type. The method will only return if the expected type is one of the collection typesArray
,Collection
orMap
. An empty collection is only a valid resolution, if theemptyCollection
flag was set.- Specified by:
verify
in interfaceParameter
- Parameters:
container
- the container from which dependencies are resolved.adapter
- theComponentAdapter
that is asking for the verificationexpectedType
- the required typeexpectedNameBinding
- Expected parameter nameuseNames
-binding
-- Throws:
PicoCompositionException
- if parameter and its dependencies cannot be resolved
-
accept
public void accept(PicoVisitor visitor)
Visit the currentParameter
.- Specified by:
accept
in interfaceParameter
- Parameters:
visitor
- the visitor.- See Also:
Parameter.accept(org.picocontainer.PicoVisitor)
-
evaluate
protected boolean evaluate(ComponentAdapter adapter)
Evaluate whether the given component adapter will be part of the collective type.- Parameters:
adapter
- aComponentAdapter
value- Returns:
true
if the adapter takes part
-
getMatchingComponentAdapters
protected java.util.Map<java.lang.Object,ComponentAdapter<?>> getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, java.lang.Class keyType, java.lang.Class valueType)
Collect the matching ComponentAdapter instances.- Parameters:
container
- container to use for dependency resolutionadapter
-ComponentAdapter
to excludekeyType
- the compatible type of the keyvalueType
- the compatible type of the addComponent- Returns:
- a
Map
with the ComponentAdapter instances and their component keys as map key.
-
-