public class AdapterInjector extends java.lang.Object implements com.google.inject.MembersInjector<IAdaptable>
MembersInjector
that supports injection of adapters into
an IAdaptable
implementation class'
IAdaptable.setAdapter(TypeToken, Object, String)
method, that is
marked as being eligible for adapter injection (see InjectAdapters
).
Being registered for a specific IAdaptable
an AdapterInjector
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 to it via setInjector(Injector)
. It will inject
all adapters, for which adapter (map) 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.
The AdapterInjector
supports that type information about the actual
adapter type may be omitted from the adapter map binding (i.e. the used
AdapterKey
only provides a role but no type key). It will try to
infer the actual adapter type from respective bindings, or fall back to the
type inferred from the adapter instance (which will not be adequate for
generic types because of type erasure) in such a case.
AdapterMap
,
AdaptableTypeListener
Constructor and Description |
---|
AdapterInjector(java.lang.reflect.Method method)
Creates a new
AdapterInjector 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<?>> |
getApplicableAdapterMapBindings(java.lang.Class<?> adaptableType)
Retrieves all adapter map bindings where the adaptable type of the map
binding is the same or a super type or 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.
|
protected void |
injectAdapters(java.lang.Object adaptable,
java.util.List<java.lang.String> issues)
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 AdapterInjector(java.lang.reflect.Method method)
AdapterInjector
to inject the given Method
,
annotated with the given AdapterMap
method annotation.method
- The Method
to be injected.protected java.util.SortedMap<com.google.inject.Key<?>,com.google.inject.Binding<?>> getApplicableAdapterMapBindings(java.lang.Class<?> adaptableType)
adaptableType
- The type of the adaptable, whose method is to be injected.protected void injectAdapters(java.lang.Object adaptable)
adaptable
- The adaptable to inject adapters into.protected void injectAdapters(java.lang.Object adaptable, java.util.List<java.lang.String> issues)
adaptable
- The adaptable to inject adapters into.issues
- A String
list, to which issues may be added that arise
during injection.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.