public final class Classes extends Object
Class
utilities.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PACKAGE_NAME
The default package name.
|
static String |
PACKAGE_SEPARATOR
The string used to separator packages
|
static char |
PACKAGE_SEPARATOR_CHAR
The characther used to separator packages
|
Constructor and Description |
---|
Classes() |
Modifier and Type | Method and Description |
---|---|
static Class<?>[] |
convertToJavaClasses(Iterator<String> it,
ClassLoader cl)
Convert a list of Strings from an Interator into an array of
Classes (the Strings are taken as classnames).
|
static void |
describe(StringBuffer buffer,
Class clazz)
Describe the class
|
static void |
describe(StringBuffer buffer,
Object object)
Describe the class of an object
|
static void |
displayClassInfo(Class clazz,
StringBuffer results)
Format a string buffer containing the Class, Interfaces, CodeSource,
and ClassLoader information for the given object clazz.
|
static void |
forceLoad(Class type)
Force the given class to be loaded fully.
|
static void |
getAllInterfaces(List allIfaces,
Class c)
Populates a list with all the interfaces implemented by the argument
class c and all its superclasses.
|
static Class[] |
getAllUniqueInterfaces(Class c)
Returns an array containing all the unique interfaces implemented
by the argument class c and all its superclasses.
|
static Method |
getAttributeGetter(Class cls,
String attr)
Returns attribute's getter method.
|
static Method |
getAttributeSetter(Class cls,
String attr,
Class type)
Returns attribute's setter method.
|
static URL[] |
getClassLoaderURLs(ClassLoader cl)
Use reflection to access a URL[] getURLs or URL[] getClasspath method so
that non-URLClassLoader class loaders, or class loaders that override
getURLs to return null or empty, can provide the true classpath info.
|
static String |
getDescription(Object object)
Describe the class of an object
|
static String |
getPackageName(Class type)
Get the package name of the specified class.
|
static String |
getPackageName(String classname)
Get the package name of the specified class.
|
static Class |
getPrimitive(Class wrapper) |
static Class |
getPrimitiveTypeForName(String name)
Get the primitive type for the given primitive name.
|
static Class |
getPrimitiveWrapper(Class type)
Get the wrapper class for the given primitive type.
|
static Object |
instantiate(Class expected,
String property,
String defaultClassName)
Instantiate a java class object
|
static boolean |
isPrimitive(Class type)
Check if the given class is a primitive class or a primitive
wrapper class.
|
static boolean |
isPrimitive(String type)
Check type against boolean, byte, char, short, int, long, float, double.
|
static boolean |
isPrimitiveWrapper(Class type)
Check if the given class is a primitive wrapper class.
|
static Class |
loadClass(String className)
This method acts equivalently to invoking
Thread.currentThread().getContextClassLoader().loadClass(className); but it also
supports primitive types and array classes of object types or primitive types. |
static Class |
loadClass(String className,
ClassLoader classLoader)
This method acts equivalently to invoking classLoader.loadClass(className)
but it also supports primitive types and array classes of object types or
primitive types.
|
static String |
stripPackageName(Class type)
Get the short name of the specified class by striping off the package
name.
|
static String |
stripPackageName(String classname)
Get the short name of the specified class by striping off the package
name.
|
public static final String PACKAGE_SEPARATOR
public static final char PACKAGE_SEPARATOR_CHAR
public static final String DEFAULT_PACKAGE_NAME
public static void displayClassInfo(Class clazz, StringBuffer results)
clazz
- the Classresults
- - the buffer to write the info topublic static URL[] getClassLoaderURLs(ClassLoader cl)
cl
- public static String getDescription(Object object)
object
- the objectpublic static void describe(StringBuffer buffer, Object object)
buffer
- the string bufferobject
- the objectpublic static void describe(StringBuffer buffer, Class clazz)
buffer
- the string bufferclazz
- the clazzpublic static String stripPackageName(String classname)
classname
- Class name.public static String stripPackageName(Class type)
type
- Class name.public static String getPackageName(String classname)
classname
- Class name.EmptyStringException
- Classname is an empty string.public static String getPackageName(Class type)
type
- Class.public static void forceLoad(Class type)
This method attempts to locate a static method on the given class the attempts to invoke it with dummy arguments in the hope that the virtual machine will prepare the class for the method call and call all of the static class initializers.
type
- Class to force load.NullArgumentException
- Type is null.public static Class getPrimitiveTypeForName(String name)
For example, "boolean" returns Boolean.TYPE and so on...
name
- Primitive type name (boolean, int, byte, ...)IllegalArgumentException
- Type is not a primitive classpublic static Class getPrimitiveWrapper(Class type)
type
- Primitive class.IllegalArgumentException
- Type is not a primitive classpublic static void getAllInterfaces(List allIfaces, Class c)
allIfaces
- - the list to populate with the interfacesc
- - the class to start scanning for interfacespublic static Class[] getAllUniqueInterfaces(Class c)
c
- - the class to start scanning for interfacespublic static boolean isPrimitiveWrapper(Class type)
type
- Class to check.public static boolean isPrimitive(Class type)
type
- Class to check.public static boolean isPrimitive(String type)
type
- The java type namepublic static Class getPrimitive(Class wrapper)
wrapper
- a primitive wrapper typepublic static Object instantiate(Class expected, String property, String defaultClassName)
expected
- the expected class typeproperty
- the system property defining the classdefaultClassName
- the default class namepublic static Class loadClass(String className) throws ClassNotFoundException
Thread.currentThread().getContextClassLoader().loadClass(className);
but it also
supports primitive types and array classes of object types or primitive types.className
- the qualified name of the class or the name of primitive type or
array in the same format as returned by the
java.lang.Class.getName()
method.ClassNotFoundException
- when the classLoader
can not find the requested classpublic static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException
className
- the qualified name of the class or the name of primitive
type or array in the same format as returned by the
java.lang.Class.getName() method.classLoader
- the ClassLoader used to load classesClassNotFoundException
- when the classLoader
can not
find the requested classpublic static final Class<?>[] convertToJavaClasses(Iterator<String> it, ClassLoader cl) throws ClassNotFoundException
it
- A java.util.Iterator pointing to a Collection of Stringscl
- The ClassLoader to useClassNotFoundException
- When a class could not be loaded from
the specified ClassLoaderpublic static final Method getAttributeGetter(Class cls, String attr) throws NoSuchMethodException
cls
- the class the attribute belongs tooattr
- the attribute's nameNoSuchMethodException
- if the getter was not foundNoSuchMethodException
public static final Method getAttributeSetter(Class cls, String attr, Class type) throws NoSuchMethodException
cls
- the class the attribute belongs toattr
- the attribute's nametype
- the attribute's typeNoSuchMethodException
- if the setter was not foundNoSuchMethodException
Copyright © 2018 JBoss by Red Hat. All rights reserved.