|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.compass.core.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 String |
convertClassNameToResourcePath(String className)
Convert a "." |
static String |
convertResourcePathToClassName(String resourcePath)
Convert a "/"-based resource path to a "." |
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 Constructor |
getDefaultConstructor(Class clazz)
Returns the default constructor for the class. |
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 String |
getShortNameForField(Field field)
|
static String |
getShortNameForMethod(Method method)
|
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 boolean |
isAbstractClass(Class clazz)
Returns true of the class is an abstract class. |
static boolean |
isPublic(Class clazz,
Member member)
Returns true if the member is public and the class
is public. |
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 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(java.lang.String)
,
Thread.getContextClassLoader()
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 getShortNameAsProperty(Class clazz)
clazz
- the class
Introspector.decapitalize(String)
public static String getShortNameForField(Field field)
public static String getShortNameForMethod(Method method)
public static String getShortName(Class clazz)
clazz
- the class to get the short name for
IllegalArgumentException
- if the class is nullpublic static String getShortName(String className)
className
- the className to get the short name for
IllegalArgumentException
- if the className is emptypublic 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)
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)
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)
clazz
- the class to analyse for interfaces
public static boolean isPublic(Class clazz, Member member)
true
if the member is public and the class
is public.
clazz
- the class to check for publicmember
- the member to check for public
true
if the member is public and the class is publicpublic static boolean isAbstractClass(Class clazz)
true
of the class is an abstract class. An
abstract class is a either an abstract class or an interface.
clazz
- the class to check for abstact
true
if the class is an abstract classpublic static Constructor getDefaultConstructor(Class clazz)
clazz
- the class to get the default constructor
public static String convertResourcePathToClassName(String resourcePath)
resourcePath
- the resource path pointing to a class
public static String convertClassNameToResourcePath(String className)
className
- the fully qualified class name
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |