public class AdapterMapInjector extends java.lang.Object implements com.google.inject.MembersInjector<IAdaptable>
MembersInjector
to support adapter map injection, i.e.
injection of adapters into IAdaptable
instances. Will be able to
perform adapter map injection if being registered (by an
AdaptableTypeListener
) on an IAdaptable
encounter, which:
Inject
, andMap<AdapterKey<?>, Object>
, which is annotated with
an AdapterMap
annotation.IAdaptable
an
AdapterMapInjector
will inject all instances of that type or any
sub-type, evaluating all AdapterMap
bindings that can be obtained
from the Injector
which was forwarded by the
AdaptableTypeListener
via setInjector(Injector)
. This means,
that it will inject via the respective method all adapters, for which
bindings with a matching AdapterMap
annotation exist. Here, matching
means, that the type provided in the AdapterMap
annotation of the
IAdaptable
#s method (AdapterMap.adaptableType()
) is either
the same or a sub-type of the type used with the AdapterMap
annotation of the related binding.AdapterMap
,
AdaptableTypeListener
Constructor and Description |
---|
AdapterMapInjector(java.lang.reflect.Method method,
AdapterMap methodAnnotation)
Creates a new
AdapterMapInjector to inject the given
Method , annotated with the given AdapterMap method
annotation. |
Modifier and Type | Method and Description |
---|---|
protected java.util.SortedMap<com.google.inject.Key<?>,com.google.inject.Binding<?>> |
getPolymorphicAdapterMapBindings(java.lang.Class<?> adaptableType,
java.lang.reflect.Method method,
AdapterMap methodAnnotation)
Retrieves all adapter map bindings where the adaptable type of the map
binding is a true super type or true super interface of the one referred
to in the given method annotation, and assignable from the given
adaptable type.
|
protected void |
injectAdapters(java.lang.Object adaptable)
Performs the adapter map injection for the given adaptable instance.
|
void |
injectMembers(IAdaptable instance) |
void |
setInjector(com.google.inject.Injector injector)
Sets the
Injector , being used for adapter map injection. |
public AdapterMapInjector(java.lang.reflect.Method method, AdapterMap methodAnnotation)
AdapterMapInjector
to inject the given
Method
, annotated with the given AdapterMap
method
annotation.method
- The Method
to be injected.methodAnnotation
- The AdapterMap
annotation specified at the single
parameter of the to be injected method.protected java.util.SortedMap<com.google.inject.Key<?>,com.google.inject.Binding<?>> getPolymorphicAdapterMapBindings(java.lang.Class<?> adaptableType, java.lang.reflect.Method method, AdapterMap methodAnnotation)
As Guice will already inject those map bindings, where the adaptable type of the map binding is the same as the one given in the method annotation, these are ignored here. Instead, only those bindings are computed where the type in the method annotation is not equal to the one of the map binding, and where the type of the map binding is assignable from the given concrete adaptable type.
adaptableType
- The concrete (runtime) adaptable type of the adaptable, whose
method is to be injected.method
- The to be injected method of the adaptable type.methodAnnotation
- The AdapterMap
method annotation of the to be injected
adaptable's method.protected void injectAdapters(java.lang.Object adaptable)
adaptable
- The adaptable to inject adapters into.public void injectMembers(IAdaptable instance)
injectMembers
in interface com.google.inject.MembersInjector<IAdaptable>
@Inject public void setInjector(com.google.inject.Injector injector)
Injector
, being used for adapter map injection.injector
- The Injector
to use.Copyright (c) 2014 itemis AG and others. All rights reserved.