org.mule.util
Class ClassHelper

java.lang.Object
  extended byorg.mule.util.ClassHelper

public class ClassHelper
extends java.lang.Object

This class is extremely useful for loading resources and classes in a fault tolerant manner that works across different applications servers. The loadClass methods and printClassloader methods were taken from the ClassLoaderUtils in WW2.

Version:
$Revision: 1.5 $
Author:
Ross Mason, $Author: rossmason $

Field Summary
static java.lang.Object[] NO_ARGS
           
 
Constructor Summary
ClassHelper()
           
 
Method Summary
static boolean compare(java.lang.Class[] c1, java.lang.Class[] c2)
           
static java.lang.Class[] getClassTypes(java.lang.Object object)
          Used for creating an array of class types for an array or single object
static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] paramTypes)
           
static java.lang.reflect.Method getMethod(java.lang.String name, java.lang.Class clazz)
           
static java.lang.Class[] getParameterTypes(java.lang.Object bean, java.lang.String methodName)
           
static java.net.URL getResource(java.lang.String resourceName, java.lang.Class callingClass)
          Load a given resource.
static java.io.InputStream getResourceAsStream(java.lang.String resourceName, java.lang.Class callingClass)
          This is a convenience method to load a resource as a stream.
static java.util.List getSatisfiableMethods(java.lang.Class implementation, java.lang.Class[] parameterTypes, boolean voidOk, boolean ignoreEquals)
          A helper method that will find all matching methods on a class with the given parameter type
static java.lang.Object instanciateClass(java.lang.Class clazz, java.lang.Object[] constructorArgs)
           
static java.lang.Object instanciateClass(java.lang.String name, java.lang.Object[] constructorArgs)
           
static boolean isClassOnPath(java.lang.String className, java.lang.Class currentClass)
          Can be used by serice endpoints to select which service to use based on what's loaded on the classpath
static boolean isConcrete(java.lang.Class clazz)
           
static java.lang.Class loadClass(java.lang.String className, java.lang.Class callingClass)
          Load a class with a given name.
static void printClassLoader()
          Prints the current classloader hierarchy - useful for debugging.
static void printClassLoader(java.lang.ClassLoader cl)
          Prints the classloader hierarchy from a given classloader - useful for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ARGS

public static final java.lang.Object[] NO_ARGS
Constructor Detail

ClassHelper

public ClassHelper()
Method Detail

isConcrete

public static boolean isConcrete(java.lang.Class clazz)

getResource

public static java.net.URL getResource(java.lang.String resourceName,
                                       java.lang.Class callingClass)
Load a given resource.

This method will try to load the resource using the following methods (in order):

Parameters:
resourceName - The name of the resource to load
callingClass - The Class object of the calling object

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resourceName,
                                                      java.lang.Class callingClass)
This is a convenience method to load a resource as a stream.

The algorithm used to find the resource is given in getResource()

Parameters:
resourceName - The name of the resource to load
callingClass - The Class object of the calling object

loadClass

public static java.lang.Class loadClass(java.lang.String className,
                                        java.lang.Class callingClass)
                                 throws java.lang.ClassNotFoundException
Load a class with a given name.

It will try to load the class in the following order:

Parameters:
className - The name of the class to load
callingClass - The Class object of the calling object
Throws:
java.lang.ClassNotFoundException - If the class cannot be found anywhere.

printClassLoader

public static void printClassLoader()
Prints the current classloader hierarchy - useful for debugging.


printClassLoader

public static void printClassLoader(java.lang.ClassLoader cl)
Prints the classloader hierarchy from a given classloader - useful for debugging.


instanciateClass

public static java.lang.Object instanciateClass(java.lang.Class clazz,
                                                java.lang.Object[] constructorArgs)
                                         throws java.lang.SecurityException,
                                                java.lang.NoSuchMethodException,
                                                java.lang.IllegalArgumentException,
                                                java.lang.InstantiationException,
                                                java.lang.IllegalAccessException,
                                                java.lang.reflect.InvocationTargetException
Throws:
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

instanciateClass

public static java.lang.Object instanciateClass(java.lang.String name,
                                                java.lang.Object[] constructorArgs)
                                         throws java.lang.ClassNotFoundException,
                                                java.lang.SecurityException,
                                                java.lang.NoSuchMethodException,
                                                java.lang.IllegalArgumentException,
                                                java.lang.InstantiationException,
                                                java.lang.IllegalAccessException,
                                                java.lang.reflect.InvocationTargetException
Throws:
java.lang.ClassNotFoundException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getParameterTypes

public static java.lang.Class[] getParameterTypes(java.lang.Object bean,
                                                  java.lang.String methodName)

getMethod

public static java.lang.reflect.Method getMethod(java.lang.String name,
                                                 java.lang.Class clazz)

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz,
                                                           java.lang.Class[] paramTypes)

getSatisfiableMethods

public static java.util.List getSatisfiableMethods(java.lang.Class implementation,
                                                   java.lang.Class[] parameterTypes,
                                                   boolean voidOk,
                                                   boolean ignoreEquals)
A helper method that will find all matching methods on a class with the given parameter type

Parameters:
implementation - the class to build methods on
parameterTypes - the argument param types to look for
voidOk - whether void methods shouldbe included in the found list
ignoreEquals - whether to ignore the equals method in the methods returned
Returns:
a list of methods on the class that match the criteria. If there are none, an empty list is returned

isClassOnPath

public static boolean isClassOnPath(java.lang.String className,
                                    java.lang.Class currentClass)
Can be used by serice endpoints to select which service to use based on what's loaded on the classpath

Parameters:
className - The class name to look for
currentClass - the calling class
Returns:
true if the class is on the path

getClassTypes

public static java.lang.Class[] getClassTypes(java.lang.Object object)
Used for creating an array of class types for an array or single object

Parameters:
object - single object or array
Returns:
an array of class types for the object

compare

public static boolean compare(java.lang.Class[] c1,
                              java.lang.Class[] c2)


Copyright © 2003-2005 SymphonySoft Limited. All Rights Reserved.