|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.lang.ClassUtils
org.mule.util.ClassUtils
public class ClassUtils
Extend the Apache Commons ClassUtils to provide additional functionality.
This class is useful for loading resources and classes in a fault tolerant manner that works across different applications servers. The resource and classloading methods are SecurityManager friendly.
Field Summary | |
---|---|
static java.lang.Object[] |
NO_ARGS
|
static java.lang.Class<?>[] |
NO_ARGS_TYPE
|
Fields inherited from class org.apache.commons.lang.ClassUtils |
---|
INNER_CLASS_SEPARATOR, INNER_CLASS_SEPARATOR_CHAR, PACKAGE_SEPARATOR, PACKAGE_SEPARATOR_CHAR |
Constructor Summary | |
---|---|
ClassUtils()
|
Method Summary | ||
---|---|---|
static void |
addLibrariesToClasspath(java.util.List urls)
|
|
static boolean |
compare(java.lang.Class[] c1,
java.lang.Class[] c2,
boolean matchOnObject)
|
|
static boolean |
equal(java.lang.Object a,
java.lang.Object b)
Simple helper for writing object equalities. |
|
static java.lang.String |
getClassName(java.lang.Class clazz)
|
|
static java.net.URL |
getClassPathRoot(java.lang.Class clazz)
|
|
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.Constructor |
getConstructor(java.lang.Class clazz,
java.lang.Class[] paramTypes,
boolean exactMatch)
Returns available constructor in the target class that as the parameters specified. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>[] parameterTypes)
Returns a matching method for the given name and parameters on the given class If the parameterTypes arguments is null it will return the first matching method on the class. |
|
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.util.Enumeration<java.net.URL> |
getResources(java.lang.String resourceName,
java.lang.Class<?> callingClass)
|
|
static java.util.List<java.lang.reflect.Method> |
getSatisfiableMethods(java.lang.Class<?> implementation,
java.lang.Class<?>[] parameterTypes,
boolean voidOk,
boolean matchOnObject,
java.util.Collection<java.lang.String> ignoredMethodNames,
WildcardFilter filter)
A helper method that will find all matching methods on a class with the given parameter type |
|
static java.util.List<java.lang.reflect.Method> |
getSatisfiableMethods(java.lang.Class<?> implementation,
java.lang.Class<?>[] parameterTypes,
boolean voidOk,
boolean matchOnObject,
java.util.Set<java.lang.String> ignoredMethodNames)
A helper method that will find all matching methods on a class with the given parameter type |
|
static java.util.List<java.lang.reflect.Method> |
getSatisfiableMethodsWithReturnType(java.lang.Class implementation,
java.lang.Class returnType,
boolean matchOnObject,
java.util.Set<java.lang.String> ignoredMethodNames)
Match all method son a class with a defined return type |
|
static java.lang.String |
getSimpleName(java.lang.Class clazz)
Provide a simple-to-understand class name (with access to only Java 1.4 API). |
|
static int |
hash(java.lang.Object[] state)
|
|
static java.lang.Class<?> |
initializeClass(java.lang.Class<?> clazz)
Ensure that the given class is properly initialized when the argument is passed in as .class literal. |
|
static
|
instanciateClass(java.lang.Class<? extends T> clazz,
java.lang.Object... constructorArgs)
|
|
static java.lang.Object |
instanciateClass(java.lang.String name,
java.lang.Object... constructorArgs)
|
|
static java.lang.Object |
instanciateClass(java.lang.String name,
java.lang.Object[] constructorArgs,
java.lang.Class<?> callingClass)
|
|
static java.lang.Object |
instanciateClass(java.lang.String name,
java.lang.Object[] constructorArgs,
java.lang.ClassLoader classLoader)
|
|
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
|
loadClass(java.lang.String className,
java.lang.Class<?> callingClass,
T type)
Load a class with a given name. |
|
static java.lang.Class |
loadClass(java.lang.String className,
java.lang.ClassLoader classLoader)
Load a class with a given name from the given classloader. |
|
static java.lang.Class[] |
wrappersToPrimitives(java.lang.Class[] wrappers)
|
|
static java.lang.Class |
wrapperToPrimitive(java.lang.Class wrapper)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Object[] NO_ARGS
public static final java.lang.Class<?>[] NO_ARGS_TYPE
Constructor Detail |
---|
public ClassUtils()
Method Detail |
---|
public static boolean isConcrete(java.lang.Class<?> clazz)
public static java.net.URL getResource(java.lang.String resourceName, java.lang.Class<?> callingClass)
Thread.currentThread().getContextClassLoader()
ClassUtils.class.getClassLoader()
callingClass.getClassLoader()
resourceName
- The name of the resource to loadcallingClass
- The Class object of the calling object
public static java.util.Enumeration<java.net.URL> getResources(java.lang.String resourceName, java.lang.Class<?> callingClass)
public static java.lang.Class loadClass(java.lang.String className, java.lang.Class<?> callingClass) throws java.lang.ClassNotFoundException
Thread.currentThread().getContextClassLoader()
Class.forName(java.lang.String)
ClassLoaderUtil.class.getClassLoader()
callingClass.getClassLoader()
className
- The name of the class to loadcallingClass
- The Class object of the calling object
java.lang.ClassNotFoundException
- If the class cannot be found anywhere.public static <T extends java.lang.Class> T loadClass(java.lang.String className, java.lang.Class<?> callingClass, T type) throws java.lang.ClassNotFoundException
Thread.currentThread().getContextClassLoader()
Class.forName(java.lang.String)
ClassLoaderUtil.class.getClassLoader()
callingClass.getClassLoader()
className
- The name of the class to loadcallingClass
- The Class object of the calling objecttype
- the class type to expect to load
java.lang.ClassNotFoundException
- If the class cannot be found anywhere.public static java.lang.Class loadClass(java.lang.String className, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
className
- the name of the class to loadclassLoader
- the loader to load it from
java.lang.ClassNotFoundException
- if the class is not available in the class loaderpublic static java.lang.Class<?> initializeClass(java.lang.Class<?> clazz)
clazz
- the Class to be initialized
public static <T> T instanciateClass(java.lang.Class<? extends T> 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
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
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
java.lang.ClassNotFoundException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object instanciateClass(java.lang.String name, java.lang.Object[] constructorArgs, java.lang.Class<?> callingClass) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object instanciateClass(java.lang.String name, java.lang.Object[] constructorArgs, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Class<?>[] getParameterTypes(java.lang.Object bean, java.lang.String methodName)
public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>[] parameterTypes)
clazz
- the class to find the method onname
- the method name to findparameterTypes
- an array of argument types or null
public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] paramTypes)
public static java.lang.reflect.Constructor getConstructor(java.lang.Class clazz, java.lang.Class[] paramTypes, boolean exactMatch)
clazz
- the class to searchparamTypes
- the param types to match againstexactMatch
- should exact types be used (i.e. equals rather than isAssignableFrom.)
public static java.util.List<java.lang.reflect.Method> getSatisfiableMethods(java.lang.Class<?> implementation, java.lang.Class<?>[] parameterTypes, boolean voidOk, boolean matchOnObject, java.util.Set<java.lang.String> ignoredMethodNames)
implementation
- the class to build methods onparameterTypes
- the argument param types to look forvoidOk
- whether void methods shouldbe included in the found listmatchOnObject
- determines whether parameters of Object type are matched
when they are of Object.class typeignoredMethodNames
- a Set of method names to ignore. Often 'equals' is
not a desired match. This argument can be null.
public static java.util.List<java.lang.reflect.Method> getSatisfiableMethods(java.lang.Class<?> implementation, java.lang.Class<?>[] parameterTypes, boolean voidOk, boolean matchOnObject, java.util.Collection<java.lang.String> ignoredMethodNames, WildcardFilter filter)
implementation
- the class to build methods onparameterTypes
- the argument param types to look forvoidOk
- whether void methods shouldbe included in the found listmatchOnObject
- determines whether parameters of Object type are matched
when they are of Object.class typeignoredMethodNames
- a Set of method names to ignore. Often 'equals' is
not a desired match. This argument can be null.filter
- Wildcard expression filter that allows methods to be matched using wildcards i.e. 'get*'
public static java.util.List<java.lang.reflect.Method> getSatisfiableMethodsWithReturnType(java.lang.Class implementation, java.lang.Class returnType, boolean matchOnObject, java.util.Set<java.lang.String> ignoredMethodNames)
implementation
- the class to searchreturnType
- the return type to matchmatchOnObject
- whether Object
methods should be matchedignoredMethodNames
- a set of method names to ignore
public static boolean isClassOnPath(java.lang.String className, java.lang.Class currentClass)
className
- The class name to look forcurrentClass
- the calling class
public static java.lang.Class<?>[] getClassTypes(java.lang.Object object)
object
- single object or array. If this parameter is null or a zero length
array then NO_ARGS_TYPE
is returned
public static java.lang.String getClassName(java.lang.Class clazz)
public static boolean compare(java.lang.Class[] c1, java.lang.Class[] c2, boolean matchOnObject)
public static java.lang.Class wrapperToPrimitive(java.lang.Class wrapper)
public static java.lang.Class[] wrappersToPrimitives(java.lang.Class[] wrappers)
public static java.lang.String getSimpleName(java.lang.Class clazz)
clazz
- The class whose name we will generate
public static boolean equal(java.lang.Object a, java.lang.Object b)
a
- object to compareb
- object to be compared to
public static int hash(java.lang.Object[] state)
public static void addLibrariesToClasspath(java.util.List urls) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.net.URL getClassPathRoot(java.lang.Class clazz)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |