java.lang.instrument
Interface ClassFileTransformer


public interface ClassFileTransformer

This interface should be implemented by classes wishing to transform classes bytecode when defining or redefining classes.

Since:
1.5
See Also:
Instrumentation, Instrumentation.addTransformer(java.lang.instrument.ClassFileTransformer), Instrumentation.removeTransformer(java.lang.instrument.ClassFileTransformer)

Method Summary
 byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer)
          Implementation of this method transforms a class by redefining its bytecodes.
 

Method Detail

transform

byte[] transform(ClassLoader loader,
                 String className,
                 Class<?> classBeingRedefined,
                 ProtectionDomain protectionDomain,
                 byte[] classfileBuffer)
                 throws IllegalClassFormatException
Implementation of this method transforms a class by redefining its bytecodes. Once a ClassFileTransformer object registers itself to the Instrumentation object, this method will be called each time a class is defined (ClassLoader.defineClass) or redefined (Instrumentation.redefineClasses)

Parameters:
loader - the loader of the class
className - the name of the class with packages separated with "/"
classBeingRedefined - the class being redefined if it's the case, null otherwise
protectionDomain - the protection domain of the class being defined or redefined
classfileBuffer - the input byte buffer in class file format
Returns:
a class file buffer or null when no transformation has been performed
Throws:
IllegalClassFormatException - if the byte buffer does not represent a well-formed class file
See Also:
Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition[])