net.groboclown.util.classes.v1.jdk0
Class UrlClassLoader

java.lang.Object
  |
  +--net.groboclown.util.classes.v1.jdk0.UrlClassLoader
All Implemented Interfaces:
BytecodeSource, IUrlClassLoader

public class UrlClassLoader
extends Object
implements IUrlClassLoader, BytecodeSource

Class responsible for loading classes in a JDK 1.0+ version compatible way. Need to determine speed vs. size for caching Jar files that are loaded over the internet. For now, we cache stuff, in the hope that the flush() will be called.

If the URL is null, or if the bytecode for a class name is not found, then this will attempt to load the class from the system classloader.

Version:
Alpha 0.9.0
Author:
Matt Albrecht

Inner Class Summary
private  class UrlClassLoader.BytecodeSourceCache
           
private  class UrlClassLoader.JarBytecodeSource
          Loads classes from a given zip/jar file
private  class UrlClassLoader.UrlBytecodeSource
           
 
Field Summary
private static String[] JAR_EXTENTIONS
           
private  ArrayClassLoader m_acl
           
private  Hashtable m_urlSources
           
 
Constructor Summary
UrlClassLoader()
          Default constructor
 
Method Summary
protected  String className2jarFileName(String className)
          Converts a class name to a file name.
protected  String convertUrl(String url)
          Converts the given string to a fully qualified URL.
protected  byte[] findZipEntry(String filename, ZipInputStream zis)
          Finds the entry of the given filename in the given input stream, and returns the entry as a byte array.
 void flush()
          Call to flush any cache stored in the interface.
protected  String getAbsoluteFilename(File f)
           
 byte[] getBytecode(String classname)
          Loads the bytecode for the given classname.
protected  BytecodeSource getBytecodeSource(String url)
           
protected  boolean isJarURL(String url)
           
protected  String joinClassToUrl(String className, String url)
          Joins a classname to a URL.
 Class loadClass(String className, String url)
          Load the given class from the given URL.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_acl

private ArrayClassLoader m_acl

m_urlSources

private Hashtable m_urlSources

JAR_EXTENTIONS

private static final String[] JAR_EXTENTIONS
Constructor Detail

UrlClassLoader

public UrlClassLoader()
Default constructor
Method Detail

loadClass

public Class loadClass(String className,
                       String url)
Load the given class from the given URL. If the URL is null, then it loads the class from the default class loader.
Specified by:
loadClass in interface IUrlClassLoader
Parameters:
className - the exact class name to load.
url - the URL from which the class is loaded. If this is null, then this loads the class from the default class loader.
Returns:
the loaded Class instance, or null if the class could not be found.

flush

public void flush()
Call to flush any cache stored in the interface. This allows for a class loader to cache results, and free up memory when it is not needed.
Specified by:
flush in interface IUrlClassLoader

getBytecode

public byte[] getBytecode(String classname)
Description copied from interface: BytecodeSource
Loads the bytecode for the given classname.
Specified by:
getBytecode in interface BytecodeSource
Following copied from interface: net.groboclown.util.classes.v1.jdk0.BytecodeSource
Parameters:
classname - the name of the class to find.
Returns:
null if there was an error finding the class, or the bytecode for the given class.

getBytecodeSource

protected BytecodeSource getBytecodeSource(String url)

convertUrl

protected String convertUrl(String url)
Converts the given string to a fully qualified URL. If no scheme is given, then it is converted to a File scheme.

isJarURL

protected boolean isJarURL(String url)
Returns:
true if the URL references a Jar-like file.

findZipEntry

protected byte[] findZipEntry(String filename,
                              ZipInputStream zis)
Finds the entry of the given filename in the given input stream, and returns the entry as a byte array. If the entry wasn't found, then null is returned.

className2jarFileName

protected String className2jarFileName(String className)
Converts a class name to a file name.

joinClassToUrl

protected String joinClassToUrl(String className,
                                String url)
Joins a classname to a URL.

getAbsoluteFilename

protected String getAbsoluteFilename(File f)


Written under the LGPL