Package com.j_spaces.kernel
Class ClassLoaderHelper
java.lang.Object
com.j_spaces.kernel.ClassLoaderHelper
This utility class which helps to load the desired class by the context ClassLoader for current
Thread. The context ClassLoader is provided by the creator of the current thread for use by code
running in this thread when loading classes and resources. Performs the specified
PrivilegedAction with privileges enabled. The action is performed with all of
the permissions possessed by the caller's protection domain.- Since:
- 5.1
- Version:
- 1.0
- Author:
- Igor Goldenberg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic ClassLoaderstatic Classstatic ClassLoad the desired class by the context ClassLoader for current Thread.static Classstatic ClassloadClass(String codebase, String className, ClassLoader classLoader) static ClassloadClass(String codebase, String className, ClassLoader classLoader, boolean localOnly) Load the desired class by the context ClassLoader for current Thread, or by use of RMIClassLoader which loads a class from a codebase URL path, optionally using the supplied loader.static ClassloadLocalClass(String className) static <T> TnewInstance(String className) static voidsetContextClassLoader(ClassLoader cl, boolean ignoreSecurity) Set current thread context ClassLoader.
-
Constructor Details
-
ClassLoaderHelper
public ClassLoaderHelper()
-
-
Method Details
-
newInstance
public static <T> T newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException -
loadClass
- Throws:
ClassNotFoundException
-
loadLocalClass
- Throws:
ClassNotFoundException
-
loadClass
Load the desired class by the context ClassLoader for current Thread.- Parameters:
className- the desired class to load.localOnly- whether or not to use the remote LRMI class loader.- Returns:
- the loaded class.
- Throws:
ClassNotFoundException- Failed to load the desired class.
-
loadClass
-
loadClass
public static Class loadClass(String codebase, String className, ClassLoader classLoader) throws ClassNotFoundException, MalformedURLException -
loadClass
public static Class loadClass(String codebase, String className, ClassLoader classLoader, boolean localOnly) throws ClassNotFoundException, MalformedURLException Load the desired class by the context ClassLoader for current Thread, or by use of RMIClassLoader which loads a class from a codebase URL path, optionally using the supplied loader. This method should be used when the caller would like to make available to the provider implementation an additional contextual class loader to consider, such as the loader of a caller on the stack. Typically, a provider implementation will attempt to resolve the named class using the given defaultLoader, if specified, before attempting to resolve the class from the codebase URL path. This method first delegates to theloadClass(String)methods with the className as argument, and if fails, delegates to the RMIClassLoaderSpi.loadClass(String,String,ClassLoader) method of the provider instance, passing codebase as the first argument, className as the second argument, and defaultLoader as the third argument.- Parameters:
codebase- the list of URLs (separated by spaces) to load the class from, or null name the name of the class to loadclassName- the name of the class to loadclassLoader- additional contextual class loader to use, or nulllocalOnly- whether or not to use the remote class loader.- Returns:
- the Class object representing the loaded class
- Throws:
ClassNotFoundException- if a definition for the class could not be found at the specified locationMalformedURLException- if codebase is non-null and contains an invalid URL, or if codebase is null and a provider-specific URL used to load classes is invalid
-
getContextClassLoader
- Returns:
- The context ClassLoader of the current Thread.
-
setContextClassLoader
Set current thread context ClassLoader.- Parameters:
cl- the classLoader to set.ignoreSecurity- iftruethe java security will be ignored(to gain performance), the direct reflection-field call will attempt to set contextClassLoader without calling thread methodThread.setContextClassLoader(ClassLoader). If non secured call was failed, the context will be set by regular way viaThread.setContextClassLoader(ClassLoader).
-
getClassLoaderLogName
-