Package aQute.lib.inject
Class Injector<T extends java.lang.annotation.Annotation>
- java.lang.Object
-
- aQute.lib.inject.Injector<T>
-
- Type Parameters:
T
- the annotation type
public class Injector<T extends java.lang.annotation.Annotation> extends java.lang.Object
This class is a simple injector with a parameterized annotation. A domain function is provided to retrieve the values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Injector.Target<T>
The Target class describes the target injection point.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Class<T>
annotation
(package private) Converter
converter
(package private) java.util.function.Function<Injector.Target<T>,java.lang.Object>
domain
-
Constructor Summary
Constructors Constructor Description Injector(Converter converter, java.util.function.Function<Injector.Target<T>,java.lang.Object> domain, java.lang.Class<T> annotation)
Create a new InjectorInjector(java.util.function.Function<Injector.Target<T>,java.lang.Object> domain, java.lang.Class<T> annotation)
Create a new Injector with a default converter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<java.lang.Class<?>>
getAbove(java.lang.Class<?> clazz)
private java.util.Collection<java.lang.reflect.Field>
getFields(java.lang.Class<?> clazz)
private java.util.Collection<java.lang.reflect.Method>
getMethods(java.lang.Class<?> clazz)
private java.lang.Object
getValue(Injector.Target<T> param)
void
inject(java.lang.Object target)
Inject an object.private java.lang.Object[]
invoke(java.lang.Object target, Injector.Target<T> param, java.lang.reflect.Executable method)
<F> F
newInstance(java.lang.Class<F> type)
-
-
-
Field Detail
-
converter
final Converter converter
-
annotation
final java.lang.Class<T extends java.lang.annotation.Annotation> annotation
-
domain
final java.util.function.Function<Injector.Target<T extends java.lang.annotation.Annotation>,java.lang.Object> domain
-
-
Constructor Detail
-
Injector
public Injector(Converter converter, java.util.function.Function<Injector.Target<T>,java.lang.Object> domain, java.lang.Class<T> annotation)
Create a new Injector- Parameters:
converter
- the converter to use for conversionsdomain
- the domain function that retrieves valuesannotation
- the annotation that triggers a call to the domain
-
Injector
public Injector(java.util.function.Function<Injector.Target<T>,java.lang.Object> domain, java.lang.Class<T> annotation)
Create a new Injector with a default converter- Parameters:
domain
- the domain function that retrieves valuesannotation
- the annotation that triggers a call to the domain
-
-
Method Detail
-
inject
public void inject(java.lang.Object target) throws java.lang.Exception
Inject an object. This will inject fields and methods. Methods must have one or more arguments. The first argument is special and is always passed to the domain function as the primaryType.- Parameters:
target
- the target object to inject- Throws:
java.lang.Exception
-
newInstance
public <F> F newInstance(java.lang.Class<F> type) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getFields
private java.util.Collection<java.lang.reflect.Field> getFields(java.lang.Class<?> clazz)
-
getMethods
private java.util.Collection<java.lang.reflect.Method> getMethods(java.lang.Class<?> clazz)
-
getAbove
private java.util.List<java.lang.Class<?>> getAbove(java.lang.Class<?> clazz)
-
getValue
private java.lang.Object getValue(Injector.Target<T> param) throws java.lang.Exception
- Throws:
java.lang.Exception
-
invoke
private java.lang.Object[] invoke(java.lang.Object target, Injector.Target<T> param, java.lang.reflect.Executable method) throws java.lang.Exception, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.Exception
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
-