qflib 0.99

de.qfs.lib.util
Class ArchiveClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byde.qfs.lib.util.ArchiveClassLoader

public class ArchiveClassLoader
extends java.lang.ClassLoader

An ArchiveClassLoader loads classes from a single source, a ZipFile or a directory. Referenced classes will be loaded from the source, if possible, or loaded via the system ClassLoader otherwise.

Author:
Gregor Schmid

Field Summary
protected  java.util.Hashtable classes
          Cache for loaded classes.
protected  java.io.File dir
          The directory holding the classes.
protected  java.util.zip.ZipFile zip
          The ZipFile holding the classes.
 
Constructor Summary
ArchiveClassLoader(java.io.File dir)
          Create a new ArchiveClassLoader that loads classes from a directory.
ArchiveClassLoader(java.util.zip.ZipFile zip)
          Create a new ArchiveClassLoader that loads classes from a ZipFile.
 
Method Summary
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Find a resource in the classpath and open a stream for it.
 java.lang.Class loadClass(java.lang.String name)
          Load and resolve a class.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load a class and maybe resolve it.
 java.lang.Class loadSystemClass(java.lang.String name)
          Load and resolve a class via the default class loader.
protected  java.lang.Class makeSystemClass(java.lang.String name, boolean resolve)
          Get a system class and maybe resolve it.
 void restrict(java.lang.String pkg)
          Add a package restriction to the class loader.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, 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

classes

protected java.util.Hashtable classes
Cache for loaded classes.


zip

protected java.util.zip.ZipFile zip
The ZipFile holding the classes.


dir

protected java.io.File dir
The directory holding the classes.

Constructor Detail

ArchiveClassLoader

public ArchiveClassLoader(java.util.zip.ZipFile zip)
Create a new ArchiveClassLoader that loads classes from a ZipFile.

Parameters:
zip - The ZipFile to read the classes from.

ArchiveClassLoader

public ArchiveClassLoader(java.io.File dir)
Create a new ArchiveClassLoader that loads classes from a directory.

Parameters:
dir - The directory to read the classes from.
Method Detail

restrict

public void restrict(java.lang.String pkg)
Add a package restriction to the class loader.

Parameters:
pkg - The package to restrict to. If the package ends in a '.', sub-packages are included.
Since:
0.99.0

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Load and resolve a class.

Parameters:
name - The class' name.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If no such class exists or some IO problem occurs.

loadSystemClass

public java.lang.Class loadSystemClass(java.lang.String name)
                                throws java.lang.ClassNotFoundException
Load and resolve a class via the default class loader. This method can be useful to allow an instance of a class loaded by this class loader to break out of the archive and access system classes.

Parameters:
name - The class' name.
Returns:
The loaded system class.
Throws:
java.lang.ClassNotFoundException - If no such class exists or some IO problem occurs.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Find a resource in the classpath and open a stream for it.

Parameters:
name - The name of the resource.
Returns:
The stream.

loadClass

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

Parameters:
name - The class' name.
resolve - Whether to resolve the class.
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - If no such class exists or some IO problem occurs.

makeSystemClass

protected java.lang.Class makeSystemClass(java.lang.String name,
                                          boolean resolve)
                                   throws java.lang.ClassNotFoundException
Get a system class and maybe resolve it.

Parameters:
name - The class' name.
resolve - Whether to resolve the class.
Returns:
The system class found.
Throws:
java.lang.ClassNotFoundException - If no such class exists or some IO problem occurs.

qflib 0.99