public final class Loader
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static Logger |
LOGGER |
private static java.lang.String |
TSTR |
Modifier | Constructor and Description |
---|---|
private |
Loader() |
Modifier and Type | Method and Description |
---|---|
static java.lang.ClassLoader |
getClassLoader()
Returns the ClassLoader to use.
|
static java.lang.ClassLoader |
getClassLoader(java.lang.Class<?> class1,
java.lang.Class<?> class2) |
static java.net.URL |
getResource(java.lang.String resource,
java.lang.ClassLoader defaultLoader)
This method will search for
resource in different
places. |
static java.io.InputStream |
getResourceAsStream(java.lang.String resource,
java.lang.ClassLoader defaultLoader)
This method will search for
resource in different
places. |
static java.lang.ClassLoader |
getThreadContextClassLoader()
Returns the ClassLoader of current thread if possible, or falls back to the system ClassLoader if none is
available.
|
static java.lang.Class<?> |
initializeClass(java.lang.String className,
java.lang.ClassLoader loader)
Loads and initializes a named Class using a given ClassLoader.
|
private static boolean |
isChild(java.lang.ClassLoader loader1,
java.lang.ClassLoader loader2)
Determines if one ClassLoader is a child of another ClassLoader.
|
static boolean |
isClassAvailable(java.lang.String className)
Determines if a named Class can be loaded or not.
|
static boolean |
isJansiAvailable() |
static java.lang.Class<?> |
loadClass(java.lang.String className,
java.lang.ClassLoader loader)
Loads a named Class using a given ClassLoader.
|
static java.lang.Class<?> |
loadSystemClass(java.lang.String className)
Load a Class in the
java.* namespace by name. |
static <T> T |
newCheckedInstanceOf(java.lang.String className,
java.lang.Class<T> clazz)
Loads, instantiates, and casts a Class using the default constructor.
|
static java.lang.Object |
newInstanceOf(java.lang.String className)
Loads and instantiates a Class using the default constructor.
|
private static final Logger LOGGER
private static final java.lang.String TSTR
public static java.lang.ClassLoader getClassLoader()
public static java.lang.ClassLoader getThreadContextClassLoader()
LoaderUtil.getThreadContextClassLoader()
public static java.lang.ClassLoader getClassLoader(java.lang.Class<?> class1, java.lang.Class<?> class2)
public static java.net.URL getResource(java.lang.String resource, java.lang.ClassLoader defaultLoader)
resource
in different
places. The search order is as follows:
resource
using the thread context
class loader under Java2. If that fails, search for
resource
using the class loader that loaded this
class (Loader
). Under JDK 1.1, only the the class
loader that loaded this class (Loader
) is used.ClassLoader.getSystemResource(resource)
, that is is
using the system class loader in JDK 1.2 and virtual machine's
built-in class loader in JDK 1.1.resource
- The resource to load.defaultLoader
- The default ClassLoader.public static java.io.InputStream getResourceAsStream(java.lang.String resource, java.lang.ClassLoader defaultLoader)
resource
in different
places. The search order is as follows:
resource
using the thread context
class loader under Java2. If that fails, search for
resource
using the class loader that loaded this
class (Loader
). Under JDK 1.1, only the the class
loader that loaded this class (Loader
) is used.ClassLoader.getSystemResource(resource)
, that is is
using the system class loader in JDK 1.2 and virtual machine's
built-in class loader in JDK 1.1.resource
- The resource to load.defaultLoader
- The default ClassLoader.private static boolean isChild(java.lang.ClassLoader loader1, java.lang.ClassLoader loader2)
null
ClassLoader is
interpreted as the system ClassLoader as per convention.loader1
- the ClassLoader to check for childhood.loader2
- the ClassLoader to check for parenthood.true
if the first ClassLoader is a strict descendant of the second ClassLoader.public static java.lang.Class<?> initializeClass(java.lang.String className, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundException
className
- The class name.loader
- The class loader.java.lang.ClassNotFoundException
- if the class could not be found.public static java.lang.Class<?> loadClass(java.lang.String className, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundException
className
- The class name.loader
- The class loader.java.lang.ClassNotFoundException
- if the class could not be found.public static java.lang.Class<?> loadSystemClass(java.lang.String className) throws java.lang.ClassNotFoundException
java.*
namespace by name. Useful for peculiar scenarios typically involving
Google App Engine.className
- The class name.java.lang.ClassNotFoundException
- if the Class could not be found.public static java.lang.Object newInstanceOf(java.lang.String className) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
className
- The class name.java.lang.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersjava.lang.IllegalAccessException
- if the class can't be instantiated through a public constructorjava.lang.InstantiationException
- if there was an exception whilst instantiating the classjava.lang.NoSuchMethodException
- if there isn't a no-args constructor on the classjava.lang.reflect.InvocationTargetException
- if there was an exception whilst constructing the classpublic static <T> T newCheckedInstanceOf(java.lang.String className, java.lang.Class<T> clazz) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
T
- The type to cast it to.className
- The class name.clazz
- The class to cast it to.T
java.lang.ClassNotFoundException
- if the class isn't available to the usual ClassLoadersjava.lang.IllegalAccessException
- if the class can't be instantiated through a public constructorjava.lang.InstantiationException
- if there was an exception whilst instantiating the classjava.lang.NoSuchMethodException
- if there isn't a no-args constructor on the classjava.lang.reflect.InvocationTargetException
- if there was an exception whilst constructing the classjava.lang.ClassCastException
- if the constructed object isn't type compatible with T
public static boolean isClassAvailable(java.lang.String className)
className
- The class name.true
if the class could be found or false
otherwise.public static boolean isJansiAvailable()