|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.picocontainer.defaults.CollectionComponentParameter
public class CollectionComponentParameter
A CollectionComponentParameter should be used to support inject an Array
, a
Collection
or Map
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.
Field Summary | |
---|---|
static CollectionComponentParameter |
ARRAY
Use ARRAY as Parameter for an Array that must have elements. |
static CollectionComponentParameter |
ARRAY_ALLOW_EMPTY
Use ARRAY_ALLOW_EMPTY as Parameter for an Array that may have no
elements. |
private java.lang.Class |
componentKeyType
|
private java.lang.Class |
componentValueType
|
private boolean |
emptyCollection
|
private static MapFactory |
mapFactory
|
Constructor Summary | |
---|---|
CollectionComponentParameter()
Expect an Array of an appropriate type as parameter. |
|
CollectionComponentParameter(boolean emptyCollection)
Expect an Array of an appropriate type as parameter. |
|
CollectionComponentParameter(java.lang.Class componentValueType,
boolean emptyCollection)
Expect any of the collection types Array ,Collection or Map as
parameter. |
|
CollectionComponentParameter(java.lang.Class componentKeyType,
java.lang.Class componentValueType,
boolean emptyCollection)
Expect any of the collection types Array ,Collection or Map as
parameter. |
Method Summary | |
---|---|
void |
accept(PicoVisitor visitor)
Visit the current Parameter . |
protected boolean |
evaluate(ComponentAdapter adapter)
Evaluate whether the given component adapter will be part of the collective type. |
private java.lang.Object[] |
getArrayInstance(PicoContainer container,
java.lang.Class expectedType,
java.util.Map adapterList)
|
private java.util.Collection |
getCollectionInstance(PicoContainer container,
java.lang.Class expectedType,
java.util.Map adapterList)
|
private java.lang.Class |
getCollectionType(java.lang.Class collectionType)
|
private java.util.Map |
getMapInstance(PicoContainer container,
java.lang.Class expectedType,
java.util.Map adapterList)
|
protected java.util.Map |
getMatchingComponentAdapters(PicoContainer container,
ComponentAdapter adapter,
java.lang.Class keyType,
java.lang.Class valueType)
Collect the matching ComponentAdapter instances. |
private java.lang.Class |
getValueType(java.lang.Class collectionType)
|
boolean |
isResolvable(PicoContainer container,
ComponentAdapter adapter,
java.lang.Class expectedType)
Check for a successful dependency resolution of the parameter for the expected type. |
java.lang.Object |
resolveInstance(PicoContainer container,
ComponentAdapter adapter,
java.lang.Class expectedType)
Resolve the parameter for the expected type. |
void |
verify(PicoContainer container,
ComponentAdapter adapter,
java.lang.Class expectedType)
Verify a successful dependency resolution of the parameter for the expected type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final MapFactory mapFactory
public static final CollectionComponentParameter ARRAY
ARRAY
as Parameter
for an Array that must have elements.
public static final CollectionComponentParameter ARRAY_ALLOW_EMPTY
ARRAY_ALLOW_EMPTY
as Parameter
for an Array that may have no
elements.
private final boolean emptyCollection
private final java.lang.Class componentKeyType
private final java.lang.Class componentValueType
Constructor Detail |
---|
public CollectionComponentParameter()
Array
of an appropriate type as parameter. At least one component of
the array's component type must exist.
public CollectionComponentParameter(boolean emptyCollection)
Array
of an appropriate type as parameter.
emptyCollection
- true
if an empty array also is a valid dependency
resolution.public CollectionComponentParameter(java.lang.Class componentValueType, boolean emptyCollection)
Array
,Collection
or Map
as
parameter.
componentValueType
- the type of the components (ignored in case of an Array)emptyCollection
- true
if an empty collection resolves the
dependency.public CollectionComponentParameter(java.lang.Class componentKeyType, java.lang.Class componentValueType, boolean emptyCollection)
Array
,Collection
or Map
as
parameter.
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 |
---|
public java.lang.Object resolveInstance(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
null
If the expected type is not one of the collection types Array
,
Collection
or Map
. An empty collection is only a valid resolution, if
the emptyCollection
flag was set.
resolveInstance
in interface Parameter
container
- the container from which dependencies are resolved.adapter
- the ComponentAdapter
that is asking for the instanceexpectedType
- the type that the returned instance needs to match.
null
PicoInitializationException
- if a referenced component could not be instantiated.public boolean isResolvable(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
Array
,Collection
or Map
. An empty collection is only a valid
resolution, if the emptyCollection
flag was set.
isResolvable
in interface Parameter
container
- the container from which dependencies are resolved.adapter
- the ComponentAdapter
that is asking for the instanceexpectedType
- the required type
true
if matching components were found or an empty collective type
is allowedpublic void verify(PicoContainer container, ComponentAdapter adapter, java.lang.Class expectedType)
Array
,
Collection
or Map
. An empty collection is only a valid resolution, if
the emptyCollection
flag was set.
verify
in interface Parameter
container
- the container from which dependencies are resolved.adapter
- the ComponentAdapter
that is asking for the verificationexpectedType
- the required type
PicoIntrospectionException
- if parameter and its dependencies cannot be resolvedpublic void accept(PicoVisitor visitor)
Parameter
.
accept
in interface Parameter
visitor
- the visitor.Parameter.accept(org.picocontainer.PicoVisitor)
protected boolean evaluate(ComponentAdapter adapter)
adapter
- a ComponentAdapter
value
true
if the adapter takes partprotected java.util.Map getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, java.lang.Class keyType, java.lang.Class valueType)
container
- container to use for dependency resolutionadapter
- ComponentAdapter
to excludekeyType
- the compatible type of the keyvalueType
- the compatible type of the component
Map
with the ComponentAdapter instances and their component keys as map key.private java.lang.Class getCollectionType(java.lang.Class collectionType)
private java.lang.Class getValueType(java.lang.Class collectionType)
private java.lang.Object[] getArrayInstance(PicoContainer container, java.lang.Class expectedType, java.util.Map adapterList)
private java.util.Collection getCollectionInstance(PicoContainer container, java.lang.Class expectedType, java.util.Map adapterList)
private java.util.Map getMapInstance(PicoContainer container, java.lang.Class expectedType, java.util.Map adapterList)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |