T
- the class the instances of which will be created by this ConstructorInstantiatorpublic class ConstructorInstantiatorWithArguments<T> extends ConstructorInstantiator<T>
instantiate
method.
This class provides a convenient way of repeatable creation of instances of a given class without the need of repeatable constructor retrieval and checking all the exceptions.
Constructor and Description |
---|
ConstructorInstantiatorWithArguments(java.lang.Class<? extends T> objectClass,
java.lang.Object... arguments)
Creates a new instance of ConstructorInstantiatorWithArguments for creating instances of
objectClass that accepts the given arguments. |
ConstructorInstantiatorWithArguments(java.lang.Class<? extends T> objectClass,
java.lang.String[] arguments,
int offset,
int length,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Creates a new instance of ConstructorInstantiatorWithArguments for creating instances of
objectClass that accepts the given string arguments. |
ConstructorInstantiatorWithArguments(java.lang.reflect.Constructor<? extends T> constructor,
java.lang.Object... arguments)
Creates a new instance of ConstructorInstantiatorWithArguments for creating instances of
T using the specified constructor and with the given stored arguments.
|
Modifier and Type | Method and Description |
---|---|
T |
instantiate()
Creates a new instance using the encapsulated constructor with the stored arguments.
|
T |
instantiate(java.lang.Object... arguments)
Creates a new instance using the encapsulated constructor.
|
createInstanceWithStringArgs, createInstanceWithStringArgs, getConstructor, getConstructor, getConstructor, getConstructor, getInstantiatorClass, getInstantiatorPrototype, instantiateByConstructor, toString
public ConstructorInstantiatorWithArguments(java.lang.reflect.Constructor<? extends T> constructor, java.lang.Object... arguments) throws NoSuchInstantiatorException
constructor
- the constructor using which the instances will be createdarguments
- the stored arguments for the constructorNoSuchInstantiatorException
- if the provided class does not have a proper constructorpublic ConstructorInstantiatorWithArguments(java.lang.Class<? extends T> objectClass, java.lang.Object... arguments) throws NoSuchInstantiatorException
objectClass
that accepts the given arguments.objectClass
- the class the instances of which will be createdarguments
- the arguments for the constructorNoSuchInstantiatorException
- if the provided class does not have a proper constructorpublic ConstructorInstantiatorWithArguments(java.lang.Class<? extends T> objectClass, java.lang.String[] arguments, int offset, int length, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws NoSuchInstantiatorException
objectClass
that accepts the given string arguments.
Note that string arguments will be converted to the proper types using Convert.stringToType(java.lang.String, java.lang.Class<E>, java.util.Map<java.lang.String, ? extends java.lang.Object>)
.objectClass
- the class the instances of which will be createdarguments
- the string arguments for the constructor (will be converted to proper types)offset
- the index of the first argument to use from the arguments
arraylength
- the number of arguments that will be used from the arguments
array (starting from offset)namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the mapNoSuchInstantiatorException
- if the provided class does not have a proper constructorpublic T instantiate(java.lang.Object... arguments) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
creating
this
ConstructorInstantiator
class.
For every given argument that is null, the stored value
is used.instantiate
in interface Instantiator<T>
instantiate
in class ConstructorInstantiator<T>
arguments
- the arguments for the encapsulated constructorjava.lang.IllegalArgumentException
- if the arguments are not compatible with the constructor prototypejava.lang.reflect.InvocationTargetException
- if there was an exception thrown when the constructor was invokedpublic T instantiate() throws java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
- if there was an exception thrown when the constructor was invoked