Class ClassLoaderHelper

java.lang.Object
com.j_spaces.kernel.ClassLoaderHelper

public class ClassLoaderHelper extends Object
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 Details

    • ClassLoaderHelper

      public ClassLoaderHelper()
  • Method Details

    • newInstance

      public static <T> T newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
      Throws:
      ClassNotFoundException
      IllegalAccessException
      InstantiationException
    • loadClass

      public static Class loadClass(String className) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • loadLocalClass

      public static Class loadLocalClass(String className) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • loadClass

      public static Class loadClass(String className, boolean localOnly) throws ClassNotFoundException
      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

      public static Class loadClass(String className, boolean localOnly, Class defaultClass)
    • loadClass

      public static Class loadClass(String codebase, String className, ClassLoader classLoader) throws ClassNotFoundException, MalformedURLException
      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 the loadClass(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 load
      className - the name of the class to load
      classLoader - additional contextual class loader to use, or null
      localOnly - 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 location
      MalformedURLException - 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

      public static ClassLoader getContextClassLoader()
      Returns:
      The context ClassLoader of the current Thread.
    • setContextClassLoader

      public static void setContextClassLoader(ClassLoader cl, boolean ignoreSecurity)
      Set current thread context ClassLoader.
      Parameters:
      cl - the classLoader to set.
      ignoreSecurity - if true the java security will be ignored(to gain performance), the direct reflection-field call will attempt to set contextClassLoader without calling thread method Thread.setContextClassLoader(ClassLoader). If non secured call was failed, the context will be set by regular way via Thread.setContextClassLoader(ClassLoader).
    • getClassLoaderLogName

      public static String getClassLoaderLogName(ClassLoader cl)