net.larsan.urd.util
Class ResourceClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--net.larsan.urd.util.ResourceClassLoader
Direct Known Subclasses:
ArchiveLoader, SharedSpaceLoader

public class ResourceClassLoader
extends java.security.SecureClassLoader

A class loader based on a resource locator. This class loader should not be used standalone without a caching resource locator to operate on.

This class only accepts single resources with the same name, so the findResources method will always return a trivial enumeration.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
protected  ResourceLocator locator
          Resource locator used by this class loader.
 
Constructor Summary
ResourceClassLoader(java.lang.ClassLoader parent, ResourceLocator locator)
          Create a class loader with a parent loader and a resource locator from which the class loader loads resources and classes.
ResourceClassLoader(ResourceLocator locator)
          Create a class loader with a resource locator from which the class loader loads resources and classes.
 
Method Summary
protected  java.lang.Class findClass(java.lang.String name)
          Find class, this method uses the resource locator to read the class bytes if possible.
protected  java.net.URL findResource(java.lang.String name)
          Find resource, this method uses the resource locator to resolve the URL and return null in the URL is not found.
protected  java.util.Enumeration findResources(java.lang.String name)
          Find resources, this method returns a trivial enumeration over the return from the findResource method.
protected  java.security.CodeSource getCodeSource(Resource rec)
          Get the code source of a resource, this method returns null if no url for the code could be found.
protected  java.security.PermissionCollection getPermissions(java.security.CodeSource src)
          Get the permission for a code source.
 java.lang.Class loadClass(java.lang.String name)
          Load a class.
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, 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

locator

protected ResourceLocator locator
Resource locator used by this class loader. The class loader will attept to resolve classes and resources from this locator. Should the class loader be used without a parent the resource locator should be caching its content for speed improvements.

Constructor Detail

ResourceClassLoader

public ResourceClassLoader(java.lang.ClassLoader parent,
                           ResourceLocator locator)
Create a class loader with a parent loader and a resource locator from which the class loader loads resources and classes.

Parameters:
parent - Parent class loader
locator - Resoucre locator to resolve resources with

ResourceClassLoader

public ResourceClassLoader(ResourceLocator locator)
Create a class loader with a resource locator from which the class loader loads resources and classes.

Parameters:
locator - Resoucre locator to resolve resources with
Method Detail

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Load a class. This method checks with an installed security manager for package access permissions.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - Class name to load
Returns:
A class object
Throws:
java.lang.ClassNotFoundException - If the class is not found

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Find class, this method uses the resource locator to read the class bytes if possible.

Overrides:
findClass in class java.lang.ClassLoader
Parameters:
name - Class name to find
Returns:
A class object
Throws:
java.lang.ClassNotFoundException - If the class is not found

getPermissions

protected java.security.PermissionCollection getPermissions(java.security.CodeSource src)
Get the permission for a code source. This returns the permission collection as specified by the system/application policy file.

Overrides:
getPermissions in class java.security.SecureClassLoader
Parameters:
src - Code source
Returns:
The system permissions for the code source

findResource

protected java.net.URL findResource(java.lang.String name)
Find resource, this method uses the resource locator to resolve the URL and return null in the URL is not found.

Overrides:
findResource in class java.lang.ClassLoader
Parameters:
name - Resource name
Returns:
The resource URL, or null if not found

findResources

protected java.util.Enumeration findResources(java.lang.String name)
Find resources, this method returns a trivial enumeration over the return from the findResource method.

Overrides:
findResources in class java.lang.ClassLoader
Parameters:
name - Resource name
Returns:
A trivial enumeration over a resource

getCodeSource

protected java.security.CodeSource getCodeSource(Resource rec)
Get the code source of a resource, this method returns null if no url for the code could be found.

Parameters:
rec - Resource to create a code source for
Returns:
A code source for the resource, or null if not found