org.sadun.util
Class DynamicClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byorg.sadun.util.DynamicClassLoader

public class DynamicClassLoader
extends java.lang.ClassLoader

A classloader whose classpath can be set dynamically.

Version 1.2 adds resource support capability, but for the findResources() which is not implemented.

By default, the classLoader attempts to use the parent class loader, if any, to find a class. By setting the forceDynamicLoading property, the classLoader will always find classes by using the embedded DynamicClassFileFinder. $Revision$

Version:
1.3
Author:
cris

Constructor Summary
DynamicClassLoader()
          Constructor for DynamicClassLoader.
DynamicClassLoader(java.lang.ClassLoader arg0)
           
DynamicClassLoader(java.lang.ClassLoader arg0, DynamicClassFileFinder cff, DynamicResourceFileFinder rff)
          Constructor for DynamicClassLoader.
DynamicClassLoader(DynamicClassFileFinder cff, DynamicResourceFileFinder rff)
          Constructor for DynamicClassLoader.
 
Method Summary
 void addClassPathEntry(java.lang.String entry)
          Add a class path entry
protected  java.lang.Class findClass(java.lang.String arg0)
           
protected  java.lang.String findLibrary(java.lang.String libname)
          Looks for a library in classpath and load it if found.
protected  java.net.URL findResource(java.lang.String name)
           
protected  java.util.Enumeration findResources(java.lang.String name)
           
 DynamicClassFileFinder getClassFileFinder()
           
 java.lang.String getClassPath()
          Returnt the current class path
 java.io.InputStream getResourceAsStream(java.lang.String name)
           
 DynamicResourceFileFinder getResourceFileFinder()
           
 boolean isForceDynamicLoading()
          Returns the forceDynamicLoading.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
static void main(java.lang.String[] args)
           
 void setClassPath(java.lang.String classPath)
          Set the class path
 void setForceDynamicLoading(boolean forceDynamicLoading)
          Sets the forceDynamicLoading.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, 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
 

Constructor Detail

DynamicClassLoader

public DynamicClassLoader(java.lang.ClassLoader arg0,
                          DynamicClassFileFinder cff,
                          DynamicResourceFileFinder rff)
Constructor for DynamicClassLoader.

Parameters:
arg0 -

DynamicClassLoader

public DynamicClassLoader(DynamicClassFileFinder cff,
                          DynamicResourceFileFinder rff)
Constructor for DynamicClassLoader.


DynamicClassLoader

public DynamicClassLoader(java.lang.ClassLoader arg0)

DynamicClassLoader

public DynamicClassLoader()
Constructor for DynamicClassLoader.

Method Detail

getClassFileFinder

public DynamicClassFileFinder getClassFileFinder()

getResourceFileFinder

public DynamicResourceFileFinder getResourceFileFinder()

addClassPathEntry

public void addClassPathEntry(java.lang.String entry)
Add a class path entry. * @param entry


setClassPath

public void setClassPath(java.lang.String classPath)
Set the class path. * @param classPath


getClassPath

public java.lang.String getClassPath()
Returnt the current class path

Returns:
the current class path

main

public static void main(java.lang.String[] args)

findClass

protected java.lang.Class findClass(java.lang.String arg0)
                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException
See Also:
ClassLoader.findClass(java.lang.String)

findResource

protected java.net.URL findResource(java.lang.String name)
See Also:
ClassLoader.findResource(java.lang.String)

findResources

protected java.util.Enumeration findResources(java.lang.String name)
                                       throws java.io.IOException
Throws:
java.io.IOException
See Also:
ClassLoader.findResources(java.lang.String)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
See Also:
ClassLoader.getResourceAsStream(java.lang.String)

isForceDynamicLoading

public boolean isForceDynamicLoading()
Returns the forceDynamicLoading.

Returns:
boolean

setForceDynamicLoading

public void setForceDynamicLoading(boolean forceDynamicLoading)
Sets the forceDynamicLoading.

Parameters:
forceDynamicLoading - The forceDynamicLoading to set

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException
See Also:
ClassLoader.loadClass(java.lang.String, boolean)

findLibrary

protected java.lang.String findLibrary(java.lang.String libname)
Looks for a library in classpath and load it if found.

See Also:
ClassLoader.findLibrary(java.lang.String)