org.apache.xbean.server.classloader
Class JarFileClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.apache.xbean.server.classloader.NamedClassLoader
                  extended byorg.apache.xbean.server.classloader.MultiParentClassLoader
                      extended byorg.apache.xbean.server.classloader.JarFileClassLoader
All Implemented Interfaces:
DestroyableClassLoader

public class JarFileClassLoader
extends MultiParentClassLoader

The JarFileClassLoader that loads classes and resources from a list of JarFiles. This method is simmilar to URLClassLoader except it properly closes JarFiles when the classloader is destroyed so that the file read lock will be released, and the jar file can be modified and deleted.

Note: This implementation currently does not work reliably on windows, since the jar URL handler included with the Sun JavaVM holds a read lock on the JarFile, and this lock is not released when the jar url is dereferenced. To fix this a replacement for the jar url handler must be written.

Since:
2.0
Version:
$Id$
Author:
Dain Sundstrom

Constructor Summary
JarFileClassLoader(java.lang.String name, java.net.URL[] urls)
          Creates a JarFileClassLoader that is a child of the system class loader.
JarFileClassLoader(java.lang.String name, java.net.URL[] urls, java.lang.ClassLoader parent)
          Creates a JarFileClassLoader that is a child of the specified class loader.
JarFileClassLoader(java.lang.String name, java.net.URL[] urls, java.lang.ClassLoader[] parents)
          Creates a named class loader as a child of the specified parents.
JarFileClassLoader(java.lang.String name, java.net.URL[] urls, java.lang.ClassLoader[] parents, java.net.URLStreamHandlerFactory factory)
          Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory for accessing the urls..
JarFileClassLoader(java.lang.String name, java.net.URL[] urls, java.lang.ClassLoader parent, java.net.URLStreamHandlerFactory factory)
          Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory for accessing the urls..
 
Method Summary
protected  void addURL(java.net.URL url)
          
protected  void addURLs(java.util.List urls)
          Adds a list of urls to the end of this class loader.
protected  void addURLs(java.net.URL[] urls)
          Adds an array of urls to the end of this class loader.
 void destroy()
          Destroys the clasloader releasing all resources. After this mehtod is called, the class loader will no longer load any classes or resources.
protected  java.lang.Class findClass(java.lang.String className)
          
 java.net.URL findResource(java.lang.String resourceName)
          
 java.util.Enumeration findResources(java.lang.String resourceName)
          
 java.net.URL[] getURLs()
          
 
Methods inherited from class org.apache.xbean.server.classloader.MultiParentClassLoader
getParents, getResource, loadClass, toString
 
Methods inherited from class org.apache.xbean.server.classloader.NamedClassLoader
getName
 
Methods inherited from class java.net.URLClassLoader
definePackage, getPermissions, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, 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, wait, wait, wait
 

Constructor Detail

JarFileClassLoader

public JarFileClassLoader(java.lang.String name,
                          java.net.URL[] urls)
Creates a JarFileClassLoader that is a child of the system class loader.

Parameters:
name - the name of this class loader
urls - a list of URLs from which classes and resources should be loaded

JarFileClassLoader

public JarFileClassLoader(java.lang.String name,
                          java.net.URL[] urls,
                          java.lang.ClassLoader parent)
Creates a JarFileClassLoader that is a child of the specified class loader.

Parameters:
name - the name of this class loader
urls - a list of URLs from which classes and resources should be loaded
parent - the parent of this class loader

JarFileClassLoader

public JarFileClassLoader(java.lang.String name,
                          java.net.URL[] urls,
                          java.lang.ClassLoader parent,
                          java.net.URLStreamHandlerFactory factory)
Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory for accessing the urls..

Parameters:
name - the name of this class loader
urls - the urls from which this class loader will classes and resources
parent - the parent of this class loader
factory - the URLStreamHandlerFactory used to access the urls

JarFileClassLoader

public JarFileClassLoader(java.lang.String name,
                          java.net.URL[] urls,
                          java.lang.ClassLoader[] parents)
Creates a named class loader as a child of the specified parents.

Parameters:
name - the name of this class loader
urls - the urls from which this class loader will classes and resources
parents - the parents of this class loader

JarFileClassLoader

public JarFileClassLoader(java.lang.String name,
                          java.net.URL[] urls,
                          java.lang.ClassLoader[] parents,
                          java.net.URLStreamHandlerFactory factory)
Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory for accessing the urls..

Parameters:
name - the name of this class loader
urls - the urls from which this class loader will classes and resources
parents - the parents of this class loader
factory - the URLStreamHandlerFactory used to access the urls
Method Detail

getURLs

public java.net.URL[] getURLs()


addURL

protected void addURL(java.net.URL url)


addURLs

protected void addURLs(java.net.URL[] urls)
Adds an array of urls to the end of this class loader.

Parameters:
urls - the URLs to add

addURLs

protected void addURLs(java.util.List urls)
Adds a list of urls to the end of this class loader.

Parameters:
urls - the URLs to add

destroy

public void destroy()
Destroys the clasloader releasing all resources. After this mehtod is called, the class loader will no longer load any classes or resources.

Specified by:
destroy in interface DestroyableClassLoader
Overrides:
destroy in class NamedClassLoader

findResource

public java.net.URL findResource(java.lang.String resourceName)


findResources

public java.util.Enumeration findResources(java.lang.String resourceName)
                                    throws java.io.IOException

Overrides:
findResources in class MultiParentClassLoader
Throws:
java.io.IOException

findClass

protected java.lang.Class findClass(java.lang.String className)
                             throws java.lang.ClassNotFoundException

Throws:
java.lang.ClassNotFoundException


Copyright © {inceptionYear}-2006 Apache Software Foundation. All Rights Reserved.