fi.hut.tml.xsmiles
Class NetworkClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byfi.hut.tml.xsmiles.NetworkClassLoader

public class NetworkClassLoader
extends java.lang.ClassLoader

The correct name for this class should be URLClassLoader. But there is already a class by that name in JDK1.2. I have had quite a few problems with URLClassLoader in past, so I ended up writing this ClassLoader. I found that the Java 2's URLClassLoader, does not close the Jar file once opened. It is a pretty good optimization step, but if you modify the class in the jar file, it does not pick it up. Some operating systems may not let you modify the jar file while it is still open. IMHO, it does make sense to close the jar file after you are done reading the class data. But this approach may not get you the performance of the URLClassLoader, but it works in all cases and also runs on JDK1.1. I have enhanced this class loader to read all the zip/jar entries once & cache the data, so that there is no overhead of opening/closing jar file to pick up each entry.

Author:
Harish Prabandham

Nested Class Summary
 class NetworkClassLoader.URLResourceReader
          This implementation of URL Resource Reader assumes 2 types of base urls.
 
Constructor Summary
NetworkClassLoader(java.lang.ClassLoader parent)
          Creates a new instance of the class loader.
 
Method Summary
 void addURL(java.net.URL url)
          Adds the given URL to this class loader.
 void clear()
          This method resets this ClassLoader's state.
protected  java.lang.Class defineClass(java.lang.String classname, byte[] classdata)
          java.lang.ClassLoader's defineClass method is final, so the its subclasses cannot override this method.
protected  void finalize()
          This method resets this ClassLoader's state and resets the references for garbage collection.
 java.lang.Class findClass(java.lang.String name)
          Call this to bypass the implementation of loadClass.
 java.io.InputStream getResourceAsStream(java.lang.String name)
           
 java.util.Enumeration getURLs()
           
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
protected  byte[] loadClassData(java.lang.String classname)
           
protected  byte[] loadResource(java.lang.String resource)
           
protected  byte[] loadResource(java.net.URL url, java.lang.String resourceName)
           
protected  void setParent(java.lang.ClassLoader parent)
          Sets the parent/delegate class loader.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkClassLoader

public NetworkClassLoader(java.lang.ClassLoader parent)
Creates a new instance of the class loader.

Method Detail

setParent

protected final void setParent(java.lang.ClassLoader parent)
Sets the parent/delegate class loader.


addURL

public void addURL(java.net.URL url)
Adds the given URL to this class loader. If the URL ends with "/", then it is assumed to be a directory otherwise, it is assumed to be a zip/jar file. If the same URL is added again, the URL is re-opened and this zip/jar file is used for serving any future class requests.


getURLs

public java.util.Enumeration getURLs()
Returns:
An enumeration of URLs where this class loader looks for classes.

findClass

public java.lang.Class findClass(java.lang.String name)
Call this to bypass the implementation of loadClass.


loadResource

protected byte[] loadResource(java.net.URL url,
                              java.lang.String resourceName)
                       throws java.io.IOException
Throws:
java.io.IOException

loadResource

protected byte[] loadResource(java.lang.String resource)

loadClassData

protected byte[] loadClassData(java.lang.String classname)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Returns:
The resource as the input stream if such a resource exists, otherwise returns null.

defineClass

protected java.lang.Class defineClass(java.lang.String classname,
                                      byte[] classdata)
java.lang.ClassLoader's defineClass method is final, so the its subclasses cannot override this method. But, this class calls this method in the loadClass() instead.

Returns:
The class object.

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

clear

public final void clear()
This method resets this ClassLoader's state. It completely removes all the URLs and classes in this class loader cache.


finalize

protected void finalize()
                 throws java.lang.Throwable
This method resets this ClassLoader's state and resets the references for garbage collection.

Throws:
java.lang.Throwable


X-Smiles 1.2