com.objectwave.customClassLoader
Class MultiClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.objectwave.customClassLoader.MultiClassLoader
Direct Known Subclasses:
FileClassLoader, SocketClassLoader, TraceClassLoader, URLClassLoader

public abstract class MultiClassLoader
extends java.lang.ClassLoader

A simple test class loader capable of loading from multiple sources, such as local files or a URL. Must be subclassed and the abstract method loadClassBytes() implemented to provide the preferred source. This class is derived from an article by Chuck McManis http://www.javaworld.com/javaworld/jw-10-1996/indepth.src.html with large modifications. This class is derived from an article by Jack Harich - 8/18/97

Version:
$Id: MultiClassLoader.java,v 2.0 2001/06/11 15:54:25 dave_hoag Exp $
Author:
Dave Hoag - 3/2/98

Field Summary
protected  boolean loadLocalClasses
           
 boolean monitorOn
           
protected  boolean sourceMonitorOn
           
 
Constructor Summary
MultiClassLoader()
          Register ourselves with the CclpURLConnection so that we can handle all system resource requests as well as class requests.
 
Method Summary
 java.lang.Class findClass(java.lang.String str)
           
protected  java.lang.String formatClassName(java.lang.String className)
           
abstract  java.lang.Object getContent(java.net.URL url)
          Every custom class loader will need to be able to get the content from a modified URL.
abstract  java.io.InputStream getInputStream(java.net.URL url)
          Every custom class loader will need to be able to get the input stream from a modified URL.
 java.net.URL getResource(java.lang.String name)
          This looks locally for the resource fist, then it returns our own CCLP url to retrieve this resource.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Return the resource as a stream.
 void initPathInformation()
          Create the jar readers.
 java.lang.Class loadClass(java.lang.String className)
          This is a simple version for external clients since they will always want the class resolved before it is returned to them.
 java.lang.Class loadClass(java.lang.String className, boolean resolveIt)
          This method is called from the VM.
protected abstract  byte[] loadClassBytes(java.lang.String className)
          Must be implmented by subclass.
protected  byte[] loadLocalClassBytes(java.lang.String fullClassName)
          Similar to findSystemClass but the newly defined class will have this as the ClassLoader.
 java.io.InputStream locateClass(java.lang.String fullClassName)
          Find the request .class bytes for the provided classname.
protected  java.lang.Class lookForPreviousDefinitions(java.lang.String className)
           
static void main(java.lang.String[] args)
          Test method.
protected  void monitor(java.lang.String text)
           
protected static void print(java.lang.String text)
           
 void setClassNameReplacementChar(char replacement)
          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.
protected  boolean useLocalLoader(java.lang.String className)
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, 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

monitorOn

public boolean monitorOn

sourceMonitorOn

protected boolean sourceMonitorOn

loadLocalClasses

protected boolean loadLocalClasses
Constructor Detail

MultiClassLoader

public MultiClassLoader()
Register ourselves with the CclpURLConnection so that we can handle all system resource requests as well as class requests.

Method Detail

main

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

Parameters:
args - The command line arguments

print

protected static void print(java.lang.String text)
Parameters:
text -

setClassNameReplacementChar

public void setClassNameReplacementChar(char replacement)
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 - The new ClassNameReplacementChar value

getContent

public abstract java.lang.Object getContent(java.net.URL url)
                                     throws java.io.IOException
Every custom class loader will need to be able to get the content from a modified URL. This URL will have the protocol of CCLP

Parameters:
url -
Returns:
The Content value
Throws:
java.io.IOException

getInputStream

public abstract java.io.InputStream getInputStream(java.net.URL url)
                                            throws java.io.IOException
Every custom class loader will need to be able to get the input stream from a modified URL. This URL will have the protocol of CCLP

Parameters:
url -
Returns:
The InputStream value
Throws:
java.io.IOException

getResource

public java.net.URL getResource(java.lang.String name)
This looks locally for the resource fist, then it returns our own CCLP url to retrieve this resource.

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name -
Returns:
The Resource value

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Return the resource as a stream. First try to get the resource from the local system, then try to get the resource from the network.

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
name -
Returns:
The ResourceAsStream value

locateClass

public java.io.InputStream locateClass(java.lang.String fullClassName)
Find the request .class bytes for the provided classname.

Parameters:
fullClassName -
Returns:

initPathInformation

public void initPathInformation()
Create the jar readers. Ignore system jars as specified in the skip variable. This can be 'rerun' to change the path information. It will look at the system property "java.class.path" for the class path.


loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
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 -
Returns:
Throws:
java.lang.ClassNotFoundException

lookForPreviousDefinitions

protected java.lang.Class lookForPreviousDefinitions(java.lang.String className)

findClass

public java.lang.Class findClass(java.lang.String str)
                          throws java.lang.ClassNotFoundException
Overrides:
findClass in class java.lang.ClassLoader
java.lang.ClassNotFoundException

useLocalLoader

protected boolean useLocalLoader(java.lang.String className)

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 boolean resolveIt)
                          throws java.lang.ClassNotFoundException
This method is called from the VM.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className -
resolveIt -
Returns:
Throws:
java.lang.ClassNotFoundException

formatClassName

protected java.lang.String formatClassName(java.lang.String className)
Parameters:
className -
Returns:

loadClassBytes

protected abstract byte[] loadClassBytes(java.lang.String className)
Must be implmented by subclass. Use whatever means necesssary to return a byte[]. This is the only method needs to be implemented in most cases.

Parameters:
className -
Returns:

loadLocalClassBytes

protected byte[] loadLocalClassBytes(java.lang.String fullClassName)
Similar to findSystemClass but the newly defined class will have this as the ClassLoader. This is important if we have cached some classes on the local machine. These classes may not be 'public' and would not be accessible to a class in the same package but loaded via a different class loader.

Parameters:
fullClassName -
Returns:

monitor

protected void monitor(java.lang.String text)
Parameters:
text -