public final class LoaderUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
IGNORE_TCCL_PROPERTY
System property to set to ignore the thread context ClassLoader.
|
Modifier and Type | Method and Description |
---|---|
static Collection<URL> |
findResources(String resource)
Finds classpath resources.
|
static ClassLoader[] |
getClassLoaders() |
static ClassLoader |
getThreadContextClassLoader()
Gets the current Thread ClassLoader.
|
static boolean |
isClassAvailable(String className)
Determines if a named Class can be loaded or not.
|
static Class<?> |
loadClass(String className)
Loads a class by name.
|
static <T> T |
newCheckedInstanceOf(String className,
Class<T> clazz)
Loads and instantiates a derived class using its default constructor.
|
static <T> T |
newCheckedInstanceOfProperty(String propertyName,
Class<T> clazz)
Loads and instantiates a class given by a property name.
|
static <T> T |
newInstanceOf(Class<T> clazz)
Loads and instantiates a Class using the default constructor.
|
static <T> T |
newInstanceOf(String className)
Loads and instantiates a Class using the default constructor.
|
public static final String IGNORE_TCCL_PROPERTY
public static ClassLoader getThreadContextClassLoader()
null
. If the system
ClassLoader is null
as well, then the ClassLoader for this class is returned. If running with a
SecurityManager
that does not allow access to the Thread ClassLoader or system ClassLoader, then the
ClassLoader for this class is returned.public static ClassLoader[] getClassLoaders()
public static boolean isClassAvailable(String className)
className
- The class name.true
if the class could be found or false
otherwise.public static Class<?> loadClass(String className) throws ClassNotFoundException
IGNORE_TCCL_PROPERTY
Log4j property. If this property is
specified and set to anything besides false
, then the default ClassLoader will be used.className
- The class name.ClassNotFoundException
- if the specified class name could not be foundpublic static <T> T newInstanceOf(Class<T> clazz) throws InstantiationException, IllegalAccessException, InvocationTargetException
clazz
- The class.IllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classInvocationTargetException
- if there was an exception whilst constructing the classpublic static <T> T newInstanceOf(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
className
- The class name.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classpublic static <T> T newCheckedInstanceOf(String className, Class<T> clazz) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException
T
- The type of the class to check.className
- The class name.clazz
- The class to cast it to.T
ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classClassCastException
- if the constructed object isn't type compatible with T
public static <T> T newCheckedInstanceOfProperty(String propertyName, Class<T> clazz) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException
T
- The type to cast it to.propertyName
- The property name to look up a class name for.clazz
- The class to cast it to.null
if the property was unset.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersIllegalAccessException
- if the class can't be instantiated through a public constructorInstantiationException
- if there was an exception whilst instantiating the classNoSuchMethodException
- if there isn't a no-args constructor on the classInvocationTargetException
- if there was an exception whilst constructing the classClassCastException
- if the constructed object isn't type compatible with T
public static Collection<URL> findResources(String resource)
resource
- the name of the resource to find.Copyright © 1999-1969 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.