SmartFrog 3.10.000

org.smartfrog.sfcore.common
Class URLClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.smartfrog.sfcore.common.BaseClassLoader
          extended by org.smartfrog.sfcore.common.URLClassLoader

public class URLClassLoader
extends BaseClassLoader

Defines a simple classloader which knows how to download classes from a URL. Classloaders with the same URL are shared to avoid class equality problems. Does NOT know how to handle jar files yet.


Field Summary
protected  java.net.URL classBase
          Base for class download.
protected static java.util.Hashtable loaders
          Table to maintain loaders for URLs.
 
Constructor Summary
URLClassLoader(java.net.URL u)
          Constructor.
 
Method Summary
protected  byte[] findClassBytes(java.lang.String className)
          Override to locate the defining bytes for given class relative to the class base.
static java.lang.ClassLoader forURL(java.net.URL u)
          Get a classloader for given URL.
 java.net.URL getResource(java.lang.String name)
          Gets a URL for given resource.
 java.io.InputStream getResourceAsStream(java.lang.String resource)
          Gets the given resource as an input stream.
protected  java.net.URL relToClassBase(java.lang.String name)
          Sets a name relative to the class base for this classloader.
 
Methods inherited from class org.smartfrog.sfcore.common.BaseClassLoader
findClass, loadClass, loadClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loaders

protected static java.util.Hashtable loaders
Table to maintain loaders for URLs.


classBase

protected java.net.URL classBase
Base for class download.

Constructor Detail

URLClassLoader

public URLClassLoader(java.net.URL u)
Constructor.

Parameters:
u - URL for this loader
Method Detail

forURL

public static java.lang.ClassLoader forURL(java.net.URL u)
Get a classloader for given URL. Looks loader up in loader-table, or creates and inserts a new one if a new URL.

Parameters:
u - URL to find loader for
Returns:
ClassLoader

findClassBytes

protected byte[] findClassBytes(java.lang.String className)
                         throws java.io.IOException
Override to locate the defining bytes for given class relative to the class base. This is were support for URL to jar file should be added (file caching could be an issue?).

Overrides:
findClassBytes in class BaseClassLoader
Parameters:
className - class to find bytes for
Returns:
bytes defining class
Throws:
java.io.IOException - error while reading bytes

relToClassBase

protected java.net.URL relToClassBase(java.lang.String name)
                               throws java.io.IOException
Sets a name relative to the class base for this classloader.

Parameters:
name - name to make relative to class base
Returns:
complete URL for name (from class base)
Throws:
java.io.IOException - error constructing URL

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String resource)
Gets the given resource as an input stream. Checks if super class can do this, then looks at an offset from the class base

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
resource - resource to look up.
Returns:
input stream to resource, or null if not found

getResource

public java.net.URL getResource(java.lang.String name)
Gets a URL for given resource. This method always offsets from the classbase.

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - resource to get
Returns:
URL to resource or null on error

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP