Package org.picocontainer.parameters
Class CollectionComponentParameter
java.lang.Object
org.picocontainer.parameters.AbstractParameter
org.picocontainer.parameters.CollectionComponentParameter
- All Implemented Interfaces:
Serializable,Parameter
public class CollectionComponentParameter
extends AbstractParameter
implements Parameter, Serializable
A CollectionComponentParameter should be used to support inject an
Array, a
Collectionor Mapof 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.picocontainer.Parameter
Parameter.DelegateResolver, Parameter.NotResolved, Parameter.Resolver, Parameter.ValueResolver -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CollectionComponentParameterUseARRAYasParameterfor an Array that must have elements.static final CollectionComponentParameterUseARRAY_ALLOW_EMPTYasParameterfor an Array that may have no elements. -
Constructor Summary
ConstructorsConstructorDescriptionExpect anArrayof an appropriate type as parameter.CollectionComponentParameter(boolean emptyCollection) Expect anArrayof an appropriate type as parameter.CollectionComponentParameter(Class componentValueType, boolean emptyCollection) CollectionComponentParameter(Class componentKeyType, Class componentValueType, boolean emptyCollection) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(PicoVisitor visitor) Visit the currentParameter.protected booleanevaluate(ComponentAdapter adapter) Evaluate whether the given component adapter will be part of the collective type.protected Map<Object, ComponentAdapter<?>> getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, Class keyType, Class valueType) Collect the matching ComponentAdapter instances.resolve(PicoContainer container, ComponentAdapter<?> forAdapter, ComponentAdapter<?> injecteeAdapter, Type expectedType, NameBinding expectedNameBinding, boolean useNames, Annotation binding) Check for a successful dependency resolution of the parameter for the expected type.voidverify(PicoContainer container, ComponentAdapter<?> adapter, Type expectedType, NameBinding expectedNameBinding, boolean useNames, Annotation binding) Verify a successful dependency resolution of the parameter for the expected type.Methods inherited from class org.picocontainer.parameters.AbstractParameter
isResolvable, resolveInstanceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.picocontainer.Parameter
isResolvable, resolveInstance
-
Field Details
-
Constructor Details
-
CollectionComponentParameter
public CollectionComponentParameter()Expect anArrayof an appropriate type as parameter. At least one component of the array's component type must exist. -
CollectionComponentParameter
public CollectionComponentParameter(boolean emptyCollection) Expect anArrayof an appropriate type as parameter.- Parameters:
emptyCollection-trueif an empty array also is a valid dependency resolution.
-
CollectionComponentParameter
- Parameters:
componentValueType- the type of the components (ignored in case of an Array)emptyCollection-trueif an empty collection resolves the dependency.
-
CollectionComponentParameter
public CollectionComponentParameter(Class componentKeyType, Class componentValueType, boolean emptyCollection) - Parameters:
componentKeyType- the type of the component's keycomponentValueType- the type of the components (ignored in case of an Array)emptyCollection-trueif an empty collection resolves the dependency.
-
-
Method Details
-
resolve
public Parameter.Resolver resolve(PicoContainer container, ComponentAdapter<?> forAdapter, ComponentAdapter<?> injecteeAdapter, Type expectedType, NameBinding expectedNameBinding, boolean useNames, 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,CollectionorMap. An empty collection is only a valid resolution, if theemptyCollectionflag was set.- Specified by:
resolvein interfaceParameter- Parameters:
container- the container from which dependencies are resolved.forAdapter- theComponentAdapterthat is asking for the instanceinjecteeAdapter-expectedType- the required typeexpectedNameBinding- Expected parameter nameuseNames-binding- @returntrueif matching components were found or an empty collective type is allowed
-
verify
public void verify(PicoContainer container, ComponentAdapter<?> adapter, Type expectedType, NameBinding expectedNameBinding, boolean useNames, 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,CollectionorMap. An empty collection is only a valid resolution, if theemptyCollectionflag was set.- Specified by:
verifyin interfaceParameter- Parameters:
container- the container from which dependencies are resolved.adapter- theComponentAdapterthat is asking for the verificationexpectedType- the required typeexpectedNameBinding- Expected parameter nameuseNames-binding-- Throws:
PicoCompositionException- if parameter and its dependencies cannot be resolved
-
accept
Visit the currentParameter. -
evaluate
Evaluate whether the given component adapter will be part of the collective type.- Parameters:
adapter- aComponentAdaptervalue- Returns:
trueif the adapter takes part
-
getMatchingComponentAdapters
protected Map<Object,ComponentAdapter<?>> getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, Class keyType, Class valueType) Collect the matching ComponentAdapter instances.- Parameters:
container- container to use for dependency resolutionadapter-ComponentAdapterto excludekeyType- the compatible type of the keyvalueType- the compatible type of the addComponent- Returns:
- a
Mapwith the ComponentAdapter instances and their component keys as map key.
-