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

public Class WeavingTransformer

extends Object
Class Inheritance
Imports
java.lang.instrument.ClassFileTransformer, .IllegalClassFormatException, java.security.ProtectionDomain, java.util.ArrayList, .List, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

ClassFileTransformer-based weaver, allowing for a list of transformers to be applied on a class byte array. Normally used inside class loaders.

Note

This class is deliberately implemented for minimal external dependencies, since it is included in weaver jars (to be deployed into application servers).

Authors
Rod Johnson, Costin Leau, Juergen Hoeller
Since
2.0

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final List<ClassFileTransformer>

Constructor Summary

AccessConstructor and Description
public
WeavingTransformer(ClassLoader
the ClassLoader to build a transformer for
classLoader
)

Create a new WeavingTransformer for the given class loader.

Method Summary

Modifier and TypeMethod and Description
public void
addTransformer(ClassFileTransformer
the class file transformer to register
transformer
)

Add a class file transformer to be applied by this weaver.

public byte[]

Returns:

(possibly transformed) class byte definition
transformIfNecessary
(String
the full qualified name of the class in dot format (i.e. some.package.SomeClass)
className
,
byte[]
class byte definition
bytes
)

Apply transformation on a given class byte definition.

public byte[]

Returns:

(possibly transformed) class byte definition
transformIfNecessary
(String
the full qualified name of the class in dot format (i.e. some.package.SomeClass)
className
,
String
class name internal name in / format (i.e. some/package/SomeClass)
internalName
,
byte[]
class byte definition
bytes
,
ProtectionDomain
protection domain to be used (can be null)
pd
)

Apply transformation on a given class byte definition.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderback to summary
private final ClassLoader classLoader
Annotations
@Nullable
transformersback to summary
private final List<ClassFileTransformer> transformers

Constructor Detail

WeavingTransformerback to summary
public WeavingTransformer(ClassLoader classLoader)

Create a new WeavingTransformer for the given class loader.

Parameters
classLoader:ClassLoader

the ClassLoader to build a transformer for

Method Detail

addTransformerback to summary
public void addTransformer(ClassFileTransformer transformer)

Add a class file transformer to be applied by this weaver.

Parameters
transformer:ClassFileTransformer

the class file transformer to register

transformIfNecessaryback to summary
public byte[] transformIfNecessary(String className, byte[] bytes)

Apply transformation on a given class byte definition. The method will always return a non-null byte array (if no transformation has taken place the array content will be identical to the original one).

Parameters
className:String

the full qualified name of the class in dot format (i.e. some.package.SomeClass)

bytes:byte[]

class byte definition

Returns:byte[]

(possibly transformed) class byte definition

transformIfNecessaryback to summary
public byte[] transformIfNecessary(String className, String internalName, byte[] bytes, ProtectionDomain pd)

Apply transformation on a given class byte definition. The method will always return a non-null byte array (if no transformation has taken place the array content will be identical to the original one).

Parameters
className:String

the full qualified name of the class in dot format (i.e. some.package.SomeClass)

internalName:String

class name internal name in / format (i.e. some/package/SomeClass)

bytes:byte[]

class byte definition

pd:ProtectionDomain

protection domain to be used (can be null)

Returns:byte[]

(possibly transformed) class byte definition