The Spring Framework

org.springframework.core
Class OverridingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.springframework.core.OverridingClassLoader
Direct Known Subclasses:
SimpleInstrumentableClassLoader, SimpleThrowawayClassLoader

public class OverridingClassLoader
extends ClassLoader

ClassLoader that does not always delegate to the parent loader, as normal class loaders do. This enables, for example, instrumentation to be forced in the overriding ClassLoader, or a "throwaway" class loading behavior, where selected classes are temporarily loaded in the overriding ClassLoader, in order to be load an instrumented version of the class in the parent ClassLoader later on.

Since:
2.0.1
Author:
Rod Johnson, Juergen Hoeller

Constructor Summary
OverridingClassLoader(ClassLoader parent)
          Create a new OverridingClassLoader for the given class loader.
 
Method Summary
 void excludeClass(String className)
          Add a class name to exclude from overriding.
 void excludePackage(String packageName)
          Add a package name to exclude from overriding.
protected  boolean isEligibleForOverriding(String className)
          Determine whether the specified class is eligible for overriding by this class loader.
protected  Class loadClass(String name, boolean resolve)
           
protected  byte[] transformIfNecessary(String name, byte[] bytes)
          Transformation hook to be implemented by subclasses.
 
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
 

Constructor Detail

OverridingClassLoader

public OverridingClassLoader(ClassLoader parent)
Create a new OverridingClassLoader for the given class loader.

Parameters:
parent - the ClassLoader to build an overriding ClassLoader for
Method Detail

excludePackage

public void excludePackage(String packageName)
Add a package name to exclude from overriding.

Any class whose fully-qualified name starts with the name registered here will be handled by the parent ClassLoader in the usual fashion.

Parameters:
packageName - the package name to exclude

excludeClass

public void excludeClass(String className)
Add a class name to exclude from overriding.

Any class name registered here will be handled by the parent ClassLoader in the usual fashion.

Parameters:
className - the class name to exclude

loadClass

protected Class loadClass(String name,
                          boolean resolve)
                   throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

isEligibleForOverriding

protected boolean isEligibleForOverriding(String className)
Determine whether the specified class is eligible for overriding by this class loader.

The default implementation checks against excluded packages and classes.

Parameters:
className - the class name to check
Returns:
whether the specified class is eligible
See Also:
excludePackage(java.lang.String), excludeClass(java.lang.String)

transformIfNecessary

protected byte[] transformIfNecessary(String name,
                                      byte[] bytes)
Transformation hook to be implemented by subclasses.

The default implementation simply returns the given bytes as-is.

Parameters:
name - the fully-qualified name of the class being transformed
bytes - the raw bytes of the class
Returns:
the transformed bytes (never null; same as the input bytes if the transformation produced no changes)

The Spring Framework

Copyright © 2002-2007 The Spring Framework.