|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.utility.reflection.FieldInstantiator<T>
T
- the class the instances of which will be created by this FieldInstantiatorpublic class FieldInstantiator<T>
This class allows to create instances of a given class. A field of the given type is encapsulated and used in subsequent calls. Note that FieldInstantiator instantiates by getting a value of a given filed on the instance provided in arguments (can be omitted if the field is static).
This class provides a convenient way of repeatable creation of instances of a given class without the need of repetable field retrieval and checking all the exceptions.
Constructor Summary | |
---|---|
FieldInstantiator(java.lang.Class<? extends T> checkClass,
java.lang.Class<?> fieldClass,
java.lang.String fieldName)
Creates a new instance of FieldInstantiator for creating instances of objectClass . |
|
FieldInstantiator(java.lang.Class<? extends T> objectClass,
java.lang.reflect.Field field)
Creates a new instance of FieldInstantiator for creating instances of objectClass via the given field. |
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 field. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FieldInstantiator(java.lang.Class<? extends T> objectClass, java.lang.reflect.Field field) throws java.lang.IllegalArgumentException
objectClass
via the given field.
objectClass
- the class the instances of which will be createdfield
- the field used to create instances
java.lang.IllegalArgumentException
- if the provided field has not the given objectClass typepublic FieldInstantiator(java.lang.Class<? extends T> checkClass, java.lang.Class<?> fieldClass, java.lang.String fieldName) throws java.lang.IllegalArgumentException
objectClass
.
checkClass
- the class the instances of which will be createdfieldClass
- the class in which the field is looked upfieldName
- the name of the field within the objectClass
java.lang.IllegalArgumentException
- if the there is no field for the given name or
if such field has not the given objectClass typeMethod Detail |
---|
public T instantiate(java.lang.Object... arguments) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
instantiate
in interface Instantiator<T>
arguments
- the instance from which to get the field (or null if the field is static)
java.lang.IllegalArgumentException
- if the arguments are not compatible
java.lang.reflect.InvocationTargetException
- if there was an exception thrown when the instance was createdpublic 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 |