org.codehaus.classworlds
Class UberJarRealmClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--org.codehaus.classworlds.RealmClassLoader
                          |
                          +--org.codehaus.classworlds.UberJarRealmClassLoader

public class UberJarRealmClassLoader
extends RealmClassLoader

Classloader for ClassRealms.

Loads classes from an "uberjar".

Version:
$Id: UberJarRealmClassLoader.java,v 1.1 2004/07/06 17:37:36 dandiep Exp $
Author:
bob mcwhirter

Field Summary
protected  DefaultClassRealm realm
          The realm.
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
UberJarRealmClassLoader(DefaultClassRealm realm)
           
 
Method Summary
 void addConstituent(java.net.URL constituent)
          Add a constituent to this realm for locating classes.
protected  byte[] findClassInDirectoryUrl(java.net.URL url, java.lang.String path)
           
protected  byte[] findClassInJarStream(java.net.URL inUrl, java.lang.String path)
           
 java.net.URL findResource(java.lang.String name)
          Find a resource within this ClassLoader only (don't delegate to the parent).
protected  java.net.URL findResourceInDirectoryUrl(java.net.URL inUrl, java.lang.String path)
           
protected  java.net.URL findResourceInJarStream(java.net.URL inUrl, java.lang.String path)
           
 java.util.Enumeration findResources(java.lang.String name)
           
 java.util.Enumeration findResourcesDirect(java.lang.String name)
          Find resources from this ClassLoader, and don't search the realm.
 java.util.Enumeration findResourcesFromClassLoader(java.lang.String name)
           
 byte[] getBytesToEndOfStream(java.io.DataInputStream in)
          Helper method for addConstituent that reads in a DataInputStream and returns it as a byte[] It attempts to use in.available - the size of the file - else defaults to 2048
(package private)  DefaultClassRealm getRealm()
          Retrieve the realm.
 java.net.URL getResource(java.lang.String name)
           
 java.net.URL getResourceDirect(java.lang.String name)
          Get a resource from this ClassLoader, and don't search the realm.
 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.
 java.lang.Class loadClassDirect(java.lang.String className)
          Load a class directly from this classloader without defering through any other ClassRealm.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, 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

realm

protected DefaultClassRealm realm
The realm.

Constructor Detail

UberJarRealmClassLoader

public UberJarRealmClassLoader(DefaultClassRealm realm)
Method Detail

addConstituent

public void addConstituent(java.net.URL constituent)
Description copied from class: RealmClassLoader
Add a constituent to this realm for locating classes. If the url definition ends in .class its a BytesURLStreamHandler so use defineClass insead. addURL is still called for byte[] even though it has no affect and we use defineClass instead, this is for consistentency and to allow access to the class with getURLs()

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

loadClassDirect

public 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.

findResource

public java.net.URL findResource(java.lang.String name)
Description copied from class: RealmClassLoader
Find a resource within this ClassLoader only (don't delegate to the parent).

Overrides:
findResource in class RealmClassLoader
Returns:
The resource.

findResourcesFromClassLoader

public java.util.Enumeration findResourcesFromClassLoader(java.lang.String name)

findResourceInJarStream

protected java.net.URL findResourceInJarStream(java.net.URL inUrl,
                                               java.lang.String path)

findResourceInDirectoryUrl

protected java.net.URL findResourceInDirectoryUrl(java.net.URL inUrl,
                                                  java.lang.String path)

findClassInJarStream

protected byte[] findClassInJarStream(java.net.URL inUrl,
                                      java.lang.String path)

findClassInDirectoryUrl

protected byte[] findClassInDirectoryUrl(java.net.URL url,
                                         java.lang.String path)

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Description copied from class: RealmClassLoader
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.

getRealm

DefaultClassRealm getRealm()
Retrieve the realm.

Returns:
The realm.

getBytesToEndOfStream

public byte[] getBytesToEndOfStream(java.io.DataInputStream in)
                             throws java.io.IOException
Helper method for addConstituent that reads in a DataInputStream and returns it as a byte[] It attempts to use in.available - the size of the file - else defaults to 2048

java.io.IOException

getURLs

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

Overrides:
getURLs in class java.net.URLClassLoader
Returns:
The urls.

getResource

public java.net.URL getResource(java.lang.String name)
Overrides:
getResource in class java.lang.ClassLoader

getResourceDirect

public java.net.URL getResourceDirect(java.lang.String name)
Get a resource from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.

Returns:
The resource.

findResources

public java.util.Enumeration findResources(java.lang.String name)
                                    throws java.io.IOException
Overrides:
findResources in class java.net.URLClassLoader
java.io.IOException

findResourcesDirect

public java.util.Enumeration findResourcesDirect(java.lang.String name)
                                          throws java.io.IOException
Find resources from this ClassLoader, and don't search the realm. Otherwise we'd recurse indefinitely.

Returns:
The resource.
java.io.IOException


Copyright © 2002-2004 The Codehaus. All Rights Reserved.