org.progeeks.util
Class ClassSpace

java.lang.Object
  extended by org.progeeks.util.ClassSpace

public class ClassSpace
extends java.lang.Object

Isolates a classloader and tracks a set of classes that will always be delegated to the parent classloader. Usually these will be interfaces that classes within the class-space will implement... so as to act as a class loader translation layer. Other methods exist for easily accessing contained classes, etc.. The primary purpose for ClassSpace is to be a convenient way for an application to create separate sandboxes that may use classes or jars that would be imcompatible with the rest of the application space.

Version:
$Revision: 1.2 $
Author:
Paul Speed

Constructor Summary
ClassSpace()
           
 
Method Summary
 void addClassPathEntry(java.io.File entry)
          Convenience method for adding a classpath entry.
 void addClassPathEntry(java.lang.String entry)
          Convenience method for adding a classpath entry.
 void addClassPathEntry(java.net.URL entry)
          Convenience method for adding a classpath entry.
 void addSharedClass(java.lang.Class c)
          Adds the name of the specified class to the list of class names that should always be loaded from the parent class loader.
 void addSharedClassName(java.lang.String s)
          Adds the name to the list of class names that should always be loaded from the parent class loader.
protected  void checkInitialized()
           
 java.util.List getClassPath()
          Returns the current classpath list for the classspace as a list of URLs.
 java.lang.ClassLoader getParentClassLoader()
          Returns the parent classloader for the space.
 PatternSet getSharedClassPatterns()
          Returns the PatternSet used to determine if a class name should be looked up in the class space classloader or in the parrent classloader.
 PatternSet getSharedResourcePatterns()
          Returns the PatternSet used to determine if a resource name should be looked up in the class space classloader or in the parrent classloader.
 void initialize()
          Initializes the internal classloader and prepares this classspace for use.
 java.lang.Class loadClass(java.lang.String name)
          Convenience method for loading a class without having to grab the space classloader first.
static void main(java.lang.String[] args)
           
 void setClassPath(java.util.List entries)
          Sets the list of class-path entries for the classpace.
 void setParentClassLoader(java.lang.ClassLoader parent)
          Sets the parent classloader for the space.
protected  boolean shouldLoadClassFromParent(java.lang.String name)
           
protected  boolean shouldLoadResourceFromParent(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassSpace

public ClassSpace()
Method Detail

checkInitialized

protected void checkInitialized()

setParentClassLoader

public void setParentClassLoader(java.lang.ClassLoader parent)
Sets the parent classloader for the space. This is the classloader that will be used to load any shared classes and defaults to the current classloader.


getParentClassLoader

public java.lang.ClassLoader getParentClassLoader()
Returns the parent classloader for the space. This is the classloader that will be used to load any shared classes and defaults to the current classloader.


setClassPath

public void setClassPath(java.util.List entries)
Sets the list of class-path entries for the classpace. This list should only contain File, String, or URL entries.


addClassPathEntry

public void addClassPathEntry(java.net.URL entry)
Convenience method for adding a classpath entry.


addClassPathEntry

public void addClassPathEntry(java.lang.String entry)
Convenience method for adding a classpath entry.


addClassPathEntry

public void addClassPathEntry(java.io.File entry)
Convenience method for adding a classpath entry.


getClassPath

public java.util.List getClassPath()
Returns the current classpath list for the classspace as a list of URLs.


getSharedClassPatterns

public PatternSet getSharedClassPatterns()
Returns the PatternSet used to determine if a class name should be looked up in the class space classloader or in the parrent classloader. Class names included in this pattern set will always be loaded from the parent.


addSharedClass

public void addSharedClass(java.lang.Class c)
Adds the name of the specified class to the list of class names that should always be loaded from the parent class loader. This is a convenience method that delegates to the class name pattern set.


addSharedClassName

public void addSharedClassName(java.lang.String s)
Adds the name to the list of class names that should always be loaded from the parent class loader. This is a convenience method that delegates to the class name pattern set.


getSharedResourcePatterns

public PatternSet getSharedResourcePatterns()
Returns the PatternSet used to determine if a resource name should be looked up in the class space classloader or in the parrent classloader. Resource names included in this pattern set will always be loaded from the parent.


shouldLoadClassFromParent

protected boolean shouldLoadClassFromParent(java.lang.String name)

shouldLoadResourceFromParent

protected boolean shouldLoadResourceFromParent(java.lang.String name)

initialize

public void initialize()
Initializes the internal classloader and prepares this classspace for use. After the classspace is initialized, it's settings are immutable.


loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Convenience method for loading a class without having to grab the space classloader first.

Throws:
java.lang.ClassNotFoundException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2002-2003 Paul Speed. All Rights Reserved.