Top Description Fields Constructors Methods
org.mortbay.jetty.webapp

public Class WebAppClassLoader

extends URLClassLoader
Class Inheritance
Imports
java.io.File, .FileOutputStream, .IOException, .InputStream, java.net.URL, .URLClassLoader, java.security.CodeSource, .PermissionCollection, java.util.StringTokenizer, org.mortbay.jetty.handler.ContextHandler, org.mortbay.log.Log, org.mortbay.resource.Resource, org.mortbay.util.IO, .LazyList, .StringUtil

ClassLoader for HttpContext. Specializes URLClassLoader with some utility and file mapping methods. This loader defaults to the 2.3 servlet spec behaviour where non system classes are loaded from the classpath in preference to the parent loader. Java2 compliant loading, where the parent loader always has priority, can be selected with the org.mortbay.jetty.webapp.WebAppContext#setParentLoaderPriority(boolean) method and influenced with WebAppContext#isServerClass(String) and WebAppContext#isSystemClass(String). If no parent class loader is provided, then the current thread context classloader will be used. If that is null then the classloader that loaded this class is used as the parent.
Author
Greg Wilkins (gregw)

Field Summary

Modifier and TypeField and Description
private WebAppContext
private String
private ClassLoader

Constructor Summary

AccessConstructor and Description
public
WebAppClassLoader(WebAppContext context)

Constructor.

public
WebAppClassLoader(ClassLoader parent, WebAppContext context)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addClassPath(String
Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
classPath
)

public void
addJars(Resource
the resource that contains the jar and/or zip files.
lib
)

Add elements to the class path for the context from the jar and zip files found in the specified resource.

public void
public ContextHandler
public String

Returns:

the name of the classloader
getName
()

Overrides java.lang.ClassLoader.getName.

Returns the name of this class loader or null if this class loader is not named.
public PermissionCollection
getPermissions(CodeSource
the codesource
cs
)

Overrides java.net.URLClassLoader.getPermissions.

Returns the permissions for the given codesource object.
public synchronized URL
getResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.
public synchronized Class<?>
loadClass(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
protected synchronized Class<?>
loadClass(String
The binary name of the class
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
public void
setName(String
the name of the classloader
name
)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.net.URLClassLoader:
addURLclosedefinePackagefindClassfindResourcefindResourcesgetResourceAsStreamgetURLsnewInstancenewInstance

Field Detail

_contextback to summary
private WebAppContext _context
_nameback to summary
private String _name
_parentback to summary
private ClassLoader _parent

Constructor Detail

WebAppClassLoaderback to summary
public WebAppClassLoader(WebAppContext context) throws IOException

Constructor.

WebAppClassLoaderback to summary
public WebAppClassLoader(ClassLoader parent, WebAppContext context) throws IOException

Constructor.

Method Detail

addClassPathback to summary
public void addClassPath(String classPath) throws IOException
Parameters
classPath:String

Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.

addJarsback to summary
public void addJars(Resource lib)

Add elements to the class path for the context from the jar and zip files found in the specified resource.

Parameters
lib:Resource

the resource that contains the jar and/or zip files.

See Also
setClassPath(String)
destroyback to summary
public void destroy()
getContextback to summary
public ContextHandler getContext()
getNameback to summary
public String getName()

Overrides java.lang.ClassLoader.getName.

Doc from java.lang.ClassLoader.getName.

Returns the name of this class loader or null if this class loader is not named.

Returns:String

the name of the classloader

getPermissionsback to summary
public PermissionCollection getPermissions(CodeSource cs)

Overrides java.net.URLClassLoader.getPermissions.

Doc from java.net.URLClassLoader.getPermissions.

Returns the permissions for the given codesource object. The implementation of this method first calls super.getPermissions and then adds permissions based on the URL of the codesource.

If the protocol of this URL is "jar", then the permission granted is based on the permission that is required by the URL of the Jar file.

If the protocol is "file" and there is an authority component, then permission to connect to and accept connections from that authority may be granted. If the protocol is "file" and the path specifies a file, then permission to read that file is granted. If protocol is "file" and the path is a directory, permission is granted to read all files and (recursively) all files and subdirectories contained in that directory.

If the protocol is not "file", then permission to connect to and accept connections from the URL's host is granted.

Parameters
cs:CodeSource

the codesource

Returns:PermissionCollection

the permissions granted to the codesource

getResourceback to summary
public synchronized URL getResource(String name)

Overrides java.lang.ClassLoader.getResource.

Doc from java.lang.ClassLoader.getResource.

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name that identifies the resource.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
name:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

loadClassback to summary
public synchronized Class<?> loadClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Doc from java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name, false).

Parameters
name:String

The binary name of the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class was not found
loadClassback to summary
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Doc from java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:

  1. Invoke findLoadedClass(String) to check if the class has already been loaded.

  2. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built into the virtual machine is used, instead.

  3. Invoke the findClass(String) method to find the class.

If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(Class) method on the resulting Class object.

Subclasses of ClassLoader are encouraged to override findClass(String), rather than this method.

Unless overridden, this method synchronizes on the result of getClassLoadingLock method during the entire class loading process.

Parameters
name:String

The binary name of the class

resolve:boolean

If true then resolve the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
setNameback to summary
public void setName(String name)
Parameters
name:String

the name of the classloader

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.