Top Description Inners Fields Constructors Methods
org.hibernate.bytecode.buildtime

public abstract Class AbstractInstrumenter

extends Object
implements Instrumenter
Class Inheritance
All Implemented Interfaces
org.hibernate.bytecode.buildtime.Instrumenter
Known Direct Subclasses
org.hibernate.bytecode.buildtime.CGLIBInstrumenter, org.hibernate.bytecode.buildtime.JavassistInstrumenter
Imports
java.util.Iterator, .Set, .HashSet, java.util.zip.ZipEntry, .ZipInputStream, .ZipOutputStream, .CRC32, java.io.File, .DataInputStream, .ByteArrayInputStream, .IOException, .FileInputStream, .OutputStream, .FileOutputStream, org.hibernate.bytecode.util.ByteCodeHelper, .ClassDescriptor, .FieldFilter, org.hibernate.bytecode.ClassTransformer

Provides the basic templating of how instrumentation should occur.
Author
Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
AbstractInstrumenter.CustomFieldFilter

Allows control over what exacctly to transform.

private static interface
AbstractInstrumenter.ZipEntryHandler

General strategy contract for handling entries in an archive file.

private static class
AbstractInstrumenter.ZipFileProcessor

Applies ZipEntryHandler strategies to the entries of an archive file.

Field Summary

Modifier and TypeField and Description
private static final int
protected final Logger
protected final Instrumenter.Options
private static final int

Constructor Summary

AccessConstructor and Description
public
AbstractInstrumenter(Logger
The bridge to the environment's logging system.
logger
,
Instrumenter.Options
User-supplied options.
options
)

Creates the basic instrumentation strategy.

Method Summary

Modifier and TypeMethod and Description
protected final boolean
checkMagic(File file, long magic)

private void
collectClassNames(File
The file from which to extract class metadata (descriptor).
file
,
final Set<E>
The collected class name collection.
classNames
)

Extract the names of classes from file, adding them to the classNames collection.

public void
execute(Set<E>
The files.
files
)

Implements org.hibernate.bytecode.buildtime.Instrumenter.execute.

The main instrumentation entry point.
protected abstract ClassDescriptor

Returns:

The class's descriptor
getClassDescriptor
(byte[]
The class bytecode.
byecode
)

Given the bytecode of a java class, retrieve the descriptor for that class.

protected abstract ClassTransformer

Returns:

The transformer for the given class; may return null to indicate that transformation should be skipped (ala already instrumented).
getClassTransformer
(ClassDescriptor
The descriptor of the class to be instrumented.
descriptor
,
Set<E>
The names of all classes to be instrumented; the "pipeline" if you will.
classNames
)

Create class transformer for the class.

protected final boolean

Returns:

True if the file is a class; false otherwise.
isClassFile
(File
The file to check.
file
)

Does this file represent a compiled class?

protected final boolean

Returns:

True if the file is n archive; false otherwise.
isJarFile
(File
The file to check.
file
)

Does this file represent a zip file of some format?

protected void
processClassFile(File
The class file to process.
file
,
Set<E>
The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
classNames
)

Process a class file.

protected void
processFile(File
The file to process.
file
,
Set<E>
The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
classNames
)

Actually process the file by applying instrumentation transformations to any classes it contains.

protected void
processJarFile(final File
The archive file to process.
file
,
final Set<E>
The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
classNames
)

Process an archive file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLASS_MAGICback to summary
private static final int CLASS_MAGIC
loggerback to summary
protected final Logger logger
optionsback to summary
protected final Instrumenter.Options options
ZIP_MAGICback to summary
private static final int ZIP_MAGIC

Constructor Detail

AbstractInstrumenterback to summary
public AbstractInstrumenter(Logger logger, Instrumenter.Options options)

Creates the basic instrumentation strategy.

Parameters
logger:Logger

The bridge to the environment's logging system.

options:Instrumenter.Options

User-supplied options.

Method Detail

checkMagicback to summary
protected final boolean checkMagic(File file, long magic) throws IOException
collectClassNamesback to summary
private void collectClassNames(File file, final Set<E> classNames) throws Exception

Extract the names of classes from file, adding them to the classNames collection.

IMPL NOTE : file here may be either a class file or a jar. If a jar, all entries in the jar file are processed.

Parameters
file:File

The file from which to extract class metadata (descriptor).

classNames:Set<E>

The collected class name collection.

Exceptions
Exception:
indicates problems accessing the file or its contents.
executeback to summary
public void execute(Set<E> files)

Implements org.hibernate.bytecode.buildtime.Instrumenter.execute.

The main instrumentation entry point. Given a set of files, perform instrumentation on each discovered class file.

Parameters
files:Set<E>

The files.

getClassDescriptorback to summary
protected abstract ClassDescriptor getClassDescriptor(byte[] byecode) throws Exception

Given the bytecode of a java class, retrieve the descriptor for that class.

Parameters
byecode:byte[]

The class bytecode.

Returns:ClassDescriptor

The class's descriptor

Exceptions
Exception:
Indicates problems access the bytecode.
getClassTransformerback to summary
protected abstract ClassTransformer getClassTransformer(ClassDescriptor descriptor, Set<E> classNames)

Create class transformer for the class.

Parameters
descriptor:ClassDescriptor

The descriptor of the class to be instrumented.

classNames:Set<E>

The names of all classes to be instrumented; the "pipeline" if you will.

Returns:ClassTransformer

The transformer for the given class; may return null to indicate that transformation should be skipped (ala already instrumented).

isClassFileback to summary
protected final boolean isClassFile(File file) throws IOException

Does this file represent a compiled class?

Parameters
file:File

The file to check.

Returns:boolean

True if the file is a class; false otherwise.

Exceptions
IOException:
Indicates problem access the file.
isJarFileback to summary
protected final boolean isJarFile(File file) throws IOException

Does this file represent a zip file of some format?

Parameters
file:File

The file to check.

Returns:boolean

True if the file is n archive; false otherwise.

Exceptions
IOException:
Indicates problem access the file.
processClassFileback to summary
protected void processClassFile(File file, Set<E> classNames) throws Exception

Process a class file. Delegated to from processFile in the case of a class file.

Parameters
file:File

The class file to process.

classNames:Set<E>

The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.

Exceptions
Exception:
Indicates an issue either access files or applying the transformations.
processFileback to summary
protected void processFile(File file, Set<E> classNames) throws Exception

Actually process the file by applying instrumentation transformations to any classes it contains.

Again, just like with collectClassNames this method can handle both class and archive files.

Parameters
file:File

The file to process.

classNames:Set<E>

The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.

Exceptions
Exception:
Indicates an issue either access files or applying the transformations.
processJarFileback to summary
protected void processJarFile(final File file, final Set<E> classNames) throws Exception

Process an archive file. Delegated to from processFile in the case of an archive file.

Parameters
file:File

The archive file to process.

classNames:Set<E>

The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.

Exceptions
Exception:
Indicates an issue either access files or applying the transformations.
org.hibernate.bytecode.buildtime back to summary

protected Class AbstractInstrumenter.CustomFieldFilter

extends Object
implements FieldFilter
Class Inheritance
  • java.lang.Object
  • org.hibernate.bytecode.buildtime.AbstractInstrumenter.CustomFieldFilter
All Implemented Interfaces
org.hibernate.bytecode.util.FieldFilter

Allows control over what exacctly to transform.

Field Summary

Modifier and TypeField and Description
private final Set<E>
private final ClassDescriptor

Constructor Summary

AccessConstructor and Description
public
CustomFieldFilter(ClassDescriptor descriptor, Set<E> classNames)

Method Summary

Modifier and TypeMethod and Description
public boolean
shouldInstrumentField(String
The name of the class currently being processed
className
,
String
The name of the field being checked.
fieldName
)

Implements org.hibernate.bytecode.util.FieldFilter.shouldInstrumentField.

Should this field definition be instrumented?
public boolean
shouldTransformFieldAccess(String
The class currently being transformed.
transformingClassName
,
String
The name of the class owning this field being checked.
fieldOwnerClassName
,
String
The name of the field being checked.
fieldName
)

Implements org.hibernate.bytecode.util.FieldFilter.shouldTransformFieldAccess.

Should we instrument *access to* the given field.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNamesback to summary
private final Set<E> classNames
descriptorback to summary
private final ClassDescriptor descriptor

Constructor Detail

CustomFieldFilterback to summary
public CustomFieldFilter(ClassDescriptor descriptor, Set<E> classNames)

Method Detail

shouldInstrumentFieldback to summary
public boolean shouldInstrumentField(String className, String fieldName)

Implements org.hibernate.bytecode.util.FieldFilter.shouldInstrumentField.

Doc from org.hibernate.bytecode.util.FieldFilter.shouldInstrumentField.

Should this field definition be instrumented?

Parameters
className:String

The name of the class currently being processed

fieldName:String

The name of the field being checked.

Returns:boolean

True if we should instrument this field.

shouldTransformFieldAccessback to summary
public boolean shouldTransformFieldAccess(String transformingClassName, String fieldOwnerClassName, String fieldName)

Implements org.hibernate.bytecode.util.FieldFilter.shouldTransformFieldAccess.

Doc from org.hibernate.bytecode.util.FieldFilter.shouldTransformFieldAccess.

Should we instrument *access to* the given field. This differs from shouldInstrumentField in that here we are talking about a particular usage of a field.

Parameters
transformingClassName:String

The class currently being transformed.

fieldOwnerClassName:String

The name of the class owning this field being checked.

fieldName:String

The name of the field being checked.

Returns:boolean

True if this access should be transformed.

org.hibernate.bytecode.buildtime back to summary

private Interface AbstractInstrumenter.ZipEntryHandler


General strategy contract for handling entries in an archive file.

Method Summary

Modifier and TypeMethod and Description
public void
handleEntry(ZipEntry
The archive file entry.
entry
,
byte[] byteCode)

Apply strategy to the given archive entry.

Method Detail

handleEntryback to summary
public void handleEntry(ZipEntry entry, byte[] byteCode) throws Exception

Apply strategy to the given archive entry.

Parameters
entry:ZipEntry

The archive file entry.

org.hibernate.bytecode.buildtime back to summary

private Class AbstractInstrumenter.ZipFileProcessor

extends Object
Class Inheritance
  • java.lang.Object
  • org.hibernate.bytecode.buildtime.AbstractInstrumenter.ZipFileProcessor

Applies ZipEntryHandler strategies to the entries of an archive file.

Field Summary

Modifier and TypeField and Description
private final AbstractInstrumenter.ZipEntryHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
process(File file)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryHandlerback to summary
private final AbstractInstrumenter.ZipEntryHandler entryHandler

Constructor Detail

ZipFileProcessorback to summary
public ZipFileProcessor(AbstractInstrumenter.ZipEntryHandler entryHandler)

Method Detail

processback to summary
public void process(File file) throws Exception