ewe.util
Class mClassLoader

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

public abstract class mClassLoader
extends ClassLoader


Field Summary
protected  Hashtable loaded
          A cache of already loaded classes.
 
Constructor Summary
mClassLoader()
           
 
Method Summary
static void addClassLoader(ClassLoader loader)
          Add a ClassLoader to the WeakSet of application classLoaders.
 void authorize(mClassLoader other)
          This passes authority from this ClassLoader to another.
protected  void cacheClass(String className, Class aClass)
          Override this to provide class caching.
protected  Class findCachedClass(String className)
          Override this to provide class caching.
protected  ByteArray findClassBytes(String className)
          You can override this method OR you can override getInputStreamFor(String className) - which is called by this method.
static Class getClass(String name, Class requestor)
          This is a utility method used to load a Class by another Class which itself may have been loaded via a ClassLoader.
static int getClassLoaders(Vector dest)
          Get the current set of application ClassLoaders into a Vector, or simply count the number of active ClassLoaders.
protected  Stream getInputStreamFor(String className)
          This is called by findClassBytes by default and you can override this if necessary instead of overriding findClassBytes().
protected  Class loadClass(String className, boolean resolve)
          This method will check for system classes and cached classes before calling findClassBytes().
static Object newInstance(String className, Class requestor)
          This tries to get a new instance of a class.
 Stream openResource(String resourceName)
          This is used to get a resource which may be dependant on the how the class was loaded.
static Stream openResource(String resourceName, Class requestor)
          This tries to open a resource via the class loader of the requestor.
static void removeClassLoader(ClassLoader loader)
           
 
Methods inherited from class java.lang.ClassLoader
defineClass, loadClass, resolveClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

loaded

protected Hashtable loaded
A cache of already loaded classes.

Constructor Detail

mClassLoader

public mClassLoader()
Method Detail

authorize

public final void authorize(mClassLoader other)
                     throws SecurityException
This passes authority from this ClassLoader to another. This call can only be made by system classes or by classes loaded by this ClassLoader, or by this ClassLoader itself.

Throws:
SecurityException

addClassLoader

public static void addClassLoader(ClassLoader loader)
Add a ClassLoader to the WeakSet of application classLoaders. You do not need to do this if you are creating a ClassLoader that inherits from mClassLoader as they automatically add to the WeakSet upon creation.


removeClassLoader

public static void removeClassLoader(ClassLoader loader)

getClassLoaders

public static int getClassLoaders(Vector dest)
Get the current set of application ClassLoaders into a Vector, or simply count the number of active ClassLoaders.

Parameters:
dest - A Vector to hold the class loaders. If this is not null it will be cleared before the classes are placed in it. If it is null then this just counts the number of active ClassLoaders.
Returns:
The number of active class loaders.

loadClass

protected Class loadClass(String className,
                          boolean resolve)
                   throws ClassNotFoundException
This method will check for system classes and cached classes before calling findClassBytes().

Specified by:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

findCachedClass

protected Class findCachedClass(String className)
Override this to provide class caching. By default a simple hashtable is used.


cacheClass

protected void cacheClass(String className,
                          Class aClass)
Override this to provide class caching. By default a simple hashtable is used.


findClassBytes

protected ByteArray findClassBytes(String className)
You can override this method OR you can override getInputStreamFor(String className) - which is called by this method. It should attempt to locate the class bytes and put it in a returned ByteArray object. If it could not it should return null or throw a RuntimeException.


getInputStreamFor

protected Stream getInputStreamFor(String className)
This is called by findClassBytes by default and you can override this if necessary instead of overriding findClassBytes(). By default it will convert all '.' to '/' and then append '.class' to the end of it. It will then call openResource() with the converted class name. Therefore, overriding openResource() will take care of loading classes AND class dependant resources.


openResource

public Stream openResource(String resourceName)
This is used to get a resource which may be dependant on the how the class was loaded.


getClass

public static Class getClass(String name,
                             Class requestor)
This is a utility method used to load a Class by another Class which itself may have been loaded via a ClassLoader. It first tries to load the class via the default system class loader using Class.forName(). If this fails it checks the ClassLoader for the requestor class (if the requestor is not null) and requests that ClassLoader to load the class. If that fails as well it will return null.


newInstance

public static Object newInstance(String className,
                                 Class requestor)
This tries to get a new instance of a class. First it calls mClassLoader.getClass() to get a Class object for the className. If that is successful it attempts to create a new instance of the class by calling the default constructor. If this is is successful it will return the newly created object.


openResource

public static Stream openResource(String resourceName,
                                  Class requestor)
This tries to open a resource via the class loader of the requestor. If this fails it will then try to open the resource normally. This actually calls ewe.sys.Vm.openResource().