public final class ClassHelper
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static char |
INNER_CLASS_SEPARATOR_CHAR |
static char |
JAR_PATH_SEPARATOR_CHAR |
static java.lang.String |
JAR_PATH_SEPARATOR_STRING |
static char |
PACKAGE_SEPARATOR_CHAR |
| Constructor and Description |
|---|
ClassHelper() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsClassName(java.lang.String path,
java.lang.String name,
char pathSeparatorChar)
Checks if the given name is the name of a class in path.
|
static java.lang.Class |
createClassByName(java.lang.String cl)
Returns a class by its name inclusively the primitive types and arrays of primitive types, e.g., int[].
|
static java.lang.String |
getBasicName(java.lang.Class c)
Extract the basic class name from a Class object.
|
static java.util.List<java.lang.String> |
getClassPath()
Returns the class path.
|
static java.lang.Object |
getField(java.lang.Object obj,
java.lang.String name)
Use Java Reflection to get the value of the object attribute for this Parameter.
|
static java.lang.Object |
getField(java.lang.Object obj,
java.lang.String name,
java.lang.Object defaultValue)
Use Java Reflection to get the value of the object attribute for this Parameter.
|
static java.lang.String |
getNameFromClassPath(java.lang.String name)
Returns a path containing 'name' in the resources of the class path.
|
static java.lang.String |
getNameFromDir(java.io.File file,
java.lang.String name)
Returns the path to a file name containing 'name' starting recursively at directory 'file'.
|
static java.lang.String |
getNameFromFileSystem(java.lang.String path,
java.lang.String name)
Returns a path containing 'name', where the search starts at 'path'.
|
static java.lang.String |
getNameFromJar(java.io.File file,
java.lang.String name)
Returns a jar file entry containing a resource with 'name'.
|
static java.lang.String |
getQualifiedName(java.lang.String name)
Returns the qualified name of a possibly unqualified class name.
|
static java.lang.Object |
instantiateByClassName(java.lang.String className)
Instantiates an Object by passing the name of the Class in a
String.
|
static java.lang.Object |
instantiateByClassName(java.lang.String className,
java.lang.String[] constructorClassNames,
java.lang.Object[] constructorParameters)
Instantiates an Object by passing the name of the Class in a
String.
|
static boolean |
setField(java.lang.Object obj,
java.lang.String name,
java.lang.Object value)
Set the value of this parameter.
|
public static final char JAR_PATH_SEPARATOR_CHAR
public static final java.lang.String JAR_PATH_SEPARATOR_STRING
public static final char PACKAGE_SEPARATOR_CHAR
public static final char INNER_CLASS_SEPARATOR_CHAR
public static java.lang.Object instantiateByClassName(java.lang.String className)
className - the name of the Class to instantiateinstantiateByClassName(String, String[], Object[])public static java.lang.Object instantiateByClassName(java.lang.String className,
java.lang.String[] constructorClassNames,
java.lang.Object[] constructorParameters)
className - the name of the Class to instantiateconstructorClassNames - the names of the Classes of the parameters (may be null)constructorParameters - the actual parameters to the constructor (may be null)public static java.lang.String getBasicName(java.lang.Class c)
public static java.lang.String getQualifiedName(java.lang.String name)
name - an un/qualified namepublic static java.util.List<java.lang.String> getClassPath()
public static java.lang.String getNameFromClassPath(java.lang.String name)
Boone are not
searched.name - a stringpublic static java.lang.String getNameFromFileSystem(java.lang.String path,
java.lang.String name)
path - path to a directory or a jar filename - a stringpublic static java.lang.String getNameFromJar(java.io.File file,
java.lang.String name)
file - a jar filename - the resource name to be found in a jar entrypublic static java.lang.String getNameFromDir(java.io.File file,
java.lang.String name)
file - a directoryname - a string to be foundpublic static boolean containsClassName(java.lang.String path,
java.lang.String name,
char pathSeparatorChar)
path - a pathname - a class namepathSeparatorChar - this char depends not only on the system, but also on the resource (e.g., JAR)public static java.lang.Class createClassByName(java.lang.String cl)
throws java.lang.ClassNotFoundException
cl - The name of the class / type.java.lang.ClassNotFoundExceptionpublic static java.lang.Object getField(java.lang.Object obj,
java.lang.String name)
obj - Object whose attribute value to retrieve.name - Name of the attribute to retrieve.java.lang.RuntimeException - if it didn't work.public static java.lang.Object getField(java.lang.Object obj,
java.lang.String name,
java.lang.Object defaultValue)
Calls getField(Object, String).
obj - Object whose attribute value to retrieve.name - Name of the attribute to retrieve.defaultValue - Default value to return in case of an error.public static boolean setField(java.lang.Object obj,
java.lang.String name,
java.lang.Object value)
obj - Object whose attribute value to set.name - Name of the attribute to retrieve.value - Value to set the attribute to; can bei either an object, a wrapper
for simple data types, or the value of a simple data type.