dsto.dfc.util.plugins
Class DfcClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by dsto.dfc.util.plugins.DfcClassLoader

public class DfcClassLoader
extends ClassLoader

A class loader that supports dynamic addition to the classpath, including JAR/ZIP files and directories. To avoid various problems, it does not load any class files that are considered to be part of the system (ie java.*, javax.* etc).

When the DfcClassLoader is first started, it scans the system class path, and adds all of the paths into its own search path.

NOTE that this loader does not currently respect the order in which items are added to the classpath, so if the same class is in several locations which one gets loaded is not defined.

Version:
$Revision$
See Also:
BootStrapLoader

Field Summary
static DfcClassLoader INSTANCE
           
 
Constructor Summary
protected DfcClassLoader()
          Constructor is protected so as to make it a singleton.
 
Method Summary
 void addJarFile(String jarFilePath)
          Adds a path to a jar file to the end of the search path.
 void addPath(String dirPath)
          addPath adds a directory path to the search path.
 void addZipFile(String zipFilePath)
          Adds a path to a zip file to the end of the search path.
protected  Class findClass(String name)
          Look for a class in the defined Jar files, Zip files and directories.
protected  URL findResource(String name)
          Finds the resource with the given name.
 Class loadClass(String name)
          Loads the class with the specified name.
 Class loadClass(String name, boolean resolve)
          Loads the class with the specified name.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, 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

INSTANCE

public static final DfcClassLoader INSTANCE
Constructor Detail

DfcClassLoader

protected DfcClassLoader()
Constructor is protected so as to make it a singleton. Use DfcClassLoader.INSTANCE.

Method Detail

addJarFile

public void addJarFile(String jarFilePath)
Adds a path to a jar file to the end of the search path.

Parameters:
jarFilePath - The path to the Jar file that you want added to the classloader path.

addZipFile

public void addZipFile(String zipFilePath)
Adds a path to a zip file to the end of the search path.

Parameters:
zipFilePath - The path to the Zip file that you want added to the classloader path.

addPath

public void addPath(String dirPath)
addPath adds a directory path to the search path. The path is added to the end of the search path.

Parameters:
dirPath - The path to the directory that you want added to the classloader path.

loadClass

public Class loadClass(String name)
                throws ClassNotFoundException
Loads the class with the specified name. This method searches for classes in the same manner as the loadClass(String, boolean) method. Calling this method is equivalent to calling loadClass(name, false)

Overrides:
loadClass in class ClassLoader
Parameters:
name - The name of the class to try to load.
Throws:
ClassNotFoundException

loadClass

public Class loadClass(String name,
                       boolean resolve)
                throws ClassNotFoundException
Loads the class with the specified name. The default implementation of this method searches for classes in the following order: 1 Call findLoadedClass(String) to check if the class has already been loaded. 2 Call the findClass(String) method to find the class. 3 Call the loadClass method on the parent class loader. If that can't find the class then you have a problem, b'cos it means that it is no-where to be found. If the class was found using the above steps, and the resolve flag is true, this method will then call the resolveClass(Class) method on the resulting class object.

Overrides:
loadClass in class ClassLoader
Parameters:
name - The name of the class to try to load.
resolve - Flag set if you would like the class loader to attempt to resolve the class.
Throws:
ClassNotFoundException - Thrown if the class couldn't be found.

findClass

protected Class findClass(String name)
                   throws ClassNotFoundException
Look for a class in the defined Jar files, Zip files and directories.

Overrides:
findClass in class ClassLoader
Parameters:
name - The name of the class to load.
Throws:
ClassNotFoundException - if the class couldn't be found.

findResource

protected URL findResource(String name)
Finds the resource with the given name. Ssearches jar files, zip files, and then directories in that order.

Overrides:
findResource in class ClassLoader
Parameters:
name - The name of the resource.
Returns:
a URL for reading the resource, or null if the resource couldn't be found.


Copyright © 2008 Commonwealth of Australia