org.codehaus.classworlds
Class UberJarRealmClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.codehaus.classworlds.RealmClassLoader
                  extended byorg.codehaus.classworlds.UberJarRealmClassLoader

class UberJarRealmClassLoader
extends RealmClassLoader

Classloader for ClassRealms. Loads classes from an "uberjar".

Version:
$Id: UberJarRealmClassLoader.java,v 1.2 2003/09/23 14:09:46 jvanzyl Exp $
Author:
bob mcwhirter

Nested Class Summary
 
Nested classes inherited from class java.lang.ClassLoader
 
Field Summary
private  java.util.Map classIndex
          Classes, indexed by path.
private  java.util.Map jarIndexes
          Indexes for constituent jars.
protected  DefaultClassRealm realm
          The realm.
private  java.util.List urls
          Urls.
 
Fields inherited from class java.net.URLClassLoader
 
Fields inherited from class java.security.SecureClassLoader
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
(package private) UberJarRealmClassLoader(DefaultClassRealm realm)
          Construct.
 
Method Summary
(package private)  void addConstituent(java.net.URL constituent)
          Add a constituent to this realm for locating classes.
private  void buildIndexForJar(java.net.URL inUrl)
          Builds an index for an incoming jar.
protected  byte[] findClassInDirectoryUrl(java.net.URL url, java.lang.String path)
          Attempt to load the bytes of a class from a directory URL.
protected  byte[] findClassInJarStream(java.net.URL inUrl, java.lang.String path)
          Attempt to load the bytes of a class from a JAR URL.
 java.net.URL findResource(java.lang.String name)
           
protected  java.net.URL findResourceInDirectoryUrl(java.net.URL inUrl, java.lang.String path)
          Find a resource that potentially exists within a directory.
protected  java.net.URL findResourceInJarStream(java.net.URL inUrl, java.lang.String path)
          Find a resource that potentially exists within a JAR stream.
(package private)  DefaultClassRealm getRealm()
          Retrieve the realm.
 java.net.URL getResource(java.lang.String name)
           
 java.net.URL[] getURLs()
          Retrieve the URLs used by this ClassLoader.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load a class.
(package private)  java.lang.Class loadClassDirect(java.lang.String className)
          Load a class directly from this classloader without defering through any other ClassRealm.
private  byte[] readStream(java.io.InputStream in)
          Read the contents of the provided input stream and return the contents as a byte array.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResources, 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, toString, wait, wait, wait
 

Field Detail

classIndex

private java.util.Map classIndex
Classes, indexed by path.


urls

private java.util.List urls
Urls.


jarIndexes

private java.util.Map jarIndexes
Indexes for constituent jars. Contains a Map for each constituent which is a jar, keyed by url. The second map contains urls to each entry of the jar keyed by path.


realm

protected DefaultClassRealm realm
The realm.

Constructor Detail

UberJarRealmClassLoader

UberJarRealmClassLoader(DefaultClassRealm realm)
Construct.

Parameters:
realm - The realm for which this loads.
Method Detail

getRealm

DefaultClassRealm getRealm()
Retrieve the realm.

Overrides:
getRealm in class RealmClassLoader
Returns:
The realm.

addConstituent

void addConstituent(java.net.URL constituent)
Add a constituent to this realm for locating classes.

Overrides:
addConstituent in class RealmClassLoader
Parameters:
constituent - URL to contituent jar or directory.

buildIndexForJar

private void buildIndexForJar(java.net.URL inUrl)
Builds an index for an incoming jar.

Parameters:
inUrl -

loadClassDirect

java.lang.Class loadClassDirect(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Load a class directly from this classloader without defering through any other ClassRealm.

Overrides:
loadClassDirect in class RealmClassLoader
Parameters:
className - The name of the class to load.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If the class could not be found.

getResource

public java.net.URL getResource(java.lang.String name)
See Also:
ClassLoader

findResource

public java.net.URL findResource(java.lang.String name)
Overrides:
findResource in class RealmClassLoader
See Also:
ClassLoader

findResourceInJarStream

protected java.net.URL findResourceInJarStream(java.net.URL inUrl,
                                               java.lang.String path)
Find a resource that potentially exists within a JAR stream.

Parameters:
inUrl - The jar stream URL.
path - The resource path to find.
Returns:
The resource URL or null if none found.

findResourceInDirectoryUrl

protected java.net.URL findResourceInDirectoryUrl(java.net.URL inUrl,
                                                  java.lang.String path)
Find a resource that potentially exists within a directory.

Parameters:
inUrl - The directory URL.
path - The resource path to find.
Returns:
The resource URL or null if none found.

findClassInJarStream

protected byte[] findClassInJarStream(java.net.URL inUrl,
                                      java.lang.String path)
Attempt to load the bytes of a class from a JAR URL.

Parameters:
inUrl - The base url.
path - The path to the desired class.
Returns:
The class bytes or null if not available via the base url.

findClassInDirectoryUrl

protected byte[] findClassInDirectoryUrl(java.net.URL url,
                                         java.lang.String path)
Attempt to load the bytes of a class from a directory URL.

Parameters:
url - The directory url.
path - The path to the desired class.
Returns:
The class bytes or null if not available via the base url.

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Load a class.

Overrides:
loadClass in class RealmClassLoader
Parameters:
name - The name of the class to load.
resolve - If true then resolve the class.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If the class cannot be found.

readStream

private byte[] readStream(java.io.InputStream in)
                   throws java.io.IOException
Read the contents of the provided input stream and return the contents as a byte array.

Throws:
java.io.IOException

getURLs

public java.net.URL[] getURLs()
Retrieve the URLs used by this ClassLoader.

Returns:
The urls.