org.jboss.ejb3.common.lang
Class ClassHelper

java.lang.Object
  extended by org.jboss.ejb3.common.lang.ClassHelper

public class ClassHelper
extends java.lang.Object

Useful methods for classes.


Constructor Summary
ClassHelper()
           
 
Method Summary
static
<T> T
cast(java.lang.Class<T> targetClass, java.lang.Object obj)
          Casts an object to the class or interface represented by the targetClass Class object.
static java.util.List<java.lang.reflect.Method> getAllMethodsByName(java.lang.Class<?> cls, java.lang.String methodName)
          Find all methods with a specific name on a class and it's super classes regardless of parameter signature.
static java.util.List<java.lang.reflect.Method> getAllMethodsByPrefix(java.lang.Class<?> clazz, java.lang.String methodNamePrefix)
          Find all methods starting with the specified prefix on the specified class
static java.lang.Class<?> getClassFromTypeName(java.lang.String type, java.lang.ClassLoader cl)
          Obtains a Class corresponding to the specified type using the specified ClassLoader, throwing a descriptive RuntimeException in the case the Class could not be found
static java.lang.reflect.Method getPrivateMethod(java.lang.Class<?> cls, java.lang.String methodName, java.lang.Class<?>... paramTypes)
          Returns the Method with the given attributes of either this class or one of it's super classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassHelper

public ClassHelper()
Method Detail

cast

public static <T> T cast(java.lang.Class<T> targetClass,
                         java.lang.Object obj)
Casts an object to the class or interface represented by the targetClass Class object. The ClassCastException thrown is more descriptive than the original.

Parameters:
obj - the object to be cast
Returns:
the object after casting, or null if obj is null
Throws:
java.lang.ClassCastException - if the object is not null and is not assignable to the type T.

getAllMethodsByName

public static java.util.List<java.lang.reflect.Method> getAllMethodsByName(java.lang.Class<?> cls,
                                                                           java.lang.String methodName)
Find all methods with a specific name on a class and it's super classes regardless of parameter signature.

Parameters:
cls - the class to scan
methodName - the name of the methods to find
Returns:
a list of methods found, or empty

getAllMethodsByPrefix

public static java.util.List<java.lang.reflect.Method> getAllMethodsByPrefix(java.lang.Class<?> clazz,
                                                                             java.lang.String methodNamePrefix)
Find all methods starting with the specified prefix on the specified class

Parameters:
clazz -
methodNamePrefix -
Returns:

getPrivateMethod

public static java.lang.reflect.Method getPrivateMethod(java.lang.Class<?> cls,
                                                        java.lang.String methodName,
                                                        java.lang.Class<?>... paramTypes)
                                                 throws java.lang.NoSuchMethodException
Returns the Method with the given attributes of either this class or one of it's super classes. TODO: return type specifics are not considered FIXME: rename method (it must return all modifiers)

Parameters:
cls - class to scan
methodName - the name of the method
paramTypes - the parameter types
Returns:
the Method matching the method name and parameters
Throws:
java.lang.NoSuchMethodException - if no method can be found

getClassFromTypeName

public static final java.lang.Class<?> getClassFromTypeName(java.lang.String type,
                                                            java.lang.ClassLoader cl)
Obtains a Class corresponding to the specified type using the specified ClassLoader, throwing a descriptive RuntimeException in the case the Class could not be found

Parameters:
type -
cl -
Returns: