org.jboss.ejb3.common.lang
Class ClassHelper

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

public class ClassHelper
extends Object

Useful methods for classes.

Version:
$Revision: 80988 $
Author:
Carlo de Wolf

Constructor Summary
ClassHelper()
           
 
Method Summary
static
<T> T
cast(Class<T> targetClass, Object obj)
          Casts an object to the class or interface represented by the targetClass Class object.
static List<Method> getAllMethodsByName(Class<?> cls, String methodName)
          Find all methods with a specific name on a class and it's super classes regardless of parameter signature.
static List<Method> getAllMethodsByPrefix(Class<?> clazz, String methodNamePrefix)
          Find all methods starting with the specified prefix on the specified class
static Class<?> getClassFromTypeName(String type, 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 Method getPrivateMethod(Class<?> cls, String methodName, 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(Class<T> targetClass,
                         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:
ClassCastException - if the object is not null and is not assignable to the type T.

getAllMethodsByName

public static List<Method> getAllMethodsByName(Class<?> cls,
                                               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 List<Method> getAllMethodsByPrefix(Class<?> clazz,
                                                 String methodNamePrefix)
Find all methods starting with the specified prefix on the specified class

Parameters:
clazz -
methodNamePrefix -
Returns:

getPrivateMethod

public static Method getPrivateMethod(Class<?> cls,
                                      String methodName,
                                      Class<?>... paramTypes)
                               throws 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:
NoSuchMethodException - if no method can be found

getClassFromTypeName

public static final Class<?> getClassFromTypeName(String type,
                                                  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:


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