|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ge.research.utils.IntrospectionUtils
A utility class with many conveinence methods for handling common
introspection tasks. Most of the methods simply wrap those
utilities found in the java.lang.reflect package,
catching and suppressing any possible errors.
| Constructor Summary | |
IntrospectionUtils()
|
|
| Method Summary | |
static java.lang.Class[] |
getAllInheritedClasses(java.lang.Object o)
Calls the getAllInheritedClasses(java.lang.Object, java.lang.Class)
with arguments o and java.lang.Object.class.
|
static java.lang.Class[] |
getAllInheritedClasses(java.lang.Object o,
java.lang.Class stopBefore)
Returns an array of all the classes declared as a superclass or superinterface of the argument object, up to but not including the stopBefore class.
|
static java.lang.reflect.Field[] |
getAllMembers(java.lang.Object o)
Returns the array of all fields (public, protected, and private) declared in the class of the o argument,
and all of its superclasses. |
static java.lang.reflect.Field |
getMember(java.lang.Object o,
java.lang.String name)
Executes the Class.getField(java.lang.String) method, trapping and suppressing any errors. |
static java.lang.Class |
getMemberType(java.lang.Object o,
java.lang.String name)
Determines the Class type of the member field,
specified by name. |
static java.lang.Object |
getMemberValue(java.lang.Object o,
java.lang.reflect.Field member)
Executes the Field.get(java.lang.Object) method, trapping and suppressing any errors. |
static java.lang.Object |
getMemberValue(java.lang.Object o,
java.lang.String name)
Calls getMemberValue(java.lang.Object, java.lang.reflect.Field) method with arguments
o and the return value from the call to getMember(java.lang.Object, java.lang.String) method
with arguments o and name. |
static java.lang.reflect.Method |
getMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] paramTypes)
Executes the Class.getMethod(java.lang.String, java.lang.Class[]) method, trapping and suppressing any errors. |
static java.lang.reflect.Method |
getMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Object[] args)
Attempts to find a method named methodName on the given class
such that the given arguments can be passed to that method successfully. |
static java.lang.Object |
getNewInstance(java.lang.Class cls)
Calls the getNewInstance(java.lang.Class, java.lang.Object[]) method
with null as the second argument. |
static java.lang.Object |
getNewInstance(java.lang.Class cls,
java.lang.Object[] args)
The args array is used to determine which constructor of the class to use,
and passes the values of the array to that constructor to instatiate the class. |
static java.lang.Object |
getNewInstance(java.lang.String classname,
java.lang.Class classType)
Calls the getNewInstance(java.lang.String, java.lang.Class, java.lang.Object[]) method
with null as the third argument. |
static java.lang.Object |
getNewInstance(java.lang.String classname,
java.lang.Class classType,
java.lang.Object[] args)
Creates an instance of a class named classname.
|
static java.lang.Class |
getPrimitiveClass(java.lang.Number num)
Returns the primitive number class represented by this Number object. |
static java.lang.Object |
invokeMethod(java.lang.reflect.Method m,
java.lang.Object o,
java.lang.Object[] args)
Executes the Method.invoke(java.lang.Object, java.lang.Object[]) method, trapping and suppressing any errors. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public IntrospectionUtils()
| Method Detail |
public static java.lang.Class[] getAllInheritedClasses(java.lang.Object o)
getAllInheritedClasses(java.lang.Object, java.lang.Class)
with arguments o and java.lang.Object.class.
Returns an array of all the classes declared as a superclass or superinterface
of the argument object (up to but not including java.lang.Object).
The returned array also includes the class of the argument object.
o - the object to find all superclasses and superinterfaces for
o argument,
including the class type of the o argumentgetAllInheritedClasses(java.lang.Object, java.lang.Class)
public static java.lang.Class[] getAllInheritedClasses(java.lang.Object o,
java.lang.Class stopBefore)
stopBefore class.
The returned array also includes the class of the argument object.
o - the object to find all superclasses and superinterfaces forstopBefore - the highest level of inherited classes to return as part of the array. The introspection stops when reaching this class type
o argument,
including the class type of the o argumentpublic static java.lang.reflect.Field[] getAllMembers(java.lang.Object o)
o argument,
and all of its superclasses.
o - the object to introspect for all fields (public, protected, and private) declared in its class and all inherited classes
getAllInheritedClasses(java.lang.Object)
public static java.lang.reflect.Field getMember(java.lang.Object o,
java.lang.String name)
Class.getField(java.lang.String) method, trapping and suppressing any errors.
o - the object of which to find the fieldname - the name of the field to find
name of the class of the object o.
Returns null if an error occured looking for the field.
public static java.lang.Class getMemberType(java.lang.Object o,
java.lang.String name)
Class type of the member field,
specified by name.
o - the object of which to find the fieldname - the name of the field to find
name of the class of the object o.
Returns null if an error occured looking for the field.
public static java.lang.Object getMemberValue(java.lang.Object o,
java.lang.String name)
getMemberValue(java.lang.Object, java.lang.reflect.Field) method with arguments
o and the return value from the call to getMember(java.lang.Object, java.lang.String) method
with arguments o and name.
o - the object to get the field value fromname - the name of the field to get the value for
name in the object o
Returns null if an error occured getting the value for the field.getMember(java.lang.Object, java.lang.String),
getMemberValue(java.lang.Object, java.lang.reflect.Field)
public static java.lang.Object getMemberValue(java.lang.Object o,
java.lang.reflect.Field member)
Field.get(java.lang.Object) method, trapping and suppressing any errors.
o - the object to retrieve the field value frommember - the field to retrieve the value of
member in the object o
Returns null if an error occured getting the value for the field.
public static java.lang.reflect.Method getMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] paramTypes)
Class.getMethod(java.lang.String, java.lang.Class[]) method, trapping and suppressing any errors.
cls - the class to introspect and find the method ofmethodName - the name of the method to findparamTypes - the method signature types for the method
methodName with signature paramTypes of class cls.
Returns null if an error occured looking for the method.
public static java.lang.reflect.Method getMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Object[] args)
methodName on the given class
such that the given arguments can be passed to that method successfully.
cls - the class to introspect and find the method ofmethodName - the name of the method to findargs - the method arguments for the method
methodName with signature paramTypes of class cls.
Returns null if an error occured looking for the method.public static java.lang.Object getNewInstance(java.lang.Class cls)
getNewInstance(java.lang.Class, java.lang.Object[]) method
with null as the second argument.
cls - the class to create an instance object of
cls class.
Returns null if an error occured preventing the class from being instantiated.getNewInstance(java.lang.Class, java.lang.Object[])
public static java.lang.Object getNewInstance(java.lang.Class cls,
java.lang.Object[] args)
args array is used to determine which constructor of the class to use,
and passes the values of the array to that constructor to instatiate the class.
cls - the class to create an instance object ofargs - the constructor argument objects to use to instantiate the new class
cls class.
Returns null if an error occured preventing the class from being instantiated.Class.getConstructor(java.lang.Class[]),
Constructor.newInstance(java.lang.Object[])
public static java.lang.Object getNewInstance(java.lang.String classname,
java.lang.Class classType)
getNewInstance(java.lang.String, java.lang.Class, java.lang.Object[]) method
with null as the third argument.
classname - the name of the class to instantiateclassType - the class (superclass, interface, or superinterface) the argument classname class should be checked to be assignable from
Returns null if an error occured preventing the class from being instantiated.getNewInstance(java.lang.String, java.lang.Class, java.lang.Object[])
public static java.lang.Object getNewInstance(java.lang.String classname,
java.lang.Class classType,
java.lang.Object[] args)
classname.
The class is loaded, and then its type is checked to be a valid subtype of the classType argument.
Finally calls the getNewInstance(java.lang.Class, java.lang.Object[]) method.
classname - the name of the class to instantiateclassType - the class (superclass, interface, or superinterface) the argument classname class should be checked to be assignable fromargs - the constructor argument objects to use to instantiate the new class
classname class.
Returns null if an error occured preventing the class from being instantiated.Class.forName(java.lang.String),
Class.isAssignableFrom(java.lang.Class),
getNewInstance(java.lang.Class, java.lang.Object[])public static final java.lang.Class getPrimitiveClass(java.lang.Number num)
num - the Number to get the primitive type for
public static java.lang.Object invokeMethod(java.lang.reflect.Method m,
java.lang.Object o,
java.lang.Object[] args)
Method.invoke(java.lang.Object, java.lang.Object[]) method, trapping and suppressing any errors.
m - the method to invokeo - the object on which to invoke the methodargs - the object array of arguments for the method invoked
null if an error occured while trying to invoke the method.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||