org.opennms.protocols.jmx.connectors
Class IsolatingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.opennms.protocols.jmx.connectors.IsolatingClassLoader

public class IsolatingClassLoader
extends URLClassLoader

An extension of the URLClassLoader that ensures it loads specified packages rather letting the parent do it. The result is that classes loaded from these packages are isolated from other classloaders.

Author:
Mike Jamison , OpenNMS

Nested Class Summary
static class IsolatingClassLoader.InvalidContextClassLoaderException
           
 
Constructor Summary
IsolatingClassLoader(String name, URL[] classpath, ClassLoader parent, String[] isolated, boolean augmentClassPath)
           
IsolatingClassLoader(String name, URL[] classpath, String[] isolated, boolean augmentClassPath)
           
 
Method Summary
protected  Class loadClass(String name, boolean resolve)
          Override to only check parent ClassLoader if the class name doesn't match our list of isolated classes.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IsolatingClassLoader

public IsolatingClassLoader(String name,
                            URL[] classpath,
                            String[] isolated,
                            boolean augmentClassPath)
                     throws IsolatingClassLoader.InvalidContextClassLoaderException
Parameters:
classpath - Where to find classes.
isolated - Array of fully qualified class names, or fully qualified prefixes ending in "*", that identify the packages or classes to isolate.
augmentClassPath - true => Add the URL's of the current thread context class loader to classpath.
Throws:
IsolatingClassLoader.InvalidContextClassLoaderException - If augmentClassPath is true and the current thread context class loader is not a URLClassLoader.

IsolatingClassLoader

public IsolatingClassLoader(String name,
                            URL[] classpath,
                            ClassLoader parent,
                            String[] isolated,
                            boolean augmentClassPath)
                     throws IsolatingClassLoader.InvalidContextClassLoaderException
Parameters:
classpath - Where to find classes.
isolated - Array of fully qualified class names, or fully qualified prefixes ending in "*", that identify the packages or classes to isolate.
augmentClassPath - true => Add the URL's of the current thread context class loader to classpath.
Throws:
IsolatingClassLoader.InvalidContextClassLoaderException - If augmentClassPath is true and the current thread context class loader is not a URLClassLoader.
Method Detail

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Override to only check parent ClassLoader if the class name doesn't match our list of isolated classes.

Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException


Copyright © 2009. All Rights Reserved.