ij.io
Class PluginClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by ij.io.PluginClassLoader

public class PluginClassLoader
extends java.lang.ClassLoader

ImageJ uses this class loader to load plugins and resources from the plugins directory and immediate subdirectories. This class loader will also load classes and resources from JAR files.

The class loader searches for classes and resources in the following order:

  1. Plugins directory
  2. Subdirectories of the Plugins directory
  3. JAR and ZIP files in the plugins directory and subdirectories

The class loader does not recurse into subdirectories beyond the first level.


Field Summary
protected  java.util.Hashtable cache
           
protected  java.util.Vector jarFiles
           
protected  java.lang.String path
           
 
Constructor Summary
PluginClassLoader(java.lang.String path)
          Creates a new PluginClassLoader that searches in the directory path passed as a parameter.
PluginClassLoader(java.lang.String path, boolean callSuper)
          This version of the constructor is used when ImageJ is launched using Java WebStart.
 
Method Summary
 java.net.URL getResource(java.lang.String name)
          Returns a resource from the path or JAR files as a URL
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Returns a resource from the path or JAR files as an InputStream
 java.lang.Class loadClass(java.lang.String className)
          Returns a Class from the path or JAR files.
 java.lang.Class loadClass(java.lang.String className, boolean resolveIt)
          Returns a Class from the path or JAR files.
protected  byte[] loadClassBytes(java.lang.String name)
          This does the actual work of loading the bytes from the disk.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, 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

path

protected java.lang.String path

cache

protected java.util.Hashtable cache

jarFiles

protected java.util.Vector jarFiles
Constructor Detail

PluginClassLoader

public PluginClassLoader(java.lang.String path)
Creates a new PluginClassLoader that searches in the directory path passed as a parameter. The constructor automatically finds all JAR and ZIP files in the path and first level of subdirectories. The JAR and ZIP files are stored in a Vector for future searches.

Parameters:
path - the path to the plugins directory.

PluginClassLoader

public PluginClassLoader(java.lang.String path,
                         boolean callSuper)
This version of the constructor is used when ImageJ is launched using Java WebStart.

Method Detail

getResource

public java.net.URL getResource(java.lang.String name)
Returns a resource from the path or JAR files as a URL

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - a resource name.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Returns a resource from the path or JAR files as an InputStream

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
name - a resource name.

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Returns a Class from the path or JAR files. Classes are automatically resolved.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className - a class name without the .class extension.
Throws:
java.lang.ClassNotFoundException

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 boolean resolveIt)
                          throws java.lang.ClassNotFoundException
Returns a Class from the path or JAR files. Classes are resolved if resolveIt is true.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className - a String class name without the .class extension. resolveIt a boolean (should almost always be true)
Throws:
java.lang.ClassNotFoundException

loadClassBytes

protected byte[] loadClassBytes(java.lang.String name)
This does the actual work of loading the bytes from the disk. Returns an array of bytes that will be defined as a Class. This should be overloaded to have the Class Loader look in more places.

Parameters:
name - a class name without the .class extension.