edu.rice.cs.plt.reflect
Class PathClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by edu.rice.cs.plt.reflect.AbstractClassLoader
          extended by edu.rice.cs.plt.reflect.PathClassLoader

public class PathClassLoader
extends AbstractClassLoader

A class loader that mimics the standard application system loader by loading classes from a file path of directories and jar files. This class also supports a dynamic class path: an Iterable provided as input to the constructor is held, not copied, and subsequent changes to that iterable are reflected in the path that is searched. Of course, once a class is loaded, subsequent changes to the path will not change the class bound to that name. The dynamic nature of the search path makes possible unusual errors -- a class may be valid in the path in which it is initially loaded, but when the JVM later transitively resolves the referenced classes, they may no longer exist, or may be shadowed. This is not a unique problem, however -- the standard system class loader is based on an underlying file system that may also change in arbitrary ways at any time.


Constructor Summary
PathClassLoader(ClassLoader parent, File... path)
          Create a path class loader with the given parent and path
PathClassLoader(ClassLoader parent, Iterable<? extends File> path)
          Create a path class loader with the given parent and path
PathClassLoader(File... path)
          Create a path class loader with the default parent (ClassLoader.getSystemClassLoader()) and the specified path.
PathClassLoader(Iterable<? extends File> path)
          Create a path class loader with the default parent (ClassLoader.getSystemClassLoader()) and the specified path.
 
Method Summary
protected  Class<?> findClass(String name)
           
protected  URL findResource(String name)
           
protected  Enumeration<URL> findResources(String name)
           
static URL getResourceInPath(String name, File... path)
          Locate a resource in the given path.
static URL getResourceInPath(String name, Iterable<File> path)
          Locate a resource in the given path.
static InputStream getResourceInPathAsStream(String name, File... path)
          Locate a resource in the given path.
static InputStream getResourceInPathAsStream(String name, Iterable<File> path)
          Locate a resource in the given path.
 
Methods inherited from class edu.rice.cs.plt.reflect.AbstractClassLoader
definePackageForClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, 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

PathClassLoader

public PathClassLoader(File... path)
Create a path class loader with the default parent (ClassLoader.getSystemClassLoader()) and the specified path.


PathClassLoader

public PathClassLoader(Iterable<? extends File> path)
Create a path class loader with the default parent (ClassLoader.getSystemClassLoader()) and the specified path.


PathClassLoader

public PathClassLoader(ClassLoader parent,
                       File... path)
Create a path class loader with the given parent and path


PathClassLoader

public PathClassLoader(ClassLoader parent,
                       Iterable<? extends File> path)
Create a path class loader with the given parent and path

Method Detail

getResourceInPath

public static URL getResourceInPath(String name,
                                    File... path)
Locate a resource in the given path. Returns null if the resource is not found. If multiple queries will be performed on the same path, a PathClassLoader instance should be created for better performance.


getResourceInPath

public static URL getResourceInPath(String name,
                                    Iterable<File> path)
Locate a resource in the given path. Returns null if the resource is not found. If multiple queries will be performed on the same path, a PathClassLoader instance should be created for better performance.


getResourceInPathAsStream

public static InputStream getResourceInPathAsStream(String name,
                                                    File... path)
Locate a resource in the given path. Returns null if the resource is not found. If multiple queries will be performed on the same path, a PathClassLoader instance should be created for better performance.


getResourceInPathAsStream

public static InputStream getResourceInPathAsStream(String name,
                                                    Iterable<File> path)
Locate a resource in the given path. Returns null if the resource is not found. If multiple queries will be performed on the same path, a PathClassLoader instance should be created for better performance.


findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Overrides:
findClass in class ClassLoader
Throws:
ClassNotFoundException

findResource

protected URL findResource(String name)
Overrides:
findResource in class ClassLoader

findResources

protected Enumeration<URL> findResources(String name)
                                  throws IOException
Overrides:
findResources in class ClassLoader
Throws:
IOException