org.apache.muse.util
Class ReflectUtils

java.lang.Object
  extended by org.apache.muse.util.ReflectUtils

public class ReflectUtils
extends Object

ReflectUtils is a collection of utilities that allows you to leverage Java reflection without all of the checked exceptions (they are converted to runtime exceptions or return values). This class was created to get around the fact that the classes in java.lang.reflect.* turn every event into an exception, which is often cumbersome or inaccurate.

Author:
Dan Jemiolo (danj)

Constructor Summary
ReflectUtils()
           
 
Method Summary
static boolean exists(String className)
           
static boolean exists(String className, ClassLoader classLoader)
           
static Class getArrayClassFromClass(Class theClass)
           
static Class getClass(String className)
          This method calls getClass(Class, ClassLoader) with this class' ClassLoader.
static Class getClass(String className, ClassLoader classLoader)
           
static Class getClassFromArrayClass(Class arrayClass)
           
static Method getFirstMethod(Class theClass, String name)
           
static String getPackageName(Class theClass)
           
static String getPackageName(String qualifiedName)
           
static String getShortName(Class type)
           
static String getShortName(String qualifiedName)
           
static Object newInstance(Class theClass)
          Invokes the Class.newInstance() method on the given Class.
static Object newInstance(String className)
          This is a convenience method that invokes newInstance(Class) with a Class object representing the given type.
static Object newInstance(String className, ClassLoader classLoader)
          This is a convenience method that invokes newInstance(Class) with a Class object loaded by the given ClassLoader
static void setHelper(ReflectUtilHelper helper)
          This is a setter for the helper object
 
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

exists

public static boolean exists(String className)
Parameters:
className - The qualified name of the class to search for.
Returns:
True if the class is in the JVM's classpath.

exists

public static boolean exists(String className,
                             ClassLoader classLoader)
Parameters:
className - The qualified name of the class to search for.
classLoader - The class loader to use in the class lookup.
Returns:
True if the class is in the JVM's classpath.

getArrayClassFromClass

public static Class getArrayClassFromClass(Class theClass)
Parameters:
theClass - A "normal", non-array type.
Returns:
The array version of the given type. For example, if you pass String.class, you get String[].class. If you pass int.class, you get int[].class. If the given class is already an array type, it is returned.
See Also:
getClassFromArrayClass(Class)

getClass

public static Class getClass(String className)
This method calls getClass(Class, ClassLoader) with this class' ClassLoader.

Parameters:
className - The name of the class to load.
Returns:
The Class representing the given class name. A RuntimeException is thrown if the class is not found.
See Also:
exists(String)

getClass

public static Class getClass(String className,
                             ClassLoader classLoader)
Parameters:
className - The name of the class to load.
classLoader - The class loader to use for class lookup.
Returns:
The Class representing the given class name. A RuntimeException is thrown if the class is not found.
See Also:
exists(String)

getClassFromArrayClass

public static Class getClassFromArrayClass(Class arrayClass)
Parameters:
arrayClass - The array version of a given type (YourType[].class)
Returns:
The non-array version of the given type. For example, if you pass String[].class, you get String.class. If you pass int[].class, you get int.class.
See Also:
getArrayClassFromClass(Class)

getFirstMethod

public static Method getFirstMethod(Class theClass,
                                    String name)

getPackageName

public static String getPackageName(Class theClass)
Parameters:
theClass -
Returns:
The full name of the Java package that contains the given class, or null if the class is not in a package.

getPackageName

public static String getPackageName(String qualifiedName)
Parameters:
qualifiedName -
Returns:
The full name of the Java package that contains the given class, or null if the class is not in a package.

getShortName

public static String getShortName(Class type)
Parameters:
type -
Returns:
The unqualified (local) name of the class/interface. If the type is an array, the [] characters will be appended.

getShortName

public static String getShortName(String qualifiedName)
Parameters:
qualifiedName -
Returns:
The unqualified (local) name.

newInstance

public static Object newInstance(Class theClass)
Invokes the Class.newInstance() method on the given Class.

Parameters:
theClass - The type to instantiate.
Returns:
An object of the given type, created with the default constructor. A RuntimeException is thrown if the object could not be created.

newInstance

public static Object newInstance(String className)
This is a convenience method that invokes newInstance(Class) with a Class object representing the given type.

See Also:
getClass(String, ClassLoader), newInstance(Class)

newInstance

public static Object newInstance(String className,
                                 ClassLoader classLoader)
This is a convenience method that invokes newInstance(Class) with a Class object loaded by the given ClassLoader

See Also:
getClass(String, ClassLoader), newInstance(Class)

setHelper

public static void setHelper(ReflectUtilHelper helper)
This is a setter for the helper object



Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.