Class 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.
    See Also:
    Serialized Form
    • Constructor Detail

      • CollectionComponentParameter

        public CollectionComponentParameter()
        Expect an Arrayof an appropriate type as parameter. At least one component of the array's component type must exist.
      • CollectionComponentParameter

        public CollectionComponentParameter​(boolean emptyCollection)
        Expect an Arrayof an appropriate type as parameter.
        Parameters:
        emptyCollection - true if an empty array also is a valid dependency resolution.
      • CollectionComponentParameter

        public CollectionComponentParameter​(Class componentValueType,
                                            boolean emptyCollection)
        Expect any of the collection types Array,Collectionor Mapas 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​(Class componentKeyType,
                                            Class componentValueType,
                                            boolean emptyCollection)
        Expect any of the collection types Array,Collectionor Mapas parameter.
        Parameters:
        componentKeyType - the type of the component's key
        componentValueType - 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,
                                          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 types Array,Collectionor Map. An empty collection is only a valid resolution, if the emptyCollection flag was set.
        Specified by:
        resolve in interface Parameter
        Parameters:
        container - the container from which dependencies are resolved.
        injecteeAdapter -
        expectedType - the required type
        expectedNameBinding - Expected parameter name
        useNames -
        binding -
        forAdapter - the ComponentAdapter 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,
                           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 types Array, Collectionor Map. An empty collection is only a valid resolution, if the emptyCollection flag was set.
        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
        expectedNameBinding - Expected parameter name
        useNames -
        binding -
        Throws:
        PicoCompositionException - if parameter and its dependencies cannot be resolved
      • evaluate

        protected boolean evaluate​(ComponentAdapter adapter)
        Evaluate whether the given component adapter will be part of the collective type.
        Parameters:
        adapter - a ComponentAdapter value
        Returns:
        true if 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 resolution
        adapter - ComponentAdapter to exclude
        keyType - the compatible type of the key
        valueType - the compatible type of the addComponent
        Returns:
        a Map with the ComponentAdapter instances and their component keys as map key.