|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.ClassUtils
public abstract class ClassUtils
Miscellaneous class utility methods. Mainly for internal use within the framework; consider Jakarta's Commons Lang for a more comprehensive suite of utilities.
Field Summary | |
---|---|
static String |
ARRAY_SUFFIX
Suffix for array class names |
Constructor Summary | |
---|---|
ClassUtils()
|
Method Summary | |
---|---|
static String |
addResourcePathToPackagePath(Class clazz,
String resourceName)
Return a path suitable for use with ClassLoader.getResource
(also suitable for use with Class.getResource by prepending a
slash ('/') to the return value. |
static String |
classPackageAsResourcePath(Class clazz)
Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). |
static Class |
forName(String name)
Replacement for Class.forName() that also returns Class instances
for primitives (like "int") and array class names (like "String[]"). |
static Class |
forName(String name,
ClassLoader classLoader)
Replacement for Class.forName() that also returns Class instances
for primitives (like "int") and array class names (like "String[]"). |
static Class[] |
getAllInterfaces(Object object)
Return all interfaces that the given object implements as array, including ones implemented by superclasses. |
static Set |
getAllInterfacesAsSet(Object object)
Return all interfaces that the given object implements as List, including ones implemented by superclasses. |
static Class[] |
getAllInterfacesForClass(Class clazz)
Return all interfaces that the given class implements as array, including ones implemented by superclasses. |
static Set |
getAllInterfacesForClassAsSet(Class clazz)
Return all interfaces that the given class implements as Set, including ones implemented by superclasses. |
static ClassLoader |
getDefaultClassLoader()
Return a default ClassLoader to use (never null ). |
static int |
getMethodCountForName(Class clazz,
String methodName)
Return the number of methods with a given name (with any argument types), for the given class and/or its superclasses. |
static String |
getQualifiedMethodName(Method method)
Return the qualified name of the given method, consisting of fully qualified interface/class name + "." + method name. |
static String |
getQualifiedName(Class clazz)
Return the qualified name of the given class: usually simply the class name, but component type class name + "[]" for arrays. |
static String |
getShortName(Class clazz)
Get the class name without the qualified package name. |
static String |
getShortName(String className)
Get the class name without the qualified package name. |
static String |
getShortNameAsProperty(Class clazz)
Return the short string name of a Java class in decapitalized JavaBeans property format. |
static Method |
getStaticMethod(Class clazz,
String methodName,
Class[] args)
Return a static method of a class. |
static boolean |
hasAtLeastOneMethodWithName(Class clazz,
String methodName)
Does the given class and/or its superclasses at least have one or more methods (with any argument types)? |
static boolean |
hasMethod(Class clazz,
String methodName,
Class[] paramTypes)
Determine whether the given class has a method with the given signature. |
static Class |
resolvePrimitiveClassName(String name)
Resolve the given class name as primitive class, if appropriate. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ARRAY_SUFFIX
Constructor Detail |
---|
public ClassUtils()
Method Detail |
---|
public static ClassLoader getDefaultClassLoader()
null
).
Returns the thread context ClassLoader, if available.
The ClassLoader that loaded the ClassUtils class will be used as fallback.
Call this method if you intend to use the thread context ClassLoader
in a scenario where you absolutely need a non-null ClassLoader reference:
for example, for class path resource loading (but not necessarily for
Class.forName
, which accepts a null
ClassLoader
reference as well).
Thread.getContextClassLoader()
public static Class forName(String name) throws ClassNotFoundException
Class.forName()
that also returns Class instances
for primitives (like "int") and array class names (like "String[]").
Always uses the default class loader: that is, preferably the thread context class loader, or the ClassLoader that loaded the ClassUtils class as fallback.
name
- the name of the Class
ClassNotFoundException
Class.forName(String, boolean, ClassLoader)
,
getDefaultClassLoader()
public static Class forName(String name, ClassLoader classLoader) throws ClassNotFoundException
Class.forName()
that also returns Class instances
for primitives (like "int") and array class names (like "String[]").
name
- the name of the ClassclassLoader
- the class loader to use
ClassNotFoundException
Class.forName(String, boolean, ClassLoader)
public static Class resolvePrimitiveClassName(String name)
name
- the name of the potentially primitive class
null
if the name does not denote
a primitive classpublic static String getShortName(String className)
className
- the className to get the short name for
IllegalArgumentException
- if the className is emptypublic static String getShortName(Class clazz)
clazz
- the class to get the short name for
public static String getShortNameAsProperty(Class clazz)
clazz
- the class
Introspector.decapitalize(String)
public static String getQualifiedName(Class clazz)
clazz
- the class
public static String getQualifiedMethodName(Method method)
method
- the method
public static boolean hasMethod(Class clazz, String methodName, Class[] paramTypes)
NoSuchMethodException
to "false".
clazz
- the clazz to analyzemethodName
- the name of the methodparamTypes
- the parameter types of the methodpublic static int getMethodCountForName(Class clazz, String methodName)
clazz
- the clazz to checkmethodName
- the name of the method
public static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName)
clazz
- the clazz to checkmethodName
- the name of the method
public static Method getStaticMethod(Class clazz, String methodName, Class[] args)
methodName
- the static method nameclazz
- the class which defines the methodargs
- the parameter types to the method
null
if no static method was found
IllegalArgumentException
- if the method name is blank or the clazz is nullpublic static String addResourcePathToPackagePath(Class clazz, String resourceName)
ClassLoader.getResource
(also suitable for use with Class.getResource
by prepending a
slash ('/') to the return value. Built by taking the package of the specified
class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
if necesssary, and concatenating the specified resource name to this.
ClassPathResource
is usually
even more convenient.
clazz
- the Class whose package will be used as the baseresourceName
- the resource name to append. A leading slash is optional.
ClassLoader.getResource(java.lang.String)
,
Class.getResource(java.lang.String)
public static String classPackageAsResourcePath(Class clazz)
clazz
- the input class. A null value or the default (empty) package
will result in an empty string ("") being returned.
ClassLoader.getResource(java.lang.String)
,
Class.getResource(java.lang.String)
public static Class[] getAllInterfaces(Object object)
object
- the object to analyse for interfaces
public static Class[] getAllInterfacesForClass(Class clazz)
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyse for interfaces
public static Set getAllInterfacesAsSet(Object object)
object
- the object to analyse for interfaces
public static Set getAllInterfacesForClassAsSet(Class clazz)
If the class itself is an interface, it gets returned as sole interface.
clazz
- the class to analyse for interfaces
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |