|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.dna.common.util.Reflection
@Immutable public class Reflection
Utility class for working reflectively with objects.
Constructor Summary | |
---|---|
Reflection(Class<?> targetClass)
Construct a Reflection instance that cache's some information about the target class. |
Method Summary | |
---|---|
static Class<?>[] |
buildArgumentClasses(Object... arguments)
Build the list of classes that correspond to the list of argument objects. |
static List<Class<?>> |
buildArgumentClassList(Object... arguments)
Build the list of classes that correspond to the list of argument objects. |
static List<Class<?>> |
convertArgumentClassesToPrimitives(Class<?>... arguments)
Convert any argument classes to primitives. |
Method |
findBestMethodOnTarget(String methodName,
Object... arguments)
Find the best method on the target class that matches the signature specified with the specified name and the list of arguments. |
Method |
findBestMethodWithSignature(String methodName,
Class<?>... argumentsClasses)
Find the best method on the target class that matches the signature specified with the specified name and the list of argument classes. |
Method |
findFirstMethod(Pattern methodNamePattern)
Find the method on the target class that matches the supplied method name. |
Method |
findFirstMethod(String methodName,
boolean caseSensitive)
Find the method on the target class that matches the supplied method name. |
Method[] |
findGetterMethods()
Find the getter methods on the target class that begin with "get" or "is", that have no parameters, and that return something other than void. |
String[] |
findGetterPropertyNames()
Find the property names with getter methods on the target class. |
Method[] |
findMethods(Pattern methodNamePattern)
Find the methods on the target class that matches the supplied method name. |
Method[] |
findMethods(String methodName,
boolean caseSensitive)
Find the method on the target class that matches the supplied method name. |
static String |
getClassName(Class<?> clazz)
Returns the name of the class. |
Class<?> |
getTargetClass()
Return the class that is the target for the reflection methods. |
Object |
invokeBestMethodOnTarget(String[] methodNames,
Object target,
Object... arguments)
Find and execute the best method on the target class that matches the signature specified with one of the specified names and the list of arguments. |
Object |
invokeGetterMethodOnTarget(String javaPropertyName,
Object target)
Find and execute the getter method on the target class for the supplied property name. |
Object |
invokeSetterMethodOnTarget(String javaPropertyName,
Object target,
Object argument)
Find and execute the best setter method on the target class for the supplied property name and the supplied list of arguments. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Reflection(Class<?> targetClass)
targetClass
- the target class
IllegalArgumentException
- if the target class is nullMethod Detail |
---|
public static Class<?>[] buildArgumentClasses(Object... arguments)
arguments
- the list of argument objects.
public static List<Class<?>> buildArgumentClassList(Object... arguments)
arguments
- the list of argument objects.
public static List<Class<?>> convertArgumentClassesToPrimitives(Class<?>... arguments)
arguments
- the list of argument classes.
public static String getClassName(Class<?> clazz)
clazz
- the class for which the class name is to be returned.
public Class<?> getTargetClass()
public Method[] findMethods(String methodName, boolean caseSensitive)
methodName
- the name of the method that is to be found.caseSensitive
- true if the method name supplied should match case-sensitively, or false if case does not matter
public Method[] findMethods(Pattern methodNamePattern)
methodNamePattern
- the regular expression pattern for the name of the method that is to be found.
public Method[] findGetterMethods()
Object.getClass()
method.
public String[] findGetterPropertyNames()
findGetterMethods()
.
public Method findFirstMethod(String methodName, boolean caseSensitive)
methodName
- the name of the method that is to be found.caseSensitive
- true if the method name supplied should match case-sensitively, or false if case does not matter
public Method findFirstMethod(Pattern methodNamePattern)
methodNamePattern
- the regular expression pattern for the name of the method that is to be found.
public Object invokeBestMethodOnTarget(String[] methodNames, Object target, Object... arguments) throws NoSuchMethodException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
This method is unable to find methods with signatures that include both primitive arguments and arguments that are
instances of Number
or its subclasses.
methodNames
- the names of the methods that are to be invoked, in the order they are to be triedtarget
- the object on which the method is to be invokedarguments
- the array of Object instances that correspond to the arguments passed to the method.
NoSuchMethodException
- if a matching method is not found.
SecurityException
- if access to the information is denied.
InvocationTargetException
IllegalAccessException
IllegalArgumentException
public Object invokeSetterMethodOnTarget(String javaPropertyName, Object target, Object argument) throws NoSuchMethodException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
This method is unable to find methods with signatures that include both primitive arguments and arguments that are
instances of Number
or its subclasses.
javaPropertyName
- the name of the property whose setter is to be invoked, in the order they are to be triedtarget
- the object on which the method is to be invokedargument
- the new value for the property
NoSuchMethodException
- if a matching method is not found.
SecurityException
- if access to the information is denied.
InvocationTargetException
IllegalAccessException
IllegalArgumentException
public Object invokeGetterMethodOnTarget(String javaPropertyName, Object target) throws NoSuchMethodException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
javaPropertyName
- the name of the property whose getter is to be invoked, in the order they are to be triedtarget
- the object on which the method is to be invoked
NoSuchMethodException
- if a matching method is not found.
SecurityException
- if access to the information is denied.
InvocationTargetException
IllegalAccessException
IllegalArgumentException
public Method findBestMethodOnTarget(String methodName, Object... arguments) throws NoSuchMethodException, SecurityException
This method is unable to find methods with signatures that include both primitive arguments and arguments that are
instances of Number
or its subclasses.
methodName
- the name of the method that is to be invoked.arguments
- the array of Object instances that correspond to the arguments passed to the method.
NoSuchMethodException
- if a matching method is not found.
SecurityException
- if access to the information is denied.public Method findBestMethodWithSignature(String methodName, Class<?>... argumentsClasses) throws NoSuchMethodException, SecurityException
methodName
- the name of the method that is to be invoked.argumentsClasses
- the list of Class instances that correspond to the classes for each argument passed to the method.
NoSuchMethodException
- if a matching method is not found.
SecurityException
- if access to the information is denied.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |