@Documented
@Target(value=PARAMETER)
@Retention(value=RUNTIME)
public @interface AdapterMap
BindingAnnotation
that can be used to annotate the single parameter
(of type Map<AdapterKey<?>, Object>
) of an
IAdaptable
's method (annotated with an Inject
annotation) to
make it eligible for adapter map injection. The annotation is also used to
qualify related AdapterMap
bindings (i.e. specific
MapBinderBinding
s) within a Module
.
In order to enable the adapter map injection mechanism, one of the
Module
s being used to create the Injector
has to bind an
AdaptableTypeListener
. This AdaptableTypeListener
will
register a specific MembersInjector
, the AdapterMapInjector
,
whenever it encounters an IAdaptable
type that is eligible for
adapter map injection. The AdapterMapInjector
will in turn inject all
IAdaptable
instances of that type, evaluating all AdapterMap
bindings that can be obtained from the Injector
with which the
AdaptableTypeListener
was injected. In detail, it will inject into an
IAdaptable
all adapters, which are bound to an AdapterMap
annotation of a type ( adaptableType()
), which is either
the same or a super-type or super-interface of the IAdaptable
to be
injected.
IAdaptable
,
AdaptableTypeListener
,
AdapterMapInjector
Modifier and Type | Optional Element and Description |
---|---|
java.lang.Class<?> |
adaptableType
The type used to qualify the
AdapterMap annotation. |
public abstract java.lang.Class<?> adaptableType
AdapterMap
annotation. It is used to
infer which bindings are taken into consideration when performing adapter
map injection on an IAdaptable
's method.
That is, when injecting a method with an adapter map only those bindings
that are annotated with an AdapterMap
annotation, whose
IAdaptable
type ( adaptableType()
) is either the same
or a super-type or super-interface of the to be injected
IAdaptable
instance's runtime type will be considered.
If a type is specified at an injection point (i.e. when annotating a
method parameter within an IAdaptable
annotation), it is simply
ignored by the AdapterMapInjector
. The runtime type of the to be
injected IAdaptable
instance is instead considered.
Please note that while the AdapterMapInjector
ignores the type
specified at the injection point (i.e. at the AdapterMap
-annotated method parameter), Guice will still evaluate it and will
require an AdapterMap
binding for the type (i.e.
IAdaptable
if no type is specified and the default is used),
unless the injection point is explicitly marked to be optional (
@Inject(optional = true)
), which is thus highly recommended.
Class
used as type of this AdapterMap
.
IAdaptable
by default.Copyright (c) 2014 itemis AG and others. All rights reserved.