org.hibernate.bytecode.buildtime.spi
Class AbstractInstrumenter

java.lang.Object
  extended by org.hibernate.bytecode.buildtime.spi.AbstractInstrumenter
All Implemented Interfaces:
Instrumenter
Direct Known Subclasses:
JavassistInstrumenter

public abstract class AbstractInstrumenter
extends Object
implements Instrumenter

Provides the basic templating of how instrumentation should occur.


Nested Class Summary
protected  class AbstractInstrumenter.CustomFieldFilter
          Allows control over what exactly to transform.
 
Nested classes/interfaces inherited from interface org.hibernate.bytecode.buildtime.spi.Instrumenter
Instrumenter.Options
 
Field Summary
protected  Logger logger
           
protected  Instrumenter.Options options
           
 
Constructor Summary
AbstractInstrumenter(Logger logger, Instrumenter.Options options)
          Creates the basic instrumentation strategy.
 
Method Summary
protected  boolean checkMagic(File file, long magic)
           
 void execute(Set<File> files)
          The main instrumentation entry point.
protected abstract  ClassDescriptor getClassDescriptor(byte[] byecode)
          Given the bytecode of a java class, retrieve the descriptor for that class.
protected abstract  ClassTransformer getClassTransformer(ClassDescriptor descriptor, Set classNames)
          Create class transformer for the class.
protected  boolean isClassFile(File file)
          Does this file represent a compiled class?
protected  boolean isJarFile(File file)
          Does this file represent a zip file of some format?
protected  void processClassFile(File file, Set<String> classNames)
          Process a class file.
protected  void processFile(File file, Set<String> classNames)
          Actually process the file by applying instrumentation transformations to any classes it contains.
protected  void processJarFile(File file, Set<String> classNames)
          Process an archive file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Logger logger

options

protected final Instrumenter.Options options
Constructor Detail

AbstractInstrumenter

public AbstractInstrumenter(Logger logger,
                            Instrumenter.Options options)
Creates the basic instrumentation strategy.

Parameters:
logger - The bridge to the environment's logging system.
options - User-supplied options.
Method Detail

getClassDescriptor

protected abstract ClassDescriptor getClassDescriptor(byte[] byecode)
                                               throws Exception
Given the bytecode of a java class, retrieve the descriptor for that class.

Parameters:
byecode - The class bytecode.
Returns:
The class's descriptor
Throws:
Exception - Indicates problems access the bytecode.

getClassTransformer

protected abstract ClassTransformer getClassTransformer(ClassDescriptor descriptor,
                                                        Set classNames)
Create class transformer for the class.

Parameters:
descriptor - The descriptor of the class to be instrumented.
classNames - The names of all classes to be instrumented; the "pipeline" if you will.
Returns:
The transformer for the given class; may return null to indicate that transformation should be skipped (ala already instrumented).

execute

public void execute(Set<File> files)
The main instrumentation entry point. Given a set of files, perform instrumentation on each discovered class file.

Specified by:
execute in interface Instrumenter
Parameters:
files - The files.

isClassFile

protected final boolean isClassFile(File file)
                             throws IOException
Does this file represent a compiled class?

Parameters:
file - The file to check.
Returns:
True if the file is a class; false otherwise.
Throws:
IOException - Indicates problem access the file.

isJarFile

protected final boolean isJarFile(File file)
                           throws IOException
Does this file represent a zip file of some format?

Parameters:
file - The file to check.
Returns:
True if the file is n archive; false otherwise.
Throws:
IOException - Indicates problem access the file.

checkMagic

protected final boolean checkMagic(File file,
                                   long magic)
                            throws IOException
Throws:
IOException

processFile

protected void processFile(File file,
                           Set<String> classNames)
                    throws Exception
Actually process the file by applying instrumentation transformations to any classes it contains.

Again, just like with collectClassNames(java.io.File, java.util.Set) this method can handle both class and archive files.

Parameters:
file - The file to process.
classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
Throws:
Exception - Indicates an issue either access files or applying the transformations.

processClassFile

protected void processClassFile(File file,
                                Set<String> classNames)
                         throws Exception
Process a class file. Delegated to from processFile(java.io.File, java.util.Set) in the case of a class file.

Parameters:
file - The class file to process.
classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
Throws:
Exception - Indicates an issue either access files or applying the transformations.

processJarFile

protected void processJarFile(File file,
                              Set<String> classNames)
                       throws Exception
Process an archive file. Delegated to from processFile(java.io.File, java.util.Set) in the case of an archive file.

Parameters:
file - The archive file to process.
classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
Throws:
Exception - Indicates an issue either access files or applying the transformations.


Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.