public class ValueInjector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class,StringConverter> |
converters
A mapping between desired types and suitable @
StringConverter . |
private static ValueInjector |
instance
A default instance
|
Constructor and Description |
---|
ValueInjector() |
Modifier and Type | Method and Description |
---|---|
<T> void |
addConverter(java.lang.Class<T> clazz,
StringConverter<T> conv)
Registers the given converter for the specified class.
|
private java.lang.Object |
convert(ProofScriptArgument<?> meta,
java.lang.String val) |
static ValueInjector |
createDefault()
Returns a fresh instance of a
ValueInjector with the support
for basic primitive data types. |
<T> StringConverter<T> |
getConverter(java.lang.Class<T> clazz)
Finds a converter for the given class.
|
static ValueInjector |
getInstance()
Returns the default instance of a
ValueInjector
Use with care. |
private java.util.Map<java.lang.String,java.lang.Object> |
getStringMap(java.lang.Object obj,
ProofScriptArgument<?> vararg) |
<T> T |
inject(ProofScriptCommand<?> command,
T obj,
java.util.Map<java.lang.String,java.lang.String> arguments)
Injects the converted version of the given
arguments in the given obj . |
private void |
injectIntoField(ProofScriptArgument<?> meta,
java.util.Map<java.lang.String,java.lang.String> args,
java.lang.Object obj) |
static <T> T |
injection(ProofScriptCommand<?> command,
T obj,
java.util.Map<java.lang.String,java.lang.String> arguments)
Injects the given
arguments in the obj . |
private static ValueInjector instance
getInstance()
private java.util.Map<java.lang.Class,StringConverter> converters
public static <T> T injection(ProofScriptCommand<?> command, T obj, java.util.Map<java.lang.String,java.lang.String> arguments) throws ArgumentRequiredException, InjectionReflectionException, NoSpecifiedConverterException, ConversionException
arguments
in the obj
.
For more details see inject(ProofScriptCommand, Object, Map)
T
- an arbitrary typecommand
- a proof script commandobj
- a parameter class with annotationarguments
- a non-null map of string pairsobj
ArgumentRequiredException
- a required argument was not given in arguments
InjectionReflectionException
- an access on some reflection methods occurredNoSpecifiedConverterException
- unknown type for the current converter mapConversionException
- an converter could not translate the given value in
public static ValueInjector getInstance()
ValueInjector
Use with care. No multi-threading.createDefault()
public static ValueInjector createDefault()
ValueInjector
with the support
for basic primitive data types.public <T> T inject(ProofScriptCommand<?> command, T obj, java.util.Map<java.lang.String,java.lang.String> arguments) throws ConversionException, InjectionReflectionException, NoSpecifiedConverterException, ArgumentRequiredException
arguments
in the given obj
.T
- type safetycommand
- a proof script commandobj
- a non-null instance of a parameter class (with annotation)arguments
- a non-null string mapobj
ArgumentRequiredException
- a required argument was not given in arguments
InjectionReflectionException
- an access on some reflection methods occurredNoSpecifiedConverterException
- unknown type for the current converter mapConversionException
- an converter could not translate the given value
in Option
,
Flag
private java.util.Map<java.lang.String,java.lang.Object> getStringMap(java.lang.Object obj, ProofScriptArgument<?> vararg) throws InjectionReflectionException
InjectionReflectionException
private void injectIntoField(ProofScriptArgument<?> meta, java.util.Map<java.lang.String,java.lang.String> args, java.lang.Object obj) throws InjectionReflectionException, ArgumentRequiredException, ConversionException, NoSpecifiedConverterException
private java.lang.Object convert(ProofScriptArgument<?> meta, java.lang.String val) throws NoSpecifiedConverterException, ConversionException
public <T> void addConverter(java.lang.Class<T> clazz, StringConverter<T> conv)
T
- an arbitrary typeclazz
- a classconv
- a converter for the given classpublic <T> StringConverter<T> getConverter(java.lang.Class<T> clazz)
T
- an arbitrary typeclazz
- a non-null class