public abstract class SpringClassUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ARRAY_SUFFIX
Suffix for array class names
|
Constructor and Description |
---|
SpringClassUtils() |
Modifier and Type | Method and Description |
---|---|
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<Class> |
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<Class> |
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 |
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)? Includes non-public methods.
|
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.
|
public static final String ARRAY_SUFFIX
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 thread context class loader.
name
- the name of the ClassClassNotFoundException
Class.forName(String, boolean, ClassLoader)
,
Thread.getContextClassLoader()
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 useClassNotFoundException
Class.forName(String, boolean, ClassLoader)
,
Thread.getContextClassLoader()
public static Class resolvePrimitiveClassName(String name)
name
- the name of the potentially primitive classnull
if the name does not denote
a primitive classpublic static String getShortNameAsProperty(Class clazz)
clazz
- the classIntrospector.decapitalize(String)
public static String getShortName(Class clazz)
clazz
- the class to get the short name forIllegalArgumentException
- if the class is nullpublic static String getShortName(String className)
className
- the className to get the short name forIllegalArgumentException
- if the className is emptypublic static String getQualifiedMethodName(Method method)
method
- the methodpublic 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 methodpublic static boolean hasAtLeastOneMethodWithName(Class clazz, String methodName)
clazz
- the clazz to checkmethodName
- the name of the methodpublic 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 methodnull
if no static method was foundIllegalArgumentException
- if the method name is blank or the clazz is nullpublic static String addResourcePathToPackagePath(Class clazz, String resourceName)
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 interfacespublic static Class[] getAllInterfacesForClass(Class clazz)
clazz
- the class to analyse for interfacespublic static Set<Class> getAllInterfacesAsSet(Object object)
object
- the object to analyse for interfacespublic static Set<Class> getAllInterfacesForClassAsSet(Class clazz)
clazz
- the class to analyse for interfacesCopyright © 2003–2016 The Apache Software Foundation. All rights reserved.