org.picocontainer.gems.constraints
Class AbstractConstraint

java.lang.Object
  extended by org.picocontainer.parameters.CollectionComponentParameter
      extended by org.picocontainer.gems.constraints.AbstractConstraint
All Implemented Interfaces:
Serializable, Constraint, Parameter
Direct Known Subclasses:
And, Anything, IsExactType, IsKey, IsKeyType, IsType, Not, Or

public abstract class AbstractConstraint
extends CollectionComponentParameter
implements Constraint

Base class for parameter constraints.

Author:
Nick Sieger
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.picocontainer.parameters.CollectionComponentParameter
ARRAY, ARRAY_ALLOW_EMPTY
 
Fields inherited from interface org.picocontainer.Parameter
DEFAULT, ZERO
 
Constructor Summary
protected AbstractConstraint()
          Construct an AbstractContraint.
 
Method Summary
abstract  boolean evaluate(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.
 boolean isResolvable(PicoContainer container, ComponentAdapter adapter, Class expectedType, NameBinding expectedNameBinding, boolean useNames, Annotation binding)
          Check for a successful dependency resolution of the parameter for the expected type.
 Object resolveInstance(PicoContainer container, ComponentAdapter adapter, Class expectedType, NameBinding expectedNameBinding, boolean useNames, Annotation binding)
          Resolve the parameter for the expected type.
 void verify(PicoContainer container, ComponentAdapter adapter, Class 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.CollectionComponentParameter
accept
 
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
accept
 

Constructor Detail

AbstractConstraint

protected AbstractConstraint()
Construct an AbstractContraint.

Method Detail

resolveInstance

public Object resolveInstance(PicoContainer container,
                              ComponentAdapter adapter,
                              Class expectedType,
                              NameBinding expectedNameBinding,
                              boolean useNames,
                              Annotation binding)
                       throws PicoCompositionException
Description copied from class: CollectionComponentParameter
Resolve the parameter for the expected type. The method will return null If the expected type is not one of the collection types Array, Collectionor Map. An empty collection is only a valid resolution, if the emptyCollection flag was set.

Specified by:
resolveInstance in interface Parameter
Overrides:
resolveInstance in class CollectionComponentParameter
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.
expectedNameBinding - Expected parameter name
Returns:
the instance of the collection type or null
Throws:
PicoCompositionException - if a referenced component could not be instantiated.

isResolvable

public boolean isResolvable(PicoContainer container,
                            ComponentAdapter adapter,
                            Class expectedType,
                            NameBinding expectedNameBinding,
                            boolean useNames,
                            Annotation binding)
                     throws PicoCompositionException
Description copied from class: CollectionComponentParameter
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:
isResolvable in interface Parameter
Overrides:
isResolvable in class CollectionComponentParameter
Parameters:
container - the container from which dependencies are resolved.
adapter - the ComponentAdapter that is asking for the instance
expectedType - the required type
expectedNameBinding - Expected parameter name
Returns:
true if matching components were found or an empty collective type is allowed
Throws:
PicoCompositionException

verify

public void verify(PicoContainer container,
                   ComponentAdapter adapter,
                   Class expectedType,
                   NameBinding expectedNameBinding,
                   boolean useNames,
                   Annotation binding)
            throws PicoCompositionException
Description copied from class: CollectionComponentParameter
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
Overrides:
verify in class CollectionComponentParameter
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
Throws:
PicoCompositionException - if parameter and its dependencies cannot be resolved

evaluate

public abstract boolean evaluate(ComponentAdapter adapter)
Description copied from class: CollectionComponentParameter
Evaluate whether the given component adapter will be part of the collective type.

Specified by:
evaluate in interface Constraint
Overrides:
evaluate in class CollectionComponentParameter
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)
Description copied from class: CollectionComponentParameter
Collect the matching ComponentAdapter instances.

Overrides:
getMatchingComponentAdapters in class CollectionComponentParameter
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.


Copyright © 2003-2010 Codehaus. All Rights Reserved.