MAEPlugin
Class JarClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--MAEPlugin.JarClassLoader

public class JarClassLoader
extends java.lang.ClassLoader

JarClassLoader provides a minimalistic ClassLoader which shows how to instantiate a class which resides in a .jar file.

This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The MAExplorer Mozilla and Legal files are available on http://maexplorer.sourceforge.net/.

Version:
1.0
Author:
John D. Mitchell, Non, Inc., Mar 3, 1999, Jai Evans 2002
See Also:
MAExplorer Home

Constructor Summary
JarClassLoader(java.io.File jarFile)
          JarClassLoader() - constructor2 that loads jar from the path that is derived from the jarFile.
JarClassLoader(java.lang.String jarPath)
          JarClassLoader() - default constructor that loads jar from the jarPath.
 
Method Summary
protected  java.lang.String formatClassName(java.lang.String className)
          formatClassName() - generate a name with ".class" extension
 JarResources getJarResources()
           
 java.lang.Class loadClass(java.lang.String className)
          loadClass() - load specified class and let it resolve the class if necessary.
 java.lang.Class loadClass(java.lang.String className, boolean resolveIt)
          loadClass() - load specified class
protected  byte[] loadClassBytes(java.lang.String className)
          loadClassBytes() loads bytes for class files.
 void setClassNameReplacementChar(char replacement)
          setClassNameReplacementChar() - remap class name.
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarClassLoader

public JarClassLoader(java.lang.String jarPath)
JarClassLoader() - default constructor that loads jar from the jarPath.
Parameters:
jarPath - is the path of the Jar file

JarClassLoader

public JarClassLoader(java.io.File jarFile)
JarClassLoader() - constructor2 that loads jar from the path that is derived from the jarFile. [constructor 2]
Parameters:
jarFile - is the Jar file.
Method Detail

loadClassBytes

protected byte[] loadClassBytes(java.lang.String className)
loadClassBytes() loads bytes for class files. Note: the class may be buried inside of a directory E.g. Plugins/className, so we need to test that first.
Parameters:
className - of class to load bytes from
Returns:
byte array of data from the class

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
loadClass() - load specified class and let it resolve the class if necessary. This is a simple version for external clients since they will always want the class resolved before it is returned to them.
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className - name of the class to load
Returns:
class that was loaded or null if error
Throws:
java.lang.ClassNotFoundException -  

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 boolean resolveIt)
                          throws java.lang.ClassNotFoundException
loadClass() - load specified class
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className - name of the class to load
resolveIt - lets it resolve the class if necessary
Returns:
class that was loaded or null if error
Throws:
java.lang.ClassNotFoundException -  

setClassNameReplacementChar

public void setClassNameReplacementChar(char replacement)
setClassNameReplacementChar() - remap class name. This optional call allows a class name such as "COM.test.Hello" to be changed to "COM_test_Hello", which is useful for storing classes from different packages in the same retrival directory. In the above example the char would be '_'.
Parameters:
replacement - character to assign.

formatClassName

protected java.lang.String formatClassName(java.lang.String className)
formatClassName() - generate a name with ".class" extension
Parameters:
className - class name
Returns:
formated class name

getJarResources

public JarResources getJarResources()