attrib4j.bcel
Class AbstractBCELClassAnnotator

java.lang.Object
  |
  +--attrib4j.bcel.AbstractBCELClassAnnotator
All Implemented Interfaces:
ClassAnnotator
Direct Known Subclasses:
BCELClassAnnotator

public abstract class AbstractBCELClassAnnotator
extends java.lang.Object
implements ClassAnnotator

Author:
Mark.Pollack

Field Summary
protected  org.apache.bcel.generic.ClassGen _classGen
           
protected  org.apache.bcel.classfile.ConstantPool _constantPool
           
protected  org.apache.bcel.generic.ConstantPoolGen _constantPoolGen
           
protected  org.apache.bcel.classfile.JavaClass _javaClass
           
 
Constructor Summary
AbstractBCELClassAnnotator()
           
 
Method Summary
abstract  java.lang.Object createAttributeInstance(java.lang.String text, java.net.URLClassLoader classLoader, java.lang.String[] attributePackages)
          Create the object that will be used to store the attribute.
abstract  byte[] createBytesFromAttribute(java.lang.Object attribute)
           
protected static java.lang.Class createFromPackageSearch(java.lang.String baseClassname, java.net.URLClassLoader classloader, java.lang.String[] attributePackages)
           
protected static java.lang.Object guessParam(java.lang.Class ctorParamType, java.lang.String paramText)
          Internal routine to guess (and create) the parameter instance from the text passed in and the type it's supposed to be (from the constructor).
 void insertClassAttribute(java.lang.Object attribute)
          Associate an attribute at the class level.
 void insertFieldAttribute(java.lang.String field, java.lang.Object attribute)
          Associate an attribute at the field level.
 void insertMethodAttribute(com.sun.javadoc.MethodDoc methodDoc, java.lang.Object attribute)
          Associate an attribute at the method level. Uses the javadoc MethodDoc class as a way to define a particular method. TODO: Think about using classes from java.lang.reflect for describing the method.
protected static java.lang.String parseAttributeClassName(java.lang.String fullAttributeText)
          Internal routine to pick out a classname from text looking something like: "@attribute attrib4j.examples.attributes.DebugAttribute(true, 12)"
protected static java.lang.String[] parseAttributeParams(java.lang.String fullAttributeText)
          Internal routine to pick out parameters from text looking something like "@attribute com.javageeks.attributes.DebugAttribute(true, 12)"
 void write(java.lang.String destDir)
          Do the work of writing all the meta-data to the new .class file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classGen

protected org.apache.bcel.generic.ClassGen _classGen

_constantPool

protected org.apache.bcel.classfile.ConstantPool _constantPool

_constantPoolGen

protected org.apache.bcel.generic.ConstantPoolGen _constantPoolGen

_javaClass

protected org.apache.bcel.classfile.JavaClass _javaClass
Constructor Detail

AbstractBCELClassAnnotator

public AbstractBCELClassAnnotator()
Method Detail

createFromPackageSearch

protected static java.lang.Class createFromPackageSearch(java.lang.String baseClassname,
                                                         java.net.URLClassLoader classloader,
                                                         java.lang.String[] attributePackages)
                                                  throws AttributeException
AttributeException

guessParam

protected static java.lang.Object guessParam(java.lang.Class ctorParamType,
                                             java.lang.String paramText)
Internal routine to guess (and create) the parameter instance from the text passed in and the type it's supposed to be (from the constructor). This method handles String, Boolean, Byte, Short, Integer, Long, Float, and Double parameter types.

Parameters:
ctorParamType - The class of the positional parameter in the attribute constructor.
paramText - The string value of this paramemter as given in in the Javadoc tag.
Returns:
An instance of the correct parameter class initialized to the value specified by the parameter text.

parseAttributeClassName

protected static java.lang.String parseAttributeClassName(java.lang.String fullAttributeText)
Internal routine to pick out a classname from text looking something like: "@attribute attrib4j.examples.attributes.DebugAttribute(true, 12)"

Parameters:
fullAttributeText - The text of the attribute javadoc tag.
Returns:
The classname to be created as parsed from the javadoc tag.

parseAttributeParams

protected static java.lang.String[] parseAttributeParams(java.lang.String fullAttributeText)
Internal routine to pick out parameters from text looking something like "@attribute com.javageeks.attributes.DebugAttribute(true, 12)"

Parameters:
fullAttributeText - The text of the attribute javadoc tag.
Returns:
An array of positional parameters that will be used for for the constructor of the attribute.

createAttributeInstance

public abstract java.lang.Object createAttributeInstance(java.lang.String text,
                                                         java.net.URLClassLoader classLoader,
                                                         java.lang.String[] attributePackages)
Description copied from interface: ClassAnnotator
Create the object that will be used to store the attribute. In current implementations this can be the object as created from the text, which in turn will be serialized into the .classfile (BCELFactory) or just the text itself (BCELTextFactory).

Specified by:
createAttributeInstance in interface ClassAnnotator
Parameters:
text - The string describing the attribute.
classLoader - The class loader user to resolve the attribute class
attributePackages - The list of package names to prefix the attribute search
Returns:
Object The attribute object for storage in the bytecode or elsewhere.

createBytesFromAttribute

public abstract byte[] createBytesFromAttribute(java.lang.Object attribute)

insertClassAttribute

public void insertClassAttribute(java.lang.Object attribute)
Associate an attribute at the class level.

Specified by:
insertClassAttribute in interface ClassAnnotator
Parameters:
attribute - The attribute, should be serializable.
See Also:
ClassAnnotator.insertClassAttribute(java.lang.Object)

insertFieldAttribute

public void insertFieldAttribute(java.lang.String field,
                                 java.lang.Object attribute)
Associate an attribute at the field level.

Specified by:
insertFieldAttribute in interface ClassAnnotator
Parameters:
field - The name of the field.
attribute - The attribute, should be serializable.
See Also:
ClassAnnotator.insertFieldAttribute(java.lang.String, java.lang.Object)

insertMethodAttribute

public void insertMethodAttribute(com.sun.javadoc.MethodDoc methodDoc,
                                  java.lang.Object attribute)
Associate an attribute at the method level. Uses the javadoc MethodDoc class as a way to define a particular method. TODO: Think about using classes from java.lang.reflect for describing the method.

Specified by:
insertMethodAttribute in interface ClassAnnotator
Parameters:
methodDoc - The particular method in the class to associate an attribute.
attribute - The attribute, should be serializable.
See Also:
ClassAnnotator.insertMethodAttribute(com.sun.javadoc.MethodDoc, java.lang.Object)

write

public void write(java.lang.String destDir)
Description copied from interface: ClassAnnotator
Do the work of writing all the meta-data to the new .class file.

Specified by:
write in interface ClassAnnotator
Parameters:
destDir - where the new .class file will be located.


Copyright © 2002-2003 Mark Pollack. All Rights Reserved.