|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.datanucleus.util.ClassUtils
public class ClassUtils
Utilities for handling classes. These are to supplement the methods provided by the Class object.
| Field Summary | |
|---|---|
protected static java.util.Map |
constructorsCache
caching for constructors - using caching, the perf is at least doubled |
protected static Localiser |
LOCALISER
Localisation utility for output messages |
| Constructor Summary | |
|---|---|
ClassUtils()
|
|
| Method Summary | |
|---|---|
static void |
assertClassForJarExistsInClasspath(ClassLoaderResolver clr,
java.lang.String className,
java.lang.String jarName)
Convenience method to throw a NucleusUserException if the specified class is not loadable from the ClassLoaderResolver. |
static boolean |
classesAreDescendents(ClassLoaderResolver clr,
java.lang.String class_name_1,
java.lang.String class_name_2)
Method to check if 2 classes are direct descendents. |
static java.lang.Object |
convertValue(java.lang.Object value,
java.lang.Class cls)
Convenience method to convert the passed value to an object of the specified type (if possible). |
static java.lang.String |
createFullClassName(java.lang.String pkg_name,
java.lang.String cls_name)
Utility to create the full class name given the package and class name. |
static void |
dumpClassInformation(java.lang.Class cls)
Utility to use Reflection to dump out the details of a class. |
static java.util.Collection |
getClassFilesForDirectory(java.io.File dir,
boolean normal_classes,
boolean inner_classes)
Method to return the class files below the specified directory. |
static java.lang.Class |
getClassForMemberOfClass(java.lang.Class cls,
java.lang.String memberName)
Method that returns the class type of a member of the specified class (if present). |
static java.lang.String |
getClassNameForClass(java.lang.Class cls)
Utility to return the class name without the package name for a class. |
static java.lang.String |
getClassnameForFilename(java.lang.String filename,
java.lang.String rootfilename)
Utility to get the Class name given the file name and the file name of the root of the package structure. |
static java.lang.String |
getClassNameForFileURL(java.net.URL fileURL)
Utility to find the class name of a class given the absolute file name of its class file. |
static java.lang.String[] |
getClassNamesForDirectoryAndBelow(java.io.File dir)
Convenience method to return the names of classes specified in the directory and below. |
static java.lang.String[] |
getClassNamesForJarFile(java.lang.String jarFileName)
Convenience accessor for the names of all class files in the jar file with the specified name. |
static java.lang.String[] |
getClassNamesForJarFile(java.net.URL jarFileURL)
Convenience accessor for the names of all class files in the jar file with the specified URL. |
static java.lang.String |
getCollectionElementType(java.lang.Class type,
java.lang.reflect.Type genericType)
Convenience method to extract the element type of a collection when using JDK1.5 generics given the input field. |
static java.lang.String |
getCollectionElementType(java.lang.reflect.Field field)
Convenience method to extract the element type of a collection when using JDK1.5 generics given the input field. |
static java.lang.String |
getCollectionElementType(java.lang.reflect.Method method)
Convenience method to extract the element type of a collection when using JDK1.5 generics, given the input method (getter). |
static java.lang.reflect.Constructor |
getConstructorWithArguments(java.lang.Class cls,
java.lang.Class[] types)
Convenience method to return the constructor of the passed class that accepts the supplied argument types. |
static java.lang.reflect.Field |
getFieldForClass(java.lang.Class cls,
java.lang.String fieldName)
Obtain a field from a class or superclasses using reflection. |
static java.lang.String |
getFieldNameForJavaBeanGetter(java.lang.String methodName)
Generate a field name for JavaBeans compatible getter method |
static java.lang.String |
getFieldNameForJavaBeanSetter(java.lang.String methodName)
Generate a field name for JavaBeans compatible setter method |
static java.lang.reflect.Method |
getGetterMethodForClass(java.lang.Class cls,
java.lang.String beanName)
Obtain a (Java bean) getter method from a class or superclasses using reflection. |
static java.lang.String |
getJavaBeanGetterName(java.lang.String fieldName,
boolean isBoolean)
Generate a JavaBeans compatible getter name |
static java.lang.String |
getJavaBeanSetterName(java.lang.String fieldName)
Generate a JavaBeans compatible setter name |
static java.lang.String |
getJavaLangClassForType(java.lang.String type)
Convenience method to return the passed type as a java.lang type wherever possible. |
static java.lang.String |
getMapKeyType(java.lang.Class type,
java.lang.reflect.Type genericType)
Convenience method to extract the key type of a map when using JDK1.5 generics given the input field. |
static java.lang.String |
getMapKeyType(java.lang.reflect.Field field)
Convenience method to extract the key type of a map when using JDK1.5 generics given the input field. |
static java.lang.String |
getMapKeyType(java.lang.reflect.Method method)
Convenience method to extract the key type of a map when using JDK1.5 generics given the input method. |
static java.lang.String |
getMapValueType(java.lang.Class type,
java.lang.reflect.Type genericType)
Convenience method to extract the value type of a map when using JDK1.5 generics given the input field |
static java.lang.String |
getMapValueType(java.lang.reflect.Field field)
Convenience method to extract the value type of a map when using JDK1.5 generics given the input field |
static java.lang.String |
getMapValueType(java.lang.reflect.Method method)
Convenience method to extract the value type of a map when using JDK1.5 generics given the input method. |
static java.lang.reflect.Method |
getMethodForClass(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] argtypes)
Obtain a method from a class or superclasses using reflection |
static java.lang.reflect.Method |
getMethodWithArgument(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class argType)
Obtain a method from a class or superclasses using reflection. |
static int |
getModifiersForFieldOfClass(ClassLoaderResolver clr,
java.lang.String className,
java.lang.String fieldName)
Convenience accessor for the modifiers of a field in a class. |
static java.lang.String[] |
getPackageJdoFilesForJarFile(java.lang.String jarFileName)
Convenience accessor for the names of all "package.jdo" files in the jar file with the specified name. |
static java.lang.String[] |
getPackageJdoFilesForJarFile(java.net.URL jarFileURL)
Convenience accessor for the names of all "package.jdo" files in the jar file with the specified URL. |
static java.lang.String |
getPackageNameForClass(java.lang.Class cls)
Utility to return the package name for a class. |
static java.lang.Class |
getPrimitiveTypeForType(java.lang.Class type)
Method to return the primitive equivalent of the specified type (if any). |
static java.util.Collection |
getSuperclasses(java.lang.Class the_class)
Method to return the superclasses for a class. |
static java.util.Collection |
getSuperinterfaces(java.lang.Class the_class)
Method to return the superinterfaces for a class. |
static java.lang.Object |
getValueForIdentityField(java.lang.Object id,
java.lang.String fieldName)
Method to find the value of a field of the provided user-defined identity. |
static java.lang.Object |
getValueOfFieldByReflection(java.lang.Object object,
java.lang.String fieldName)
Helper method to return the value of a field of an object using reflection. |
static java.lang.Object |
getValueOfMethodByReflection(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
Helper method to return the value returned by a method on an object using reflection. |
static java.lang.Class |
getWrapperTypeForPrimitiveType(java.lang.Class type)
Convenience method to return the object wrapper type for a primitive type. |
static java.lang.String |
getWrapperTypeNameForPrimitiveTypeName(java.lang.String typeName)
Convenience method to return the object wrapper type for a primitive type name. |
static boolean |
hasDefaultConstructor(java.lang.Class the_class)
Method to check for a default constructor on a class. |
static boolean |
isInnerClass(java.lang.String class_name)
Method to check whether a classname is for an inner class. |
static boolean |
isPrimitiveArrayType(java.lang.String typeName)
Convenience method to return if the passed type (name) is a primitive array type. |
static boolean |
isPrimitiveType(java.lang.String typeName)
Convenience method to return if the passed type (name) is a primitive type. |
static boolean |
isPrimitiveWrapperType(java.lang.String typeName)
Convenience method to return if the passed type (name) is a primitive wrapper type. |
static boolean |
isReferenceType(java.lang.Class cls)
Method to return whether the passes type is a "reference" type. |
static java.lang.Object |
newInstance(java.lang.Class type,
java.lang.Class[] parameterTypes,
java.lang.Object[] parameters)
Accessor for a new instance of an object. |
static boolean |
stringArrayContainsValue(java.lang.String[] array,
java.lang.String value)
Convenience method to return if a String array contains a value. |
static boolean |
typesAreCompatible(java.lang.Class cls1,
java.lang.Class cls2)
Convenience method to return if two types are compatible. |
static boolean |
typesAreCompatible(java.lang.Class cls1,
java.lang.String clsName2,
ClassLoaderResolver clr)
Convenience method to return if two types are compatible. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Localiser LOCALISER
protected static java.util.Map constructorsCache
| Constructor Detail |
|---|
public ClassUtils()
| Method Detail |
|---|
public static java.lang.Object newInstance(java.lang.Class type,
java.lang.Class[] parameterTypes,
java.lang.Object[] parameters)
type - Type of object (the class).parameterTypes - Classes of params for the constructorparameters - The parameters for the constructor
NucleusException - If an error occurs creating the instance
public static java.lang.reflect.Constructor getConstructorWithArguments(java.lang.Class cls,
java.lang.Class[] types)
cls - The classtypes - The constructor argument types
public static java.lang.reflect.Method getMethodWithArgument(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class argType)
cls - the class to find the declared fields and populate the mapmethodName - the method name to findargType - the argument type
public static java.lang.reflect.Method getMethodForClass(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] argtypes)
cls - the class where to look for the methodmethodName - the method name to findargtypes - the classes argument of the method
public static java.lang.String getClassnameForFilename(java.lang.String filename,
java.lang.String rootfilename)
filename - The filename of the class filerootfilename - The filename of the root of the package structure
public static java.util.Collection getClassFilesForDirectory(java.io.File dir,
boolean normal_classes,
boolean inner_classes)
dir - The directorynormal_classes - Whether to include normal classesinner_classes - Whether to include inner classes
public static java.lang.String[] getClassNamesForJarFile(java.lang.String jarFileName)
jarFileName - Name of the jar file
public static java.lang.String[] getClassNamesForJarFile(java.net.URL jarFileURL)
jarFileURL - URL for the jar file
public static java.lang.String[] getPackageJdoFilesForJarFile(java.lang.String jarFileName)
jarFileName - Name of the jar file
public static java.lang.String[] getPackageJdoFilesForJarFile(java.net.URL jarFileURL)
jarFileURL - URL for the jar file
public static java.lang.String[] getClassNamesForDirectoryAndBelow(java.io.File dir)
dir - Directory that we should look below (root of classpath)
public static boolean isInnerClass(java.lang.String class_name)
class_name - The class name
public static boolean hasDefaultConstructor(java.lang.Class the_class)
the_class - The class
public static java.util.Collection getSuperclasses(java.lang.Class the_class)
the_class - The class
public static java.util.Collection getSuperinterfaces(java.lang.Class the_class)
the_class - The class
public static java.lang.reflect.Field getFieldForClass(java.lang.Class cls,
java.lang.String fieldName)
cls - the class to find the field fromfieldName - the field name to find
public static java.lang.reflect.Method getGetterMethodForClass(java.lang.Class cls,
java.lang.String beanName)
cls - the class to find the getter frombeanName - the name of the java bean to find the getter for
public static java.lang.String getWrapperTypeNameForPrimitiveTypeName(java.lang.String typeName)
typeName - The primitive type name
public static java.lang.Class getWrapperTypeForPrimitiveType(java.lang.Class type)
type - The primitive type
public static java.lang.Class getPrimitiveTypeForType(java.lang.Class type)
type - The type
public static boolean isPrimitiveWrapperType(java.lang.String typeName)
typeName - Name of the type
public static boolean isPrimitiveArrayType(java.lang.String typeName)
typeName - Name of the type
public static boolean isPrimitiveType(java.lang.String typeName)
typeName - Name of the type
public static java.lang.Object convertValue(java.lang.Object value,
java.lang.Class cls)
value - The valuecls - The class
public static boolean typesAreCompatible(java.lang.Class cls1,
java.lang.String clsName2,
ClassLoaderResolver clr)
cls1 - First classclsName2 - Name of the second classclr - ClassLoader resolver to use
public static boolean typesAreCompatible(java.lang.Class cls1,
java.lang.Class cls2)
cls1 - First classcls2 - Second class
public static java.lang.String createFullClassName(java.lang.String pkg_name,
java.lang.String cls_name)
packageName=test className=Test, returns result=test.Test packageName=test className=test1.Test, returns result=test1.Test packageName=<null> className=Test, returns result=Test packageName=<null> className=test1.Test, returns result=test1.Test
pkg_name - package name.cls_name - class name.
public static java.lang.String getJavaLangClassForType(java.lang.String type)
type - The type name
public static boolean classesAreDescendents(ClassLoaderResolver clr,
java.lang.String class_name_1,
java.lang.String class_name_2)
clr - ClassLoaderResolver for loading the classesclass_name_1 - Name of first classclass_name_2 - Name of second class
public static void dumpClassInformation(java.lang.Class cls)
cls - The class to dump out to the log
public static java.lang.String getJavaBeanGetterName(java.lang.String fieldName,
boolean isBoolean)
fieldName - the field nameisBoolean - whether the field is primitive boolean type
public static java.lang.String getJavaBeanSetterName(java.lang.String fieldName)
fieldName - the field name
public static java.lang.String getFieldNameForJavaBeanGetter(java.lang.String methodName)
methodName - the method name
public static java.lang.String getFieldNameForJavaBeanSetter(java.lang.String methodName)
methodName - the method name
public static java.lang.String getClassNameForFileURL(java.net.URL fileURL)
throws java.lang.ClassNotFoundException
fileURL - URL for the class file
java.lang.ClassNotFoundException - Thrown when the file is not foundpublic static java.lang.String getPackageNameForClass(java.lang.Class cls)
cls - The class
public static java.lang.String getClassNameForClass(java.lang.Class cls)
cls - The class
public static java.lang.String getCollectionElementType(java.lang.reflect.Field field)
field - The field
public static java.lang.String getCollectionElementType(java.lang.Class type,
java.lang.reflect.Type genericType)
type - the field typegenericType - the generic type
public static java.lang.String getCollectionElementType(java.lang.reflect.Method method)
method - The method
public static java.lang.String getMapKeyType(java.lang.reflect.Field field)
field - The field
public static java.lang.String getMapKeyType(java.lang.Class type,
java.lang.reflect.Type genericType)
type - the field typegenericType - the generic type
public static java.lang.String getMapKeyType(java.lang.reflect.Method method)
method - The method
public static java.lang.String getMapValueType(java.lang.reflect.Field field)
field - The field
public static java.lang.String getMapValueType(java.lang.Class type,
java.lang.reflect.Type genericType)
type - the field typegenericType - the generic type
public static java.lang.String getMapValueType(java.lang.reflect.Method method)
method - The method
public static int getModifiersForFieldOfClass(ClassLoaderResolver clr,
java.lang.String className,
java.lang.String fieldName)
clr - ClassLoader resolverclassName - Name of the classfieldName - Name of the field
public static boolean isReferenceType(java.lang.Class cls)
cls - The type
public static void assertClassForJarExistsInClasspath(ClassLoaderResolver clr,
java.lang.String className,
java.lang.String jarName)
clr - ClassLoader resolverclassName - Name of the classjarName - Name of the jar containing the class
NucleusUserException - if the class is not found
public static boolean stringArrayContainsValue(java.lang.String[] array,
java.lang.String value)
array - The String arrayvalue - The value
public static java.lang.Object getValueOfMethodByReflection(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
object - The objectmethodName - Name of the method
public static java.lang.Object getValueOfFieldByReflection(java.lang.Object object,
java.lang.String fieldName)
object - The objectfieldName - Name of the field
public static java.lang.Object getValueForIdentityField(java.lang.Object id,
java.lang.String fieldName)
id - The identityfieldName - Name of the field
NucleusUserException - if not possible to get the value
public static java.lang.Class getClassForMemberOfClass(java.lang.Class cls,
java.lang.String memberName)
cls - The classmemberName - The member name
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||