org.jboss.reflect.plugins.introspection
Class ReflectionUtils

java.lang.Object
  extended by org.jboss.reflect.plugins.introspection.ReflectionUtils

public class ReflectionUtils
extends Object

ReflectionUtils.

Version:
$Revision: 77014 $
Author:
Adrian Brock, Ales Justin

Constructor Summary
ReflectionUtils()
           
 
Method Summary
protected static Object arrayInfo(Object... objects)
          Get array info.
static Constructor<?> findConstructor(Class<?> clazz, Class<?>... parameterTypes)
          Find the constructor by parameters.
static Constructor<?> findExactConstructor(Class<?> clazz, Class<?>... parameterTypes)
          Find the constructor by parameters.
static Field findExactField(Class<?> clazz, String name)
          Find the field by name.
static Method findExactMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
          Find the method by name and parameters.
static Field findField(Class<?> clazz, String name)
          Find the field by name.
static Method findMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
          Find the method by name and parameters.
static Object getField(Field field, Object target)
          Get a field
static Throwable handleErrors(String context, Field field, Object target, Object value, Throwable t)
          Handle errors
static Throwable handleErrors(String context, Object target, Class<?>[] parameters, Object[] arguments, Throwable t)
          Handle errors
static Object invoke(Method method, Object target, Object[] arguments)
          Invoke on a method
static Object newInstance(Class<?> clazz)
          Create a new instance
static Object newInstance(Constructor<?> constructor, Object[] arguments)
          Create a new instance
static Object newInstance(String className)
          Create a new instance
static Object newInstance(String className, ClassLoader cl)
          Create a new instance
static Object setField(Field field, Object target, Object value)
          Set a field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtils

public ReflectionUtils()
Method Detail

invoke

public static Object invoke(Method method,
                            Object target,
                            Object[] arguments)
                     throws Throwable
Invoke on a method

Parameters:
method - the method
target - the target
arguments - the arguments
Returns:
the result of the invocation
Throws:
Throwable - for any error

newInstance

public static Object newInstance(Class<?> clazz)
                          throws Throwable
Create a new instance

Parameters:
clazz - the class
Returns:
the constructed object
Throws:
Throwable - for any error

newInstance

public static Object newInstance(String className,
                                 ClassLoader cl)
                          throws Throwable
Create a new instance

Parameters:
className - the class name
cl - the classloader
Returns:
the constructed object
Throws:
Throwable - for any error

newInstance

public static Object newInstance(String className)
                          throws Throwable
Create a new instance

Parameters:
className - the class name
Returns:
the constructed object
Throws:
Throwable - for any error

newInstance

public static Object newInstance(Constructor<?> constructor,
                                 Object[] arguments)
                          throws Throwable
Create a new instance

Parameters:
constructor - the constructor
arguments - the arguments
Returns:
the constructed object
Throws:
Throwable - for any error

getField

public static Object getField(Field field,
                              Object target)
                       throws Throwable
Get a field

Parameters:
field - the field
target - the target
Returns:
null
Throws:
Throwable - for any error

setField

public static Object setField(Field field,
                              Object target,
                              Object value)
                       throws Throwable
Set a field

Parameters:
field - the field
target - the target
value - the value
Returns:
null
Throws:
Throwable - for any error

arrayInfo

protected static Object arrayInfo(Object... objects)
Get array info. Handle null parameter.

Parameters:
objects - the array of objects
Returns:
info

findMethod

public static Method findMethod(Class<?> clazz,
                                String name,
                                Class<?>... parameterTypes)
Find the method by name and parameters.

Parameters:
clazz - the class to look for method
name - the name
parameterTypes - the types
Returns:
method or null if not found

findExactMethod

public static Method findExactMethod(Class<?> clazz,
                                     String name,
                                     Class<?>... parameterTypes)
                              throws NoSuchMethodException
Find the method by name and parameters.

Parameters:
clazz - the class to look for method
name - the name
parameterTypes - the types
Returns:
method or throw exception if not found
Throws:
NoSuchMethodException - for no such method

findField

public static Field findField(Class<?> clazz,
                              String name)
Find the field by name.

Parameters:
clazz - the class to look for field
name - the name
Returns:
field or null if not found

findExactField

public static Field findExactField(Class<?> clazz,
                                   String name)
                            throws NoSuchFieldException
Find the field by name.

Parameters:
clazz - the class to look for field
name - the name
Returns:
field or throw exception if not found
Throws:
NoSuchFieldException - for no such field

findConstructor

public static Constructor<?> findConstructor(Class<?> clazz,
                                             Class<?>... parameterTypes)
Find the constructor by parameters.

Parameters:
clazz - the class to look for constructor
parameterTypes - the types
Returns:
constructor or null if not found

findExactConstructor

public static Constructor<?> findExactConstructor(Class<?> clazz,
                                                  Class<?>... parameterTypes)
                                           throws NoSuchMethodException
Find the constructor by parameters.

Parameters:
clazz - the class to look for constructor
parameterTypes - the types
Returns:
method or throw exception if not found
Throws:
NoSuchMethodException - for no such method

handleErrors

public static Throwable handleErrors(String context,
                                     Object target,
                                     Class<?>[] parameters,
                                     Object[] arguments,
                                     Throwable t)
                              throws Throwable
Handle errors

Parameters:
context - the context
target - the target
parameters - the parameters
arguments - the arguments
t - the error
Returns:
never
Throws:
Throwable - always

handleErrors

public static Throwable handleErrors(String context,
                                     Field field,
                                     Object target,
                                     Object value,
                                     Throwable t)
                              throws Throwable
Handle errors

Parameters:
context - the context
field - the field
target - the target
value - the value
t - the error
Returns:
never
Throws:
Throwable - always


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.