voldemort.utils
Class ReflectUtils

java.lang.Object
  extended by voldemort.utils.ReflectUtils

public class ReflectUtils
extends java.lang.Object

Utilities for reflection


Constructor Summary
ReflectUtils()
           
 
Method Summary
static
<T> T
callConstructor(java.lang.Class<T> klass)
          Call the no-arg constructor for the given class
static
<T> T
callConstructor(java.lang.Class<T> c, java.lang.Class<?>[] argTypes, java.lang.Object[] args)
          Call the class constructor with the given arguments
static
<T> T
callConstructor(java.lang.Class<T> klass, java.lang.Object[] args)
          Call the constructor for the given class, inferring the correct types for the arguments.
static
<T> java.lang.Object
callMethod(java.lang.Object obj, java.lang.Class<T> c, java.lang.String name, java.lang.Class<?>[] classes, java.lang.Object[] args)
          Call the named method
static
<T> java.lang.reflect.Method
getMethod(java.lang.Class<T> c, java.lang.String name, java.lang.Class<?>... argTypes)
          Get the named method from the class
static java.lang.String getPropertyName(java.lang.String name)
          Get the property name of a method name.
static java.lang.Class<?> loadClass(java.lang.String className)
          Load the given class using the default constructor
static java.lang.Class<?> loadClass(java.lang.String className, java.lang.ClassLoader cl)
          Load the given class using a specific class loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectUtils

public ReflectUtils()
Method Detail

getPropertyName

public static java.lang.String getPropertyName(java.lang.String name)
Get the property name of a method name. For example the property name of setSomeValue would be someValue. Names not beginning with set or get are not changed.

Parameters:
name - The name to process
Returns:
The property name

loadClass

public static java.lang.Class<?> loadClass(java.lang.String className)
Load the given class using the default constructor

Parameters:
className - The name of the class
Returns:
The class object

loadClass

public static java.lang.Class<?> loadClass(java.lang.String className,
                                           java.lang.ClassLoader cl)
Load the given class using a specific class loader.

Parameters:
className - The name of the class
cl - The Class Loader to be used for finding the class.
Returns:
The class object

callConstructor

public static <T> T callConstructor(java.lang.Class<T> klass)
Call the no-arg constructor for the given class

Type Parameters:
T - The type of the thing to construct
Parameters:
klass - The class
Returns:
The constructed thing

callConstructor

public static <T> T callConstructor(java.lang.Class<T> klass,
                                    java.lang.Object[] args)
Call the constructor for the given class, inferring the correct types for the arguments. This could be confusing if there are multiple constructors with the same number of arguments and the values themselves don't disambiguate.

Parameters:
klass - The class to construct
args - The arguments
Returns:
The constructed value

callConstructor

public static <T> T callConstructor(java.lang.Class<T> c,
                                    java.lang.Class<?>[] argTypes,
                                    java.lang.Object[] args)
Call the class constructor with the given arguments

Parameters:
c - The class
args - The arguments
Returns:
The constructed object

callMethod

public static <T> java.lang.Object callMethod(java.lang.Object obj,
                                              java.lang.Class<T> c,
                                              java.lang.String name,
                                              java.lang.Class<?>[] classes,
                                              java.lang.Object[] args)
Call the named method

Parameters:
obj - The object to call the method on
c - The class of the object
name - The name of the method
args - The method arguments
Returns:
The result of the method

getMethod

public static <T> java.lang.reflect.Method getMethod(java.lang.Class<T> c,
                                                     java.lang.String name,
                                                     java.lang.Class<?>... argTypes)
Get the named method from the class

Parameters:
c - The class to get the method from
name - The method name
argTypes - The argument types
Returns:
The method


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu