|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 Object[] |
NO_ARGS
|
static 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(List urls)
|
|
static boolean |
compare(Class[] c1,
Class[] c2,
boolean matchOnObject)
|
|
static boolean |
compare(Class[] c1,
Class[] c2,
boolean matchOnObject,
boolean acceptNulls)
Returns true if the types from array c2 are assignable to the types from c1 and the arrays are the same size. |
|
static boolean |
equal(Object a,
Object b)
Simple helper for writing object equalities. |
|
static String |
getClassName(Class clazz)
|
|
static URL |
getClassPathRoot(Class clazz)
|
|
static Class<?>[] |
getClassTypes(Object object)
Used for creating an array of class types for an array or single object |
|
static Constructor |
getConstructor(Class clazz,
Class[] paramTypes)
|
|
static Constructor |
getConstructor(Class clazz,
Class[] paramTypes,
boolean exactMatch)
Returns available constructor in the target class that as the parameters specified. |
|
static Method |
getMethod(Class<?> clazz,
String name,
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 Method |
getMethod(Class clazz,
String name,
Class[] parameterTypes,
boolean acceptNulls)
|
|
static Class<?>[] |
getParameterTypes(Object bean,
String methodName)
|
|
static URL |
getResource(String resourceName,
Class<?> callingClass)
Load a given resource. |
|
static Enumeration<URL> |
getResources(String resourceName,
Class<?> callingClass)
|
|
static List<Method> |
getSatisfiableMethods(Class<?> implementation,
Class<?>[] parameterTypes,
boolean voidOk,
boolean matchOnObject,
Collection<String> ignoredMethodNames,
WildcardFilter filter)
A helper method that will find all matching methods on a class with the given parameter type |
|
static List<Method> |
getSatisfiableMethods(Class<?> implementation,
Class<?>[] parameterTypes,
boolean voidOk,
boolean matchOnObject,
Set<String> ignoredMethodNames)
A helper method that will find all matching methods on a class with the given parameter type |
|
static List<Method> |
getSatisfiableMethodsWithReturnType(Class implementation,
Class returnType,
boolean matchOnObject,
Set<String> ignoredMethodNames)
Match all method son a class with a defined return type |
|
static String |
getSimpleName(Class clazz)
Provide a simple-to-understand class name (with access to only Java 1.4 API). |
|
static int |
hash(Object[] state)
|
|
static Class<?> |
initializeClass(Class<?> clazz)
Ensure that the given class is properly initialized when the argument is passed in as .class literal. |
|
static
|
instanciateClass(Class<? extends T> clazz,
Object... constructorArgs)
|
|
static Object |
instanciateClass(String name,
Object... constructorArgs)
|
|
static Object |
instanciateClass(String name,
Object[] constructorArgs,
Class<?> callingClass)
|
|
static Object |
instanciateClass(String name,
Object[] constructorArgs,
ClassLoader classLoader)
|
|
static boolean |
isClassOnPath(String className,
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(Class<?> clazz)
|
|
static Class |
loadClass(String className,
Class<?> callingClass)
Load a class with a given name. |
|
static
|
loadClass(String className,
Class<?> callingClass,
T type)
Load a class with a given name. |
|
static Class |
loadClass(String className,
ClassLoader classLoader)
Load a class with a given name from the given classloader. |
|
static Class[] |
wrappersToPrimitives(Class[] wrappers)
|
|
static Class |
wrapperToPrimitive(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 Object[] NO_ARGS
public static final Class<?>[] NO_ARGS_TYPE
Constructor Detail |
---|
public ClassUtils()
Method Detail |
---|
public static boolean isConcrete(Class<?> clazz)
public static URL getResource(String resourceName, 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 Enumeration<URL> getResources(String resourceName, Class<?> callingClass)
public static Class loadClass(String className, Class<?> callingClass) throws 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
ClassNotFoundException
- If the class cannot be found anywhere.public static <T extends Class> T loadClass(String className, Class<?> callingClass, T type) throws 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
ClassNotFoundException
- If the class cannot be found anywhere.public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException
className
- the name of the class to loadclassLoader
- the loader to load it from
ClassNotFoundException
- if the class is not available in the class loaderpublic static Class<?> initializeClass(Class<?> clazz)
clazz
- the Class to be initialized
public static <T> T instanciateClass(Class<? extends T> clazz, Object... constructorArgs) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
SecurityException
NoSuchMethodException
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException
public static Object instanciateClass(String name, Object... constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
ClassNotFoundException
SecurityException
NoSuchMethodException
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException
public static Object instanciateClass(String name, Object[] constructorArgs, Class<?> callingClass) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
ClassNotFoundException
SecurityException
NoSuchMethodException
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException
public static Object instanciateClass(String name, Object[] constructorArgs, ClassLoader classLoader) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
ClassNotFoundException
SecurityException
NoSuchMethodException
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException
public static Class<?>[] getParameterTypes(Object bean, String methodName)
public static Method getMethod(Class<?> clazz, String name, Class<?>[] parameterTypes)
clazz
- the class to find the method onname
- the method name to findparameterTypes
- an array of argument types or null
public static Method getMethod(Class clazz, String name, Class[] parameterTypes, boolean acceptNulls)
public static Constructor getConstructor(Class clazz, Class[] paramTypes)
public static Constructor getConstructor(Class clazz, 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 List<Method> getSatisfiableMethods(Class<?> implementation, Class<?>[] parameterTypes, boolean voidOk, boolean matchOnObject, Set<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 List<Method> getSatisfiableMethods(Class<?> implementation, Class<?>[] parameterTypes, boolean voidOk, boolean matchOnObject, Collection<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 List<Method> getSatisfiableMethodsWithReturnType(Class implementation, Class returnType, boolean matchOnObject, Set<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(String className, Class currentClass)
className
- The class name to look forcurrentClass
- the calling class
public static Class<?>[] getClassTypes(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 String getClassName(Class clazz)
public static boolean compare(Class[] c1, Class[] c2, boolean matchOnObject)
public static boolean compare(Class[] c1, Class[] c2, boolean matchOnObject, boolean acceptNulls)
c1
- parameter types arrayc2
- parameter types arraymatchOnObject
- return false if there is a parameter of type Object in c1acceptNulls
- allows null parameter types in c2
public static Class wrapperToPrimitive(Class wrapper)
public static Class[] wrappersToPrimitives(Class[] wrappers)
public static String getSimpleName(Class clazz)
clazz
- The class whose name we will generate
public static boolean equal(Object a, Object b)
a
- object to compareb
- object to be compared to
public static int hash(Object[] state)
public static void addLibrariesToClasspath(List urls) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
NoSuchMethodException
IllegalAccessException
InvocationTargetException
public static URL getClassPathRoot(Class clazz)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |