net.sourceforge.groboutils.util.classes.v1.jdk0
Class UrlClassLoader

java.lang.Object
  extended bynet.sourceforge.groboutils.util.classes.v1.jdk0.UrlClassLoader
All Implemented Interfaces:
BytecodeSource, IUrlClassLoader

public class UrlClassLoader
extends java.lang.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.

NOTE: As of version 1.0.0, there is no longer a dependency upon net.sourceforge.groboutils.util.io.v1

Since:
November 17, 2000 (GroboUtils Alpha 0.9.0)
Version:
$Date: 2003/05/06 05:35:00 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Constructor Summary
UrlClassLoader()
          Default constructor
 
Method Summary
protected  java.lang.String className2jarFileName(java.lang.String className)
          Converts a class name to a file name.
protected  java.lang.String convertUrl(java.lang.String url)
          Converts the given string to a fully qualified URL.
protected  byte[] findZipEntry(java.lang.String filename, java.util.zip.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  java.lang.String getAbsoluteFilename(java.io.File f)
           
 byte[] getBytecode(java.lang.String classname)
          Loads the bytecode for the given classname.
protected  BytecodeSource getBytecodeSource(java.lang.String url)
           
protected  boolean isJarURL(java.lang.String url)
           
protected  java.lang.String joinClassToUrl(java.lang.String className, java.lang.String url)
          Joins a classname to a URL.
 java.lang.Class loadClass(java.lang.String className, java.lang.String url)
          Load the given class from the given URL.
protected  byte[] readByteStream(java.io.InputStream is)
          A re-implementation of net.groboclown.util.io.v1.ReadByteStream, to reduce the amount of inter-package dependencies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlClassLoader

public UrlClassLoader()
Default constructor

Method Detail

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 java.lang.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(java.lang.String classname)
Description copied from interface: BytecodeSource
Loads the bytecode for the given classname.

Specified by:
getBytecode in interface 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(java.lang.String url)

convertUrl

protected java.lang.String convertUrl(java.lang.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(java.lang.String url)
Returns:
true if the URL references a Jar-like file.

findZipEntry

protected byte[] findZipEntry(java.lang.String filename,
                              java.util.zip.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 java.lang.String className2jarFileName(java.lang.String className)
Converts a class name to a file name.


joinClassToUrl

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


getAbsoluteFilename

protected java.lang.String getAbsoluteFilename(java.io.File f)

readByteStream

protected byte[] readByteStream(java.io.InputStream is)
                         throws java.io.IOException
A re-implementation of net.groboclown.util.io.v1.ReadByteStream, to reduce the amount of inter-package dependencies.

Throws:
java.io.IOException


Copyright © 2001-2003 by The GroboUtils Project