@Typed public abstract class ClassUtils extends Object
ClassLoader
and Manifest
handlingModifier and Type | Method and Description |
---|---|
static ClassLoader |
getClassLoader(Object o)
Detect the right ClassLoader.
|
static String |
getJarVersion(Class targetClass)
Reads the version of the jar which contains the given class
|
static String |
getRevision(Class targetClass)
Reads the VCS revision which was used for creating the jar
|
static Object |
instantiateClassForName(String className)
Creates an instance for the given class-name
|
static Class |
loadClassForName(String name)
Loads class for the given name
|
static <T> T |
tryToInstantiateClass(Class<T> targetClass)
Instantiates a given class via the default constructor
|
static Object |
tryToInstantiateClassForName(String className)
Tries to instantiate a class for the given name via the default constructor
|
static <T> T |
tryToInstantiateClassForName(String className,
Class<T> targetType)
Tries to instantiate a class for the given name and type via the default constructor
|
static Class |
tryToLoadClassForName(String name)
Tries to load a class based on the given name
|
static <T> Class<T> |
tryToLoadClassForName(String name,
Class<T> targetType)
Tries to load a class based on the given name and interface or abstract class.
|
public static ClassLoader getClassLoader(Object o)
o
- if not null
it may get used to detect the classloader.ClassLoader
which should get used to create new instancespublic static <T> Class<T> tryToLoadClassForName(String name, Class<T> targetType)
T
- current typename
- name of the concrete classtargetType
- target type (interface or abstract class)public static Class tryToLoadClassForName(String name)
name
- name of the classnull
if it isn't in the classpathpublic static Class loadClassForName(String name) throws ClassNotFoundException
name
- name of the classClassNotFoundException
- if the class can't be loadedpublic static <T> T tryToInstantiateClass(Class<T> targetClass)
T
- current typetargetClass
- class which should be instantiatedpublic static <T> T tryToInstantiateClassForName(String className, Class<T> targetType)
T
- current typeclassName
- name of the classtargetType
- target typepublic static Object tryToInstantiateClassForName(String className)
className
- name of the classpublic static Object instantiateClassForName(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
className
- name of the class which should be instantiatedClassNotFoundException
- if the instantiation failedIllegalAccessException
- if the instantiation failedInstantiationException
- if the instantiation failedpublic static String getJarVersion(Class targetClass)
targetClass
- class within the jarCopyright © 2015 The Apache Software Foundation. All rights reserved.