Voyager ORB

com.objectspace.voyager.loader
Class VoyagerClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.objectspace.voyager.loader.VoyagerClassLoader

public final class VoyagerClassLoader
extends java.lang.ClassLoader

VoyagerClassLoader is the default class loader, and supports custom loading of resources such as classes and proxies.

A VoyagerClassLoader maintains a list of prioritized resource loaders that implement IResourceLoader. If a resource cannot be found in the local CLASSPATH, each loader is sent getResourceAsStream( name ), starting at the loader with the highest priority. If two or more resource loaders are added at the same priority level, they are consulted in the order they were added.

The dynamic proxy generator implements IResourceLoader and is automatically installed at priority 5.

Version:
3.0

Method Summary
static IResourceLoader addResourceLoader(IResourceLoader resource)
          Add a resource loader of priority 10 to my list of loaders.
static IResourceLoader addResourceLoader(IResourceLoader resource, float priority)
          If the specified resource loader is not already in my list of loaders, add it at the specified priority and return it, otherwise return the existing loader.
static void addURLResource(java.lang.String url)
          Add a loader that obtains resources from the specified URL.
 java.io.InputStream getLocalResourceAsStream(java.lang.String name)
          Searches all installed resource loaders for the resource name specified.
 java.net.URL getResource(java.lang.String name)
          Return a URL for the requested resource.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Return an InputStream containing the bytes for the requested resource.
static boolean isResourceLoadingEnabled()
          Return true if resource loading is enabled.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load the specifed class, resolving if necessary.
static java.lang.Class loadClass(java.lang.String url, java.lang.String classname)
          This method is used for bootstrapping clients via the VoyagerClassLoader.
static boolean removeResourceLoader(IResourceLoader resource)
          If the specified resource loader is in my list of loaders, remove it and return true, otherwise return false.
static void setResourceLoadingEnabled(boolean flag)
          If the flag is true, enable resource loading.
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addResourceLoader

public static IResourceLoader addResourceLoader(IResourceLoader resource)
Add a resource loader of priority 10 to my list of loaders.
Parameters:
resource - The resource loader.

addResourceLoader

public static IResourceLoader addResourceLoader(IResourceLoader resource,
                                                float priority)
If the specified resource loader is not already in my list of loaders, add it at the specified priority and return it, otherwise return the existing loader. The higher the priority value, the higher the search priority.
Parameters:
resource - The resource loader.
priority - The search priority.

removeResourceLoader

public static boolean removeResourceLoader(IResourceLoader resource)
If the specified resource loader is in my list of loaders, remove it and return true, otherwise return false.
Parameters:
resource - The resource loader.

setResourceLoadingEnabled

public static void setResourceLoadingEnabled(boolean flag)
If the flag is true, enable resource loading.
Parameters:
flag - The new setting.

isResourceLoadingEnabled

public static boolean isResourceLoadingEnabled()
Return true if resource loading is enabled.

addURLResource

public static void addURLResource(java.lang.String url)
                           throws java.net.MalformedURLException
Add a loader that obtains resources from the specified URL. To allow class loading from a repository served up by a web server or HTTP-enabled Voyager server, specify the address as 'http://host:port/root/' (note the trailing forward slash). To allow class loading from a directory not in the CLASSPATH, specify the address as 'file:///' (note the trailing three forward slashes).
If no protocol is given, file:/// will be assumed, thus ./dir1/ would become file:///currentdir/dir1/, and /dir1/ would become file:///dir1/. Adding null has no effect.
Parameters:
url - The URL to search when loading resources.
Throws:
java.net.MalformedURLException - The URL had a syntax error.

loadClass

public static java.lang.Class loadClass(java.lang.String url,
                                        java.lang.String classname)
                                 throws java.net.MalformedURLException,
                                        java.lang.ClassNotFoundException
This method is used for bootstrapping clients via the VoyagerClassLoader. This allows an entire application to be loaded by Voyager's class loader.
Parameters:
url - The url of the "codebase" from which the class can be loaded.
classname - The fully qualified name of the class to load.
Throws:
java.net.MalformedURLException - The url is not a valid url.
java.lang.ClassNotFoundException - The class was not found.

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Load the specifed class, resolving if necessary.
Parameters:
name - The full name of the class to load.
resolve - If true, resolve immediately.
Throws:
java.lang.ClassNotFoundException - The class was not found.
Overrides:
loadClass in class java.lang.ClassLoader

getResource

public java.net.URL getResource(java.lang.String name)
Return a URL for the requested resource. Resources provided by IResourceLoaders are not returned by this method.
Parameters:
name - The filename, including path, of a particular resource.
Overrides:
getResource in class java.lang.ClassLoader

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Return an InputStream containing the bytes for the requested resource.
Parameters:
name - The full filename of a particular resource.
Overrides:
getResourceAsStream in class java.lang.ClassLoader

getLocalResourceAsStream

public java.io.InputStream getLocalResourceAsStream(java.lang.String name)
Searches all installed resource loaders for the resource name specified.

ObjectSpace Inc.

(c) Copyright 1997-1999 ObjectSpace, Inc.
14850 Quorum Drive, Suite 500
Dallas, Texas 75240