java.lang
Class ClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
Direct Known Subclasses:
mClassLoader

public abstract class ClassLoader
extends Object

A ClassLoader is used to load and link classes which would not be loaded by the system (bootstrap loader).

The only method you should override is loadClass(String name,boolean resolve) This method should do the following:

  • First call Reflect.getForName(String name) to see if it is a system loadable class. If it is it should return that value. Otherwise it should catch the exception.
  • Second see if it has already loaded that class (by checking some kind of cache of previously loaded classes).
  • Then it should attempt to locate the bytes for the class definition. If it could not then it should throw a ClassNotFoundException.
  • If it finds the bytes it should call defineClass(String className,byte [] bytes,int offset,int length). This will define the class within the VM.
  • If the "resolve" parameter is true, it should call resolveClass(Class definedClass) on the Class returned by defineClass.

    An easier class loader to extend is ewe.util.mClassLoader. This does most of this work already and you only need to override findClassBytes().


    Constructor Summary
    protected ClassLoader()
               
     
    Method Summary
    protected  Class defineClass(String name, byte[] classBytes, int start, int offset)
              This tells the VM to convert a sequence of bytes representing a class definition into a Class Object.
     Class loadClass(String name)
              This requests a class to be loaded and resolved.
    protected abstract  Class loadClass(String name, boolean resolve)
              This should be overriden to actually locate the class bytes and define the class.
    protected  void resolveClass(Class c)
              This requests the VM to resolve the class after being defined.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, toString
     

    Constructor Detail

    ClassLoader

    protected ClassLoader()
    Method Detail

    loadClass

    public final Class loadClass(String name)
                          throws ClassNotFoundException
    This requests a class to be loaded and resolved.

    Throws:
    ClassNotFoundException

    loadClass

    protected abstract Class loadClass(String name,
                                       boolean resolve)
                                throws ClassNotFoundException
    This should be overriden to actually locate the class bytes and define the class.

    Throws:
    ClassNotFoundException

    resolveClass

    protected final void resolveClass(Class c)
    This requests the VM to resolve the class after being defined. It should be called by loadClass() if the resolve parameter is true.


    defineClass

    protected final Class defineClass(String name,
                                      byte[] classBytes,
                                      int start,
                                      int offset)
    This tells the VM to convert a sequence of bytes representing a class definition into a Class Object. It should be called by loadClass() once the bytes are located.