The Spring Framework

org.springframework.instrument.classloading
Class ShadowingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.springframework.instrument.classloading.ShadowingClassLoader
Direct Known Subclasses:
ResourceOverridingShadowingClassLoader

public class ShadowingClassLoader
extends ClassLoader

ClassLoader decorator that shadows an enclosing ClassLoader, applying registered transformers to all affected classes.

Since:
2.0
Author:
Rob Harrop, Rod Johnson, Costin Leau, Juergen Hoeller
See Also:
addTransformer(java.lang.instrument.ClassFileTransformer), OverridingClassLoader

Field Summary
static String[] DEFAULT_EXCLUDED_PACKAGES
          Packages that are excluded by default
 
Constructor Summary
ShadowingClassLoader(ClassLoader enclosingClassLoader)
          Create a new ShadowingClassLoader, decorating the given ClassLoader.
 
Method Summary
 void addTransformer(ClassFileTransformer transformer)
          Add the given ClassFileTransformer to the list of transformers that this ClassLoader will apply.
 void copyTransformers(ShadowingClassLoader other)
          Copy all ClassFileTransformers from the given ClassLoader to the list of transformers that this ClassLoader will apply.
 void excludeClass(String className)
          Add a class name to exclude from shadowing.
 void excludePackage(String packageName)
          Add a package name to exclude from shadowing.
 URL getResource(String name)
           
 InputStream getResourceAsStream(String name)
           
 Enumeration<URL> getResources(String name)
           
protected  boolean isClassNameExcludedFromShadowing(String className)
          Deprecated. in favor of isEligibleForShadowing(java.lang.String)
protected  boolean isEligibleForShadowing(String className)
          Determine whether the specified class is eligible for shadowing by this class loader.
 Class<?> loadClass(String name)
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, 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

DEFAULT_EXCLUDED_PACKAGES

public static final String[] DEFAULT_EXCLUDED_PACKAGES
Packages that are excluded by default

Constructor Detail

ShadowingClassLoader

public ShadowingClassLoader(ClassLoader enclosingClassLoader)
Create a new ShadowingClassLoader, decorating the given ClassLoader.

Parameters:
enclosingClassLoader - the ClassLoader to decorate
Method Detail

excludePackage

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

Any class whose fully-qualified name starts with the name registered here will be handled by the enclosing 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 shadowing.

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

Parameters:
className - the class name to exclude

addTransformer

public void addTransformer(ClassFileTransformer transformer)
Add the given ClassFileTransformer to the list of transformers that this ClassLoader will apply.

Parameters:
transformer - the ClassFileTransformer

copyTransformers

public void copyTransformers(ShadowingClassLoader other)
Copy all ClassFileTransformers from the given ClassLoader to the list of transformers that this ClassLoader will apply.

Parameters:
other - the ClassLoader to copy from

loadClass

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

isEligibleForShadowing

protected boolean isEligibleForShadowing(String className)
Determine whether the specified class is eligible for shadowing 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)

isClassNameExcludedFromShadowing

protected boolean isClassNameExcludedFromShadowing(String className)
Deprecated. in favor of isEligibleForShadowing(java.lang.String)

Subclasses can override this method to specify whether or not a particular class should be excluded from shadowing.

Parameters:
className - the class name to test
Returns:
whether the specified class is excluded

getResource

public URL getResource(String name)
Overrides:
getResource in class ClassLoader

getResourceAsStream

public InputStream getResourceAsStream(String name)
Overrides:
getResourceAsStream in class ClassLoader

getResources

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

The Spring Framework

Copyright © 2002-2007 The Spring Framework.