edu.rice.cs.cunit
Class InstrumentingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by edu.rice.cs.cunit.InstrumentingClassLoader

public class InstrumentingClassLoader
extends java.lang.ClassLoader

Class loader that instruments loaded classes by applying IInstrumentors to them.

Author:
Mathias Ricken

Nested Class Summary
private static class InstrumentingClassLoader.RecurIntoClassesException
          Private exception used to transport an exception out of the inner class.
 
Field Summary
protected  java.util.ArrayList<java.lang.String> _classPath
          Class path to consider when loading classes.
protected  java.util.ArrayList<IInstrumentationStrategy> _instrumentors
          List of instrumentors that should be applied to a class.
protected  boolean _makeBackups
          Make backups of original classes?
protected  java.util.HashMap<java.lang.String,java.lang.Class<?>> _processedClasses
          Hash map of classes already processed.
protected  boolean _saveInstrumented
          Should the instrumented classes be saved?
 
Constructor Summary
InstrumentingClassLoader(IInstrumentationStrategy[] instrumentors)
          Creates a new instrumenting class loader using specified instrumentors.
 
Method Summary
 boolean isSaveInstrumented()
          Accessor for the save instrumented flag
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Load and instrument the class with the specified name.
protected  void recurIntoClasses(ClassFile cf, boolean resolve)
          Recur into all the classes defined in the class.
 void setMakeBackups(boolean makeBackups)
          Mutator for the make backups flag
 void setSaveInstrumented(boolean saveInstrumented)
          Mutator for the save instrumented flag
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, 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
 

Field Detail

_saveInstrumented

protected boolean _saveInstrumented
Should the instrumented classes be saved?


_makeBackups

protected boolean _makeBackups
Make backups of original classes?


_instrumentors

protected java.util.ArrayList<IInstrumentationStrategy> _instrumentors
List of instrumentors that should be applied to a class.


_classPath

protected java.util.ArrayList<java.lang.String> _classPath
Class path to consider when loading classes.


_processedClasses

protected java.util.HashMap<java.lang.String,java.lang.Class<?>> _processedClasses
Hash map of classes already processed. Once processing of a class has begun, it is added with a value of null. When processing is done, this value is updated to the actual Class object.If a class has not been processed, it is not present.

Constructor Detail

InstrumentingClassLoader

public InstrumentingClassLoader(IInstrumentationStrategy[] instrumentors)
Creates a new instrumenting class loader using specified instrumentors.

Parameters:
instrumentors - array of instrumentors
Method Detail

isSaveInstrumented

public boolean isSaveInstrumented()
Accessor for the save instrumented flag

Returns:
flag

setSaveInstrumented

public void setSaveInstrumented(boolean saveInstrumented)
Mutator for the save instrumented flag

Parameters:
saveInstrumented - new flag

setMakeBackups

public void setMakeBackups(boolean makeBackups)
Mutator for the make backups flag

Parameters:
makeBackups - new flag

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Load and instrument the class with the specified name.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - class name
resolve - true if class should be resolved
Returns:
Class instance for the loaded class
Throws:
java.lang.ClassNotFoundException

recurIntoClasses

protected void recurIntoClasses(ClassFile cf,
                                boolean resolve)
                         throws java.lang.ClassNotFoundException
Recur into all the classes defined in the class.

Parameters:
cf - class file
resolve - resolve classes?
Throws:
java.lang.ClassNotFoundException