Top Description Fields Constructors Methods
org.springframework.instrument.classloading

public Class ReflectiveLoadTimeWeaver

extends Object
implements LoadTimeWeaver
Class Inheritance
All Implemented Interfaces
org.springframework.instrument.classloading.LoadTimeWeaver
Imports
java.lang.instrument.ClassFileTransformer, java.lang.reflect.Method, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.DecoratingClassLoader, .OverridingClassLoader, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils

LoadTimeWeaver which uses reflection to delegate to an underlying ClassLoader with well-known transformation hooks. The underlying ClassLoader is expected to support the following weaving methods (as defined in the LoadTimeWeaver interface):

Please note that the above methods must reside in a class that is publicly accessible, although the class itself does not have to be visible to the application's class loader.

The reflective nature of this LoadTimeWeaver is particularly useful when the underlying ClassLoader implementation is loaded in a different class loader itself (such as the application server's class loader which is not visible to the web application). There is no direct API dependency between this LoadTimeWeaver adapter and the underlying ClassLoader, just a 'loose' method contract.

This is the LoadTimeWeaver to use e.g. with the Resin application server version 3.1+.

Authors
Costin Leau, Juergen Hoeller
Since
2.0
See Also
addTransformer(java.lang.instrument.ClassFileTransformer), getThrowawayClassLoader(), SimpleThrowawayClassLoader

Field Summary

Modifier and TypeField and Description
private static final String
private final Method
private final ClassLoader
private static final String
private final Method
private static final Log

Constructor Summary

AccessConstructor and Description
public
ReflectiveLoadTimeWeaver()

Create a new ReflectiveLoadTimeWeaver for the current context class loader, which needs to support the required weaving methods.

public
ReflectiveLoadTimeWeaver(ClassLoader
the ClassLoader to delegate to for weaving (must support the required weaving methods).
classLoader
)

Create a new SimpleLoadTimeWeaver for the given class loader.

Method Summary

Modifier and TypeMethod and Description
public void
addTransformer(ClassFileTransformer
the ClassFileTransformer to add
transformer
)

Implements org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Add a ClassFileTransformer to be applied by this LoadTimeWeaver.
public ClassLoader
getInstrumentableClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

Return a ClassLoader that supports instrumentation through AspectJ-style load-time weaving based on user-defined ClassFileTransformers.
public ClassLoader
getThrowawayClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getThrowawayClassLoader.

Return a throwaway ClassLoader, enabling classes to be loaded and inspected without affecting the parent ClassLoader.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ADD_TRANSFORMER_METHOD_NAMEback to summary
private static final String ADD_TRANSFORMER_METHOD_NAME
addTransformerMethodback to summary
private final Method addTransformerMethod
classLoaderback to summary
private final ClassLoader classLoader
GET_THROWAWAY_CLASS_LOADER_METHOD_NAMEback to summary
private static final String GET_THROWAWAY_CLASS_LOADER_METHOD_NAME
getThrowawayClassLoaderMethodback to summary
private final Method getThrowawayClassLoaderMethod
Annotations
@Nullable
loggerback to summary
private static final Log logger

Constructor Detail

ReflectiveLoadTimeWeaverback to summary
public ReflectiveLoadTimeWeaver()

Create a new ReflectiveLoadTimeWeaver for the current context class loader, which needs to support the required weaving methods.

ReflectiveLoadTimeWeaverback to summary
public ReflectiveLoadTimeWeaver(ClassLoader classLoader)

Create a new SimpleLoadTimeWeaver for the given class loader.

Parameters
classLoader:ClassLoader

the ClassLoader to delegate to for weaving (must support the required weaving methods).

Exceptions
IllegalStateException:
if the supplied ClassLoader does not support the required weaving methods

Method Detail

addTransformerback to summary
public void addTransformer(ClassFileTransformer transformer)

Implements org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.addTransformer.

Add a ClassFileTransformer to be applied by this LoadTimeWeaver.

Parameters
transformer:ClassFileTransformer

the ClassFileTransformer to add

Annotations
@Override
getInstrumentableClassLoaderback to summary
public ClassLoader getInstrumentableClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.getInstrumentableClassLoader.

Return a ClassLoader that supports instrumentation through AspectJ-style load-time weaving based on user-defined ClassFileTransformers.

May be the current ClassLoader, or a ClassLoader created by this LoadTimeWeaver instance.

Returns:ClassLoader

the ClassLoader which will expose instrumented classes according to the registered transformers

Annotations
@Override
getThrowawayClassLoaderback to summary
public ClassLoader getThrowawayClassLoader()

Implements org.springframework.instrument.classloading.LoadTimeWeaver.getThrowawayClassLoader.

Doc from org.springframework.instrument.classloading.LoadTimeWeaver.getThrowawayClassLoader.

Return a throwaway ClassLoader, enabling classes to be loaded and inspected without affecting the parent ClassLoader.

Should not return the same instance of the ClassLoader returned from an invocation of getInstrumentableClassLoader().

Returns:ClassLoader

a temporary throwaway ClassLoader; should return a new instance for each call, with no existing state

Annotations
@Override