public class ClassUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Method |
findDeclaredMethod(Class clazz,
String name,
Class[] params) |
static Method |
findMethod(Class clazz,
String name,
Class[] params) |
static Class |
getClass(String name)
Load a class with a given name.
|
static Object |
getFieldValue(Class clazz,
String fieldname) |
static Object |
getFieldValue(String fieldPath) |
static Object |
getInstance(String classname) |
static Iterator |
getIterator(Object obj)
Retrieves an Iterator from or creates and Iterator for the specified object.
|
static URL |
getResource(String name,
Object caller)
Load a given resource.
|
static InputStream |
getResourceAsStream(String name,
Object caller)
This is a convenience method to load a resource as a stream.
|
static List<URL> |
getResources(String name,
Object caller)
Load all resources with the specified name.
|
public static Class getClass(String name) throws ClassNotFoundException
Thread
.currentThread().getContextClassLoader()
Class.forName(java.lang.String)
ClassUtils
.class.getClassLoader()
name
- Fully qualified class name to be loadedClassNotFoundException
- if the class cannot be foundpublic static Object getInstance(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException
public static List<URL> getResources(String name, Object caller)
ClassUtils
.class.getClassLoader().getResources(name)ClassUtils
.class.getResource(name)getCallerLoader(Object caller)
.getResources(name)name
- The name of the resources to loadcaller
- The instance or Class
calling this methodpublic static URL getResource(String name, Object caller)
ClassUtils
.class.getClassLoader().getResource(name)ClassUtils
.class.getResource(name)name
- The name of the resource to loadcaller
- The instance or Class
calling this methodpublic static InputStream getResourceAsStream(String name, Object caller)
name
- The name of the resource to loadcaller
- The instance or Class
calling this methodpublic static Method findMethod(Class clazz, String name, Class[] params) throws SecurityException
SecurityException
public static Method findDeclaredMethod(Class clazz, String name, Class[] params) throws SecurityException
SecurityException
public static Object getFieldValue(String fieldPath) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalAccessException
public static Object getFieldValue(Class clazz, String fieldname) throws NoSuchFieldException, SecurityException, IllegalAccessException
public static Iterator getIterator(Object obj) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
obj
- the target objNoSuchMethodException
- if no iterator() methodIllegalAccessException
- if iterator() method not callableInvocationTargetException
- if iterator() method throwedCopyright © 2002–2018 The Apache Software Foundation. All rights reserved.