com.stellent.cis.common.classloader
Class IsolatedJarClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by com.stellent.cis.common.classloader.IsolatedJarClassLoader

public class IsolatedJarClassLoader
extends java.net.URLClassLoader

Loads classes based on nested libraries within the jar file.


Nested Class Summary
static class IsolatedJarClassLoader.TemporaryFileManager
           
 
Field Summary
protected  java.lang.String[] m_delegateFilters
           
protected  java.util.jar.JarFile m_jarFile
           
protected  java.net.URL m_jarUrl
           
protected  java.lang.String m_libDirectory
           
protected  java.io.File m_localLibFolder
           
protected  java.util.List m_urls
           
 
Constructor Summary
IsolatedJarClassLoader(java.net.URL jarUrl, java.lang.ClassLoader delegate, java.lang.String[] delegateFilters)
          Build the classloader.
 
Method Summary
protected  java.io.File createLocalLibraryFolder()
          Determine the location of the local folder we will use to store our custom classpath
protected  java.net.URL extractJar(java.util.jar.JarEntry jarEntry)
          Extract the jar entry from the main jar file to the local lib directory
 java.io.File getLocalLibraryFolder()
           
 java.net.URL getResource(java.lang.String name)
          Searches locally first, then parent
protected  void initialize()
          Initialize the system; get URLs to all contained jar files...
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Loads the class with the specified name.
 
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, 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
 

Field Detail

m_delegateFilters

protected java.lang.String[] m_delegateFilters

m_jarUrl

protected java.net.URL m_jarUrl

m_jarFile

protected java.util.jar.JarFile m_jarFile

m_urls

protected java.util.List m_urls

m_libDirectory

protected java.lang.String m_libDirectory

m_localLibFolder

protected java.io.File m_localLibFolder
Constructor Detail

IsolatedJarClassLoader

public IsolatedJarClassLoader(java.net.URL jarUrl,
                              java.lang.ClassLoader delegate,
                              java.lang.String[] delegateFilters)
                       throws java.io.IOException
Build the classloader. Will search the jar represented by the URL for libraries and extract them getLocalLibraryFolder() directory.

Parameters:
jarUrl - url pointing to a jar file
delegate - classloader that will be delegated to for non-nested classes
delegateFilter - classes starting with the filter will be passed to the delegate loader first
Throws:
java.io.IOException
Method Detail

getLocalLibraryFolder

public java.io.File getLocalLibraryFolder()
Returns:
the file that stores the extracted local classpath files

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Loads the class with the specified name. The default implementation of this method searches for classes in the following order:

Overrides:
loadClass in class java.lang.ClassLoader
Returns:
The resulting Class object
Throws:
java.lang.ClassNotFoundException - If the class could not be found

getResource

public java.net.URL getResource(java.lang.String name)
Searches locally first, then parent

Overrides:
getResource in class java.lang.ClassLoader

createLocalLibraryFolder

protected java.io.File createLocalLibraryFolder()
                                         throws java.io.IOException
Determine the location of the local folder we will use to store our custom classpath

Returns:
a unique local folder
Throws:
java.io.IOException

initialize

protected void initialize()
                   throws java.io.IOException
Initialize the system; get URLs to all contained jar files...

Throws:
java.io.IOException

extractJar

protected java.net.URL extractJar(java.util.jar.JarEntry jarEntry)
                           throws java.io.IOException
Extract the jar entry from the main jar file to the local lib directory

Parameters:
jarEntry - the jar entry to extract
Returns:
the URL to the extracted file
Throws:
java.io.IOException