Class SimpleInjector<T>
java.lang.Object
ch.tocco.nice2.toolbox.api.inject.SimpleInjector<T>
- All Implemented Interfaces:
Injector<T>
When instantiating, the first constructor where every argument can be found is used, where the order is from
the most parameters to the least.
When initializing, first all setter methods are tried. Again the setters are only invoked if there is a
argument value for every parameter. After this, all fields (which still null) are set if a value can be
found. By default the type of the field/parameter is used to get the value from the
annotation.
At last the object to initialize is checked for implementing
. If so, the
method is invoked.
ValueProvider
.
This can be overriden specifying the type using the
invalid reference
javax.annotation.Resource
invalid reference
Initializable
invalid reference
Initializable#afterInitialize()
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final Object
getFieldValue
(Object target, Field field) void
initialize
(T object, ValueProvider provider) First it usesIntrospector
to invoke all setter methods.protected boolean
injectField
(T object, Field field, FieldIterable.FieldIterator iter) Check whether to set a field value.instantiate
(ValueProvider provider) Creates a new instance by searching for a ctor that can be matched using values from the specified value provider.protected void
invokeSetMethod
(T owner, ValueProvider provider, PropertyDescriptor pdesc, Object curval, Class<?> beanClass) protected void
invokeSetter
(T owner, ValueProvider provider, BeanInfo info) protected void
setFields
(T object, ValueProvider provider) protected final void
setFieldValue
(Object target, Field field, Object value) toString()
-
Constructor Details
-
SimpleInjector
-
SimpleInjector
public SimpleInjector()
-
-
Method Details
-
instantiate
Description copied from interface:Injector
Creates a new instance by searching for a ctor that can be matched using values from the specified value provider. The best constructor is used, which is the one with the greatest number of arguments that can be retrieved using the specifiedValueProvider
.- Specified by:
instantiate
in interfaceInjector<T>
-
initialize
First it usesIntrospector
to invoke all setter methods. Then all fields are queried and each one is initialized if it isnull
. At last if theobject
implementsinvalid reference
Initializable
invalid reference
Initializable#afterInitialize()
- Specified by:
initialize
in interfaceInjector<T>
-
injectField
Check whether to set a field value. This will return true for non-final fields that don't have a value yet and only non-private fields of superclass(es). -
setFields
-
invokeSetter
-
invokeSetMethod
protected void invokeSetMethod(T owner, ValueProvider provider, PropertyDescriptor pdesc, Object curval, Class<?> beanClass) -
getFieldValue
-
setFieldValue
-
toString
-