org.apache.commons.javaflow
Class ContinuationClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.apache.commons.javaflow.ContinuationClassLoader

public final class ContinuationClassLoader
extends java.net.URLClassLoader

URLClassLoader with bytecode instrumentation for javaflow.

This class loader is useful where the application can set up multiple class loaders (such as in a container environment, ClassWorlds, or Forehead) and when you can isolate the continuation-enabled portion of your application into a separate jar file.


Constructor Summary
ContinuationClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
           
ContinuationClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent, ResourceTransformer transformer)
          Creates a classloader by using the classpath given.
 
Method Summary
 void addLoaderPackageRoot(java.lang.String packageRoot)
          Adds a package root to the list of packages which must be loaded using this loader.
 void addSystemPackageRoot(java.lang.String packageRoot)
          Adds a package root to the list of packages which must be loaded on the parent loader.
protected  java.lang.Class defineClassFromData(byte[] classData, java.lang.String classname)
          Define a class given its bytes
 java.lang.Class findClass(java.lang.String name)
          Searches for and load a class on the classpath of this class loader.
 java.lang.Class forceLoadClass(java.lang.String classname)
          Loads a class through this class loader even if that class is available on the parent classpath.
 java.net.URL getResource(java.lang.String name)
          Finds the resource with the given name.
protected  java.lang.Class loadClass(java.lang.String classname, boolean resolve)
          Loads a class with this class loader.
 void setIsolated(boolean isolated)
          Sets whether this classloader should run in isolated mode.
 void setParentFirst(boolean parentFirst)
          Control whether class lookup is delegated to the parent loader first or after this loader.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, 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
 

Constructor Detail

ContinuationClassLoader

public ContinuationClassLoader(java.net.URL[] urls,
                               java.lang.ClassLoader parent,
                               ResourceTransformer transformer)
Creates a classloader by using the classpath given.

Parameters:
urls - The URLs from which to load classes and resources
parent - The parent classloader to which unsatisfied loading attempts are delegated. May be null, in which case the system classloader is used as the parent.
transformer - This transformer is used to perform the byte-code enhancement. May not be null.

ContinuationClassLoader

public ContinuationClassLoader(java.net.URL[] urls,
                               java.lang.ClassLoader parent)
Method Detail

setParentFirst

public void setParentFirst(boolean parentFirst)
Control whether class lookup is delegated to the parent loader first or after this loader. Use with extreme caution. Setting this to false violates the class loader hierarchy and can lead to Linkage errors

Parameters:
parentFirst - if true, delegate initial class search to the parent classloader.

setIsolated

public void setIsolated(boolean isolated)
Sets whether this classloader should run in isolated mode. In isolated mode, classes not found on the given classpath will not be referred to the parent class loader but will cause a ClassNotFoundException.

Parameters:
isolated - Whether or not this classloader should run in isolated mode.

addSystemPackageRoot

public void addSystemPackageRoot(java.lang.String packageRoot)
Adds a package root to the list of packages which must be loaded on the parent loader. All subpackages are also included.

Parameters:
packageRoot - The root of all packages to be included. Should not be null.

addLoaderPackageRoot

public void addLoaderPackageRoot(java.lang.String packageRoot)
Adds a package root to the list of packages which must be loaded using this loader. All subpackages are also included.

Parameters:
packageRoot - The root of all packages to be included. Should not be null.

forceLoadClass

public java.lang.Class forceLoadClass(java.lang.String classname)
                               throws java.lang.ClassNotFoundException
Loads a class through this class loader even if that class is available on the parent classpath. This ensures that any classes which are loaded by the returned class will use this classloader.

Parameters:
classname - The name of the class to be loaded. Must not be null.
Returns:
the required Class object
Throws:
java.lang.ClassNotFoundException - if the requested class does not exist on this loader's classpath.

loadClass

protected java.lang.Class loadClass(java.lang.String classname,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Loads a class with this class loader. This class attempts to load the class in an order determined by whether or not the class matches the system/loader package lists, with the loader package list taking priority. If the classloader is in isolated mode, failure to load the class in this loader will result in a ClassNotFoundException.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
classname - The name of the class to be loaded. Must not be null.
resolve - true if all classes upon which this class depends are to be loaded.
Returns:
the required Class object
Throws:
java.lang.ClassNotFoundException - if the requested class does not exist on the system classpath (when not in isolated mode) or this loader's classpath.

defineClassFromData

protected java.lang.Class defineClassFromData(byte[] classData,
                                              java.lang.String classname)
Define a class given its bytes

Parameters:
classData - the bytecode data for the class
classname - the name of the class
Returns:
the Class instance created from the given data

findClass

public java.lang.Class findClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Searches for and load a class on the classpath of this class loader.

Overrides:
findClass in class java.net.URLClassLoader
Parameters:
name - The name of the class to be loaded. Must not be null.
Returns:
the required Class object
Throws:
java.lang.ClassNotFoundException - if the requested class does not exist on this loader's classpath.

getResource

public java.net.URL getResource(java.lang.String name)
Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - The name of the resource for which a stream is required. Must not be null.
Returns:
a URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource.


Copyright 2004-2008 The Apache Software Foundation. All Rights Reserved.