@Documented
@Target(value=PARAMETER)
@Retention(value=RUNTIME)
public @interface AdapterMap
BindingAnnotation
that can be used to qualify adapter (map)
bindings, i.e. provide type information related to valid IAdaptable
injection points.
Clients should not use it directly, but rather query
AdapterMaps.getAdapterMapBinder(com.google.inject.Binder, Class)
to
obtain a map binder that already qualifies its bindings with the respective
AdapterMap
annotation for a given type. Adapter (map) bindings can
then be specified as follows:
// Obtain a map binder bound to MyAdaptable. MapBinder<AdapterKey<?>, Object> adapterMapBinder = AdapterMaps.getAdapterMapBinder(binder(), MyAdaptable.class); // Bind instance of raw type 'A' as adapter with 'default' role to each MyAdaptable instance. // The AdapterKey does not have to specify the adapter type, as it can be inferred from the binding and/or the adapter instance. adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(A.class); // Bind instance of parameterized type 'B<A>' as adapter with 'r' role to each MyAdaptable instance. // The AdapterKey does not have to specify the adapter type, as it can be inferred from the binding. adapterMapBinder.addBinding(AdapterKey.role("r").to(new TypeLiteral<B<A>>(){}); // Bind instance 'c' of parameterized type 'C<A>' as adapter with 'r' role to each MyAdaptable instance. // The AdapterKey has to specify the adapter type, as it cannot be inferred from the binding or adapter instance. adapterMapBinder.addBinding(AdapterKey.get(new TypeToken<C<A>>(){}, "r").toInstance(c);If an
IAdaptable
marks itself as eligible for adapter injection (see
InjectAdapters
), all adapter (map bindings) that are bound to a
type
(by being qualified with a respective
AdapterMap
annotation), which is either the same or a super-type or
super-interface of the IAdaptable
will be evaluated, and respective
adapters will be injected.
In order to enable adapter injection, AdapterInjectionSupport
has to
be installed by one of the Module
s used by the Injector
.
IAdaptable
,
AdaptableTypeListener
,
AdapterInjector
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
injection on an IAdaptable
's method.
That is, when injecting adapters into
IAdaptable.setAdapter(TypeToken, Object, String)
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.
Class
used as type of this AdapterMap
.
IAdaptable
by default.Copyright (c) 2014 itemis AG and others. All rights reserved.