org.jwalk
Class TestClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.jwalk.GeneratorLoader
                  extended by org.jwalk.TestClassLoader

public class TestClassLoader
extends GeneratorLoader

TestClassLoader is a class loader for loading the test class. Every time the test class is reloaded, it must use a new instance of TestClassLoader to ensure that it is indeed reloaded, rather than fetched from the cache of loaded classes. This allows a modified test class to be recompiled and reloaded by JWalk tools within the same Java runtime. Any other class on which the test class depends is loaded by the delegate ClassLoader, which should always be the GeneratorLoader created by JWalk at start-up. This allows both the test class and arbitrary custom generators to refer to common classes, which are resolved just once in the current Java runtime.

Version:
1.0
Author:
Anthony Simons

Constructor Summary
TestClassLoader(java.lang.ClassLoader delegate, java.lang.String name)
          Creates a TestClassLoader which treats the test class as special.
 
Method Summary
 java.lang.Class<?> loadClass(java.lang.String name)
          Loads the class specified by the package-qualified name.
 
Methods inherited from class org.jwalk.GeneratorLoader
addDirectory
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, 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, 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
 

Constructor Detail

TestClassLoader

public TestClassLoader(java.lang.ClassLoader delegate,
                       java.lang.String name)
Creates a TestClassLoader which treats the test class as special. The package-qualified name of the test class must be provided at construction, to identify the test class apart from all other classes which this TestClassLoader may be asked to load. It delegates all other requests to its delegate ClassLoader, which should be the GeneratorLoader created by JWalk at startup.

Parameters:
delegate - the delegate ClassLoader to use for all other classes.
name - the package-qualified name of the test class.
Method Detail

loadClass

public java.lang.Class<?> loadClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Loads the class specified by the package-qualified name. If this is the test class, loads it locally, searching all the directory paths that were added to this TestClassLoader. Otherwise, delegates to the ClassLoader supplied at creation, which should be the GeneratorLoader created by JWalk at startup.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - a package-qualified test class name.
Returns:
the Class object for this class.
Throws:
java.lang.ClassNotFoundException