|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.utility.reflection.FactoryMethodInstantiator<T>
T
- the class the instances of which will be created by this FactoryMethodInstantiatorpublic class FactoryMethodInstantiator<T>
This class allows to create instances of a given class. A factory method with the given prototype is encapsulated and used in subsequent calls. Note that a factory method must be static and must return the object of the given class.
This class provides a convenient way of repeatable creation of instances of a given class without the need of repetable factory method retrieval and checking all the exceptions.
Constructor Summary | |
---|---|
FactoryMethodInstantiator(java.lang.Class<? extends T> checkClass,
java.lang.Class<?> methodClass,
java.lang.String methodName,
java.lang.Class<?>... prototype)
Creates a new instance of FactoryMethodInstantiator for creating instances of objectClass that accepts parameters of the given prototype. |
|
FactoryMethodInstantiator(java.lang.Class<? extends T> checkClass,
java.lang.Class<?> methodClass,
java.lang.String methodName,
int argumentCount)
Creates a new instance of FactoryMethodInstantiator for creating instances of objectClass that accepts the given number of parameters. |
|
FactoryMethodInstantiator(java.lang.Class<? extends T> objectClass,
java.lang.reflect.Method method)
Creates a new instance of FactoryMethodInstantiator for creating instances of objectClass via the given method. |
Method Summary | |
---|---|
java.lang.Class<? extends T> |
getInstantiatorClass()
Returns the class instantiated by this Instantiator. |
java.lang.Class<?>[] |
getInstantiatorPrototype()
Returns the classes of arguments for the Instantiator.instantiate(java.lang.Object[]) method. |
T |
instantiate(java.lang.Object... arguments)
Creates a new instance using the encapsulated factory method. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FactoryMethodInstantiator(java.lang.Class<? extends T> objectClass, java.lang.reflect.Method method) throws java.lang.IllegalArgumentException
objectClass
via the given method.
objectClass
- the class the instances of which will be createdmethod
- the factory method used to create instances
java.lang.IllegalArgumentException
- if the provided method is not static or does not return the given objectClasspublic FactoryMethodInstantiator(java.lang.Class<? extends T> checkClass, java.lang.Class<?> methodClass, java.lang.String methodName, java.lang.Class<?>... prototype) throws java.lang.IllegalArgumentException
objectClass
that accepts parameters of the given prototype.
checkClass
- the class the instances of which will be createdmethodClass
- the class from which the method is takenmethodName
- the name of the factory method within the objectClass
prototype
- the types of constructor arguments
java.lang.IllegalArgumentException
- if the there is no method for the given name and prototype or
if such method is not static or does not return the given objectClasspublic FactoryMethodInstantiator(java.lang.Class<? extends T> checkClass, java.lang.Class<?> methodClass, java.lang.String methodName, int argumentCount) throws java.lang.IllegalArgumentException
objectClass
that accepts the given number of parameters.
Note that if there are several methods of the same name and number of arguments,
one is selected.
checkClass
- the class the instances of which will be createdmethodClass
- the class from which the method is takenmethodName
- the name of the factory method within the objectClass
argumentCount
- the number of arguments that the method should have
java.lang.IllegalArgumentException
- if the there is no method for the given name and number of arguments or
if such method is not static or does not return the given objectClassMethod Detail |
---|
public T instantiate(java.lang.Object... arguments) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
creating
this
FactoryMethodInstantiator
class.
instantiate
in interface Instantiator<T>
arguments
- the arguments for the encapsulated factory method
java.lang.IllegalArgumentException
- if the arguments are not compatible with the method prototype
java.lang.reflect.InvocationTargetException
- if there was an exception thrown when the method was invokedpublic java.lang.Class<?>[] getInstantiatorPrototype()
Instantiator
Instantiator.instantiate(java.lang.Object[])
method.
getInstantiatorPrototype
in interface Instantiator<T>
public java.lang.Class<? extends T> getInstantiatorClass()
Instantiator
getInstantiatorClass
in interface Instantiator<T>
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |