org.springframework.instrument.classloading.tomcat
Class TomcatInstrumentableClassLoader

java.lang.Object
  extended by WebappClassLoader
      extended by org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader

public class TomcatInstrumentableClassLoader
extends WebappClassLoader

Extension of Tomcat's default class loader which adds instrumentation to loaded classes without the need to use a VM-wide agent.

To be registered using a Loader tag in Tomcat's Context definition in the server.xml file, with the Spring-provided "spring-tomcat-weaver.jar" file deployed into Tomcat's "server/lib" (for Tomcat 5.x) or "lib" (for Tomcat 6.x) directory. The required configuration tag looks as follows:

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

Typically used in combination with a ReflectiveLoadTimeWeaver defined in the Spring application context. The addTransformer and getThrowawayClassLoader methods mirror the corresponding methods in the LoadTimeWeaver interface, as expected by ReflectiveLoadTimeWeaver.

See the PetClinic sample application for a full example of this ClassLoader in action.

NOTE: Requires Apache Tomcat version 5.0 or higher.

Since:
2.0
Author:
Costin Leau, Juergen Hoeller
See Also:
addTransformer(java.lang.instrument.ClassFileTransformer), getThrowawayClassLoader(), ReflectiveLoadTimeWeaver

Field Summary
private static java.lang.String CLASS_SUFFIX
           
private  WeavingTransformer weavingTransformer
          Use an internal WeavingTransformer
 
Constructor Summary
TomcatInstrumentableClassLoader()
          Create a new TomcatInstrumentableClassLoader using the current context class loader.
TomcatInstrumentableClassLoader(java.lang.ClassLoader parent)
          Create a new TomcatInstrumentableClassLoader with the supplied class loader as parent.
 
Method Summary
 void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
          Delegate for LoadTimeWeaver's addTransformer method.
private static java.lang.Class findCommonAncestor(java.lang.Class one, java.lang.Class two)
           
protected  ResourceEntry findResourceInternal(java.lang.String name, java.lang.String path)
           
 java.lang.ClassLoader getThrowawayClassLoader()
          Delegate for LoadTimeWeaver's getThrowawayClassLoader method.
private static void shallowCopyFieldState(java.lang.Object src, java.lang.Object dest)
          Given the source object and the destination, which must be the same class or a subclass, copy all fields, including inherited fields.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_SUFFIX

private static final java.lang.String CLASS_SUFFIX
See Also:
Constant Field Values

weavingTransformer

private final WeavingTransformer weavingTransformer
Use an internal WeavingTransformer

Constructor Detail

TomcatInstrumentableClassLoader

public TomcatInstrumentableClassLoader()
Create a new TomcatInstrumentableClassLoader using the current context class loader.

See Also:
TomcatInstrumentableClassLoader(ClassLoader)

TomcatInstrumentableClassLoader

public TomcatInstrumentableClassLoader(java.lang.ClassLoader parent)
Create a new TomcatInstrumentableClassLoader with the supplied class loader as parent.

Parameters:
parent - the parent ClassLoader to be used
Method Detail

addTransformer

public void addTransformer(java.lang.instrument.ClassFileTransformer transformer)
Delegate for LoadTimeWeaver's addTransformer method. Typically called through ReflectiveLoadTimeWeaver.

See Also:
LoadTimeWeaver.addTransformer(java.lang.instrument.ClassFileTransformer), ReflectiveLoadTimeWeaver

getThrowawayClassLoader

public java.lang.ClassLoader getThrowawayClassLoader()
Delegate for LoadTimeWeaver's getThrowawayClassLoader method. Typically called through ReflectiveLoadTimeWeaver.

See Also:
LoadTimeWeaver.getThrowawayClassLoader(), ReflectiveLoadTimeWeaver

findResourceInternal

protected ResourceEntry findResourceInternal(java.lang.String name,
                                             java.lang.String path)

toString

public java.lang.String toString()

shallowCopyFieldState

private static void shallowCopyFieldState(java.lang.Object src,
                                          java.lang.Object dest)
                                   throws java.lang.IllegalArgumentException
Given the source object and the destination, which must be the same class or a subclass, copy all fields, including inherited fields. Designed to work on objects with public no-arg constructors.

Throws:
java.lang.IllegalArgumentException - if arguments are incompatible or either is null

findCommonAncestor

private static java.lang.Class findCommonAncestor(java.lang.Class one,
                                                  java.lang.Class two)
                                           throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException