org.merlotxml.merlot.plugin
Class PluginClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byorg.merlotxml.merlot.plugin.PluginClassLoader

public class PluginClassLoader
extends java.lang.ClassLoader

This classloader loads plugin classes and resources from merlot plugin jar files or plugin development directories.

When loading a class or a resource from a jar file, it first looks in the jar directly (as the normal class loader does), then it checks the classes directory, and lastly, it checks for embedded jar files located in a lib directory within the plugin jar file.

To load classes and resource from embedded jar files, the PluginClassLoader must write out jars in the lib directory to a temporary location to be used by ZipFile.

Author:
Kelly Campbell, Tim McCune

Constructor Summary
PluginClassLoader(java.io.File source)
          Creates a new PluginClassLoader from a the specified directory or jar file
 
Method Summary
protected  void copyEmbeddedZipFiles(java.util.zip.ZipFile zip)
          Writes out embedded zips to temp files
protected  java.lang.Class findClass(java.lang.String name)
           
protected  java.lang.String findLibrary(java.lang.String libname)
           
protected  java.lang.String findLibraryInDependencies(java.lang.String libname)
           
 java.net.URL findResource(java.lang.String name)
          Generates an URL class of the resource in a jar file or directory.
protected  java.net.URL findResourceInClasses(java.lang.Object dirzip, java.lang.String name)
          Finds resources in classes directory
protected  java.net.URL findResourceInDependencies(java.lang.String name)
           
protected  java.net.URL findResourceInLib(java.lang.Object dirzip, java.lang.String name)
          Finds resources in lib/zip files
protected  java.net.URL findResourceInRoot(java.lang.Object dirzip, java.lang.String name)
          Finds resources in jar or directory root
protected  java.net.URL findResourceInZip(java.io.File file, java.lang.String name)
          This finds a resource and returns a stream of it from a zip file
 void setSource(java.io.File source)
          Sets this loader's source to the given directory or jar file.
protected  java.io.File unpackZipFile(java.io.File f)
          Unpacks a plugin file where the plugin is located
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, 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

PluginClassLoader

public PluginClassLoader(java.io.File source)
Creates a new PluginClassLoader from a the specified directory or jar file

Parameters:
source - the plugin jar file or directory
See Also:
setSource(File)
Method Detail

setSource

public void setSource(java.io.File source)
               throws java.lang.IllegalArgumentException
Sets this loader's source to the given directory or jar file.

Parameters:
source - a directory containing the plugin.xml, dtd, and classes for a plugin, or a jar file containing the same contents.
Throws:
java.lang.IllegalArgumentException - if the source is not a directory or readable Jar file

findResource

public java.net.URL findResource(java.lang.String name)
Generates an URL class of the resource in a jar file or directory. Example:

   <path>.<to>.<some>.<class>.<NameOfClass>.class.getResource(<resourceName>);
 
will pass as a parameter 'name' this string value:
 <path>/<to>/<some>/<class>/<resourceName>
 
This value is used as an end of the URL. The begining depends on the source of the classes (if we use a JAR file or a directory).

Parameters:
name - Name of the resource as is passed from the standard getResource method. It is a full class name with all '.' replaced by '/'.
Returns:
URL Resource URL class or null if no _sourcezip or _sourcedir is specified.

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

findResourceInZip

protected java.net.URL findResourceInZip(java.io.File file,
                                         java.lang.String name)
This finds a resource and returns a stream of it from a zip file


copyEmbeddedZipFiles

protected void copyEmbeddedZipFiles(java.util.zip.ZipFile zip)
Writes out embedded zips to temp files


unpackZipFile

protected java.io.File unpackZipFile(java.io.File f)
                              throws java.io.IOException
Unpacks a plugin file where the plugin is located

Returns:
the directory it unpacked into or null
Throws:
java.io.IOException

findResourceInLib

protected java.net.URL findResourceInLib(java.lang.Object dirzip,
                                         java.lang.String name)
Finds resources in lib/zip files


findResourceInClasses

protected java.net.URL findResourceInClasses(java.lang.Object dirzip,
                                             java.lang.String name)
Finds resources in classes directory


findResourceInRoot

protected java.net.URL findResourceInRoot(java.lang.Object dirzip,
                                          java.lang.String name)
Finds resources in jar or directory root


findResourceInDependencies

protected java.net.URL findResourceInDependencies(java.lang.String name)

findLibrary

protected java.lang.String findLibrary(java.lang.String libname)

findLibraryInDependencies

protected java.lang.String findLibraryInDependencies(java.lang.String libname)