|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.utility.reflection.Instantiators
public abstract class Instantiators
Collection of utility methods for Instantiator
s.
Constructor Summary | |
---|---|
Instantiators()
|
Method Summary | ||
---|---|---|
static java.lang.Object |
createInstanceStaticField(java.lang.Class<?> clazz,
java.lang.String name)
Get instance from a static field of a class. |
|
static
|
createInstanceUsingFactoryMethod(java.lang.Class<?> declaringClass,
java.lang.String methodName,
java.lang.Class<E> instanceClass,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.lang.String... arguments)
Creates a new instance of a class. |
|
static
|
createInstanceUsingFactoryMethod(java.lang.Class<E> instanceClass,
java.lang.String methodName,
java.lang.Object... arguments)
Creates a new instance of a class. |
|
static
|
createInstanceWithInheritableArgs(java.lang.Class<E> instanceClass,
java.lang.Object... arguments)
Creates a new instance of a class. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String... arguments)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String[] arguments,
int argStartIndex)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String[] arguments,
int argStartIndex,
int argEndIndex)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String[] arguments,
int argStartIndex,
int argEndIndex,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String[] arguments,
int argStartIndex,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors,
java.lang.String[] arguments,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Creates a new instance of a class using string arguments for its constructor. |
|
static
|
createInstanceWithStringArgs(java.lang.String signature,
java.lang.Class<E> checkClass,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Creates a new instance of a class with a string constructor/factory-method/static-field signature. |
|
static
|
getConstructor(java.lang.Class<E> clazz,
boolean convertStringArguments,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.lang.Object[] arguments)
Returns a constructor for the specified class that accepts the specified arguments. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
boolean convertStringArguments,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.lang.Object[] arguments)
Returns a method for the specified class that accepts the specified arguments. |
|
static boolean |
isPrototypeMatching(java.lang.Class<?>[] methodTypes,
java.lang.Class<?>[] methodPrototype)
Test argument array, if it is compatible with the provided prototype. |
|
static boolean |
isPrototypeMatching(java.lang.Class<?>[] methodTypes,
java.lang.Class<?>[] methodPrototype,
int skipIndex)
Test argument array, if it is compatible with the provided prototype. |
|
static boolean |
isPrototypeMatching(java.lang.Class<?>[] prototype,
java.lang.Object[] arguments,
boolean convertStringArguments,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Test argument array, if it is compatible with the provided prototype. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Instantiators()
Method Detail |
---|
public static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String[] arguments, int argStartIndex, int argEndIndex, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the number of arguments equal to argEndIndex - argStartIndex + 1
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct typesargStartIndex
- index in the string arguments array from which to expect arguments (all the previous items are ignored)argEndIndex
- index in the string arguments array to which to expect arguments (all the following items are ignored)namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the map
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String[] arguments, int argStartIndex, int argEndIndex) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the number of arguments equal to argEndIndex - argStartIndex + 1
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
Note also that LocalAbstractObject
parameters will not be converted. For this fuctionality,
use the full createInstanceWithStringArgs
method instead.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct typesargStartIndex
- index in the string arguments array from which to expect arguments (all the previous items are ignored)argEndIndex
- index in the string arguments array to which to expect arguments (all the following items are ignored)
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String[] arguments, int argStartIndex) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the number of arguments equal to arguments.length - argStartIndex
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
Note also that LocalAbstractObject
parameters will not be converted. For this fuctionality,
use the full createInstanceWithStringArgs
method instead.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct typesargStartIndex
- index in the string arguments array from which to expect arguments (all the previous items are ignored)
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String[] arguments, int argStartIndex, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the number of arguments equal to arguments.length - argStartIndex
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct typesargStartIndex
- index in the string arguments array from which to expect arguments (all the previous items are ignored)namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the map
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String... arguments) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the same number of arguments as the length of arguments
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
Note also that LocalAbstractObject
parameters will not be converted. For this fuctionality,
use the full createInstanceWithStringArgs
method instead.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct types
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.util.List<java.lang.reflect.Constructor<E>> constructors, java.lang.String[] arguments, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws java.lang.reflect.InvocationTargetException
constructors
argument.
The constructors are tried one by one from this list and if the arguments
are convertible to the arguments of that constructor, a new instance is created.
Note that only constructors with the same number of arguments as the length of arguments
are tried. If there are several constructors with the same number of arguments, the first (in the order
of the list) constructor that succeeds in converting string arguments will be used.
Note also that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in constructors.
E
- the type of the instantiated objectconstructors
- the list of constructors of the desired class to tryarguments
- the string arguments for the constructor that will be converted to correct typesnamedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the map
java.lang.reflect.InvocationTargetException
- if the constructor can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiationpublic static <E> E createInstanceWithStringArgs(java.lang.String signature, java.lang.Class<E> checkClass, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundException
messif.pivotselection.StreamSequencePivotChooser(messif.objects.impl.MetaObjectMap, file)Or the string can be a fully specified name of a factory method (package.class.methodName) with arguments enclosed by parenthesis, e.g.:
messif.utility.ExtendedProperties.getProperties(file)Or the string can be a fully specified name of a public static field (package.class.fieldName), e.g.:
messif.buckets.index.LocalAbstractObjectOrder.locatorToLocalObjectComparator
Note that only types convertible by Convert.stringToType(java.lang.String, java.lang.Class
method can be used in arguments.
E
- the type of the instantiated objectsignature
- constructor or factory method call with string arguments or a static fieldcheckClass
- the superclass of (or the same class as) the instantiated objectnamedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the map
java.lang.reflect.InvocationTargetException
- if the constructor/factory-method/static-field can't be found for the specified arguments,
the argument string-to-type convertion has failed or
there was an error during instantiation
java.lang.ClassNotFoundException
- if the class in the constructor signature was not found or is not a descendant of checkClasspublic static <E> E createInstanceWithInheritableArgs(java.lang.Class<E> instanceClass, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
E
- the type of the instantiated objectinstanceClass
- the class for which to create an instancearguments
- the arguments for the constructor
java.lang.NoSuchMethodException
- if there was no constructor for the specified list of arguments
java.lang.reflect.InvocationTargetException
- if there was an exception during instantiationpublic static <E> E createInstanceUsingFactoryMethod(java.lang.Class<E> instanceClass, java.lang.String methodName, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
E
- the type of the instantiated objectinstanceClass
- the class for which to create an instancemethodName
- the name of the factory methodarguments
- the arguments for the factory method
java.lang.NoSuchMethodException
- if there was no factory method for the specified list of arguments
java.lang.reflect.InvocationTargetException
- if there was an exception during instantiationpublic static <E> E createInstanceUsingFactoryMethod(java.lang.Class<?> declaringClass, java.lang.String methodName, java.lang.Class<E> instanceClass, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.lang.String... arguments) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
E
- the type of the instantiated objectdeclaringClass
- the class where the factory method is declaredmethodName
- the name of the factory methodinstanceClass
- the class for which to create an instancenamedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the maparguments
- the arguments for the factory method
java.lang.IllegalArgumentException
- if there was no factory method for the specified list of arguments or has wrong parameters
java.lang.reflect.InvocationTargetException
- if there was an exception during instantiationpublic static java.lang.Object createInstanceStaticField(java.lang.Class<?> clazz, java.lang.String name) throws java.lang.IllegalArgumentException
clazz
- the class the field of which to accessname
- the name of the clazz
's static field
java.lang.IllegalArgumentException
- if there was no public static field for the specified clazz
and name
public static <E> java.lang.reflect.Constructor<E> getConstructor(java.lang.Class<E> clazz, boolean convertStringArguments, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
clazz
's declared constructors are searched for the one that
accepts the arguments.
If the convertStringArguments
is specified, the
arguments
elements are replaced with the converted types
if and only if a proper constructor is found. Their types then will be
compatible with the constructor.
E
- the class the constructor will createclazz
- the class for which to get the constructorconvertStringArguments
- if true the string values from the arguments are converted using Convert.stringToType(java.lang.String, java.lang.Class, java.util.Map)
namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the maparguments
- the arguments for the constructor
java.lang.NoSuchMethodException
- if there was no constructor for the specified list of argumentspublic static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String methodName, boolean convertStringArguments, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
clazz
's declared methods are searched for the one that
accepts the arguments.
If the convertStringArguments
is specified, the
arguments
elements are replaced with the converted types
if and only if a proper method is found. Their types then will be
compatible with the method.
clazz
- the class for which to get the methodmethodName
- the name of the method to getconvertStringArguments
- if true the string values from the arguments are converted using Convert.stringToType(java.lang.String, java.lang.Class, java.util.Map)
namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the maparguments
- the arguments for the method
java.lang.NoSuchMethodException
- if there was no method with the specified name and argumentspublic static boolean isPrototypeMatching(java.lang.Class<?>[] methodTypes, java.lang.Class<?>[] methodPrototype, int skipIndex)
methodTypes
) must be assignable
from the respective methodPrototype
item.
methodTypes
- the tested arguments arraymethodPrototype
- the prototype arguments arrayskipIndex
- the index of an argument that is not checked for the compatibility condition
public static boolean isPrototypeMatching(java.lang.Class<?>[] methodTypes, java.lang.Class<?>[] methodPrototype)
methodTypes
must be assignable
from the respective methodPrototype
item.
methodTypes
- the tested arguments arraymethodPrototype
- the prototype arguments array
public static boolean isPrototypeMatching(java.lang.Class<?>[] prototype, java.lang.Object[] arguments, boolean convertStringArguments, java.util.Map<java.lang.String,java.lang.Object> namedInstances)
prototype
item.
If the convertStringArguments
is specified, the
arguments
elements are replaced with the converted types
if and only if the method returns true.
prototype
- the tested prototypearguments
- the tested argumentsconvertStringArguments
- if true the string values from the arguments are converted using Convert.stringToType(java.lang.String, java.lang.Class, java.util.Map)
namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the map
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |