org.jomc.tools
Class ClassFileProcessor

Package class diagram package ClassFileProcessor
java.lang.Object
  extended by org.jomc.tools.JomcTool
      extended by org.jomc.tools.ClassFileProcessor

public class ClassFileProcessor
extends JomcTool

Processes class files.

Use cases

Version:
$Id: ClassFileProcessor.java 1562 2010-03-07 01:06:40Z schulte2005 $
Author:
Christian Schulte
See Also:
JomcTool.getModules()

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jomc.tools.JomcTool
JomcTool.Listener
 
Constructor Summary
ClassFileProcessor()
          Creates a new ClassFileProcessor instance.
ClassFileProcessor(ClassFileProcessor tool)
          Creates a new ClassFileProcessor instance taking a ClassFileProcessor instance to initialize the instance with.
 
Method Summary
 void commitModelObjects(org.jomc.model.Implementation implementation, javax.xml.bind.Marshaller marshaller, File classesDirectory)
          Commits model objects of a given implementation of the modules of the instance to class files.
 void commitModelObjects(javax.xml.bind.Marshaller marshaller, File classesDirectory)
          Commits model objects of the modules of the instance to class files.
 void commitModelObjects(org.jomc.model.Module module, javax.xml.bind.Marshaller marshaller, File classesDirectory)
          Commits model objects of a given module of the modules of the instance to class files.
 void commitModelObjects(org.jomc.model.Specification specification, javax.xml.bind.Marshaller marshaller, File classesDirectory)
          Commits model objects of a given specification of the modules of the instance to class files.
<T extends org.jomc.model.ModelObject>
T
decodeModelObject(javax.xml.bind.Unmarshaller unmarshaller, byte[] bytes, Class<T> type)
          Decodes a model object from a byte array.
 byte[] encodeModelObject(javax.xml.bind.Marshaller marshaller, javax.xml.bind.JAXBElement<? extends org.jomc.model.ModelObject> modelObject)
          Encodes a model object to a byte array.
 byte[] getClassfileAttribute(org.apache.bcel.classfile.JavaClass clazz, String attributeName)
          Gets an attribute from a java class.
 org.apache.bcel.classfile.JavaClass getJavaClass(File classFile)
          Parses a class file.
 org.apache.bcel.classfile.JavaClass getJavaClass(InputStream stream, String className)
          Parses a class file.
 org.apache.bcel.classfile.JavaClass getJavaClass(URL url, String className)
          Parses a class file.
 void setClassfileAttribute(org.apache.bcel.classfile.JavaClass clazz, String attributeName, byte[] data)
          Adds or updates an attribute in a java class.
 void transformModelObjects(org.jomc.model.Implementation implementation, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, org.apache.bcel.classfile.JavaClass classFile, List<Transformer> transformers)
          Transforms model objects of class files.
 void transformModelObjects(javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, File classesDirectory, List<Transformer> transformers)
          Transforms model objects of class files.
 void transformModelObjects(org.jomc.model.Module module, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, File classesDirectory, List<Transformer> transformers)
          Transforms model objects of class files.
 void transformModelObjects(org.jomc.model.Specification specification, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, org.apache.bcel.classfile.JavaClass classFile, List<Transformer> transformers)
          Transforms model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Implementation implementation, javax.xml.bind.Unmarshaller unmarshaller, org.apache.bcel.classfile.JavaClass classFile)
          Validates model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Module module, javax.xml.bind.Unmarshaller unmarshaller, ClassLoader classLoader)
          Validates model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Module module, javax.xml.bind.Unmarshaller unmarshaller, File classesDirectory)
          Validates model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Specification specification, javax.xml.bind.Unmarshaller unmarshaller, org.apache.bcel.classfile.JavaClass classFile)
          Validates model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(javax.xml.bind.Unmarshaller unmarshaller, ClassLoader classLoader)
          Validates model objects of class files.
 org.jomc.model.ModelValidationReport validateModelObjects(javax.xml.bind.Unmarshaller unmarshaller, File classesDirectory)
          Validates model objects of class files.
 
Methods inherited from class org.jomc.tools.JomcTool
getDefaultLogLevel, getDisplayLanguage, getInputEncoding, getJavaClasspathLocation, getJavaClasspathLocation, getJavadocComment, getJavaGetterMethodName, getJavaGetterMethodName, getJavaGetterMethodName, getJavaInterfaceNames, getJavaModifierName, getJavaModifierName, getJavaModifierName, getJavaPackageName, getJavaPackageName, getJavaPackageName, getJavaString, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getListeners, getLogLevel, getLongDate, getLongDateTime, getLongTime, getModules, getOutputEncoding, getProfile, getShortDate, getShortDateTime, getShortTime, getTemplateEncoding, getVelocityContext, getVelocityEngine, getVelocityTemplate, getYears, isJavaDefaultPackage, isJavaDefaultPackage, isJavaPrimitiveType, isLoggable, log, setDefaultLogLevel, setInputEncoding, setLogLevel, setModules, setOutputEncoding, setProfile, setTemplateEncoding, setVelocityEngine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFileProcessor

public ClassFileProcessor()
Creates a new ClassFileProcessor instance.


ClassFileProcessor

public ClassFileProcessor(ClassFileProcessor tool)
                   throws IOException
Creates a new ClassFileProcessor instance taking a ClassFileProcessor instance to initialize the instance with.

Parameters:
tool - The instance to initialize the new instance with,
Throws:
NullPointerException - if tool is null.
IOException - if copying tool fails.
Method Detail

commitModelObjects

public void commitModelObjects(javax.xml.bind.Marshaller marshaller,
                               File classesDirectory)
                        throws IOException
Commits model objects of the modules of the instance to class files.

Parameters:
marshaller - The marshaller to use for committing the model objects.
classesDirectory - The directory holding the class files.
Throws:
NullPointerException - if marshaller or classesDirectory is null.
IOException - if committing model objects fails.
See Also:
commitModelObjects(org.jomc.model.Module, javax.xml.bind.Marshaller, java.io.File), ModelContext.createMarshaller()

commitModelObjects

public void commitModelObjects(org.jomc.model.Module module,
                               javax.xml.bind.Marshaller marshaller,
                               File classesDirectory)
                        throws IOException
Commits model objects of a given module of the modules of the instance to class files.

Parameters:
module - The module to process.
marshaller - The marshaller to use for committing the model objects.
classesDirectory - The directory holding the class files.
Throws:
NullPointerException - if module, marshaller or classesDirectory is null.
IOException - if committing model objects fails.
See Also:
commitModelObjects(org.jomc.model.Specification, javax.xml.bind.Marshaller, java.io.File), commitModelObjects(org.jomc.model.Implementation, javax.xml.bind.Marshaller, java.io.File), ModelContext.createMarshaller()

commitModelObjects

public void commitModelObjects(org.jomc.model.Specification specification,
                               javax.xml.bind.Marshaller marshaller,
                               File classesDirectory)
                        throws IOException
Commits model objects of a given specification of the modules of the instance to class files.

Parameters:
specification - The specification to process.
marshaller - The marshaller to use for committing the model objects.
classesDirectory - The directory holding the class files.
Throws:
NullPointerException - if specification, marshaller or classesDirectory is null.
IOException - if committing model objects fails.
See Also:
ModelContext.createMarshaller()

commitModelObjects

public void commitModelObjects(org.jomc.model.Implementation implementation,
                               javax.xml.bind.Marshaller marshaller,
                               File classesDirectory)
                        throws IOException
Commits model objects of a given implementation of the modules of the instance to class files.

Parameters:
implementation - The implementation to process.
marshaller - The marshaller to use for committing the model objects.
classesDirectory - The directory holding the class files.
Throws:
NullPointerException - if implementation, marshaller or classesDirectory is null.
IOException - if committing model objects fails.
See Also:
ModelContext.createMarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(javax.xml.bind.Unmarshaller unmarshaller,
                                                                 File classesDirectory)
                                                          throws IOException
Validates model objects of class files.

Parameters:
unmarshaller - The unmarshaller to use for validating model objects.
classesDirectory - The directory holding the class files.
Returns:
The report of the validation.
Throws:
NullPointerException - if unmarshaller or classesDirectory is null.
IOException - if validating model objects fails.
See Also:
validateModelObjects(org.jomc.model.Module, javax.xml.bind.Unmarshaller, java.io.File), ModelContext.createUnmarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(javax.xml.bind.Unmarshaller unmarshaller,
                                                                 ClassLoader classLoader)
                                                          throws IOException
Validates model objects of class files.

Parameters:
unmarshaller - The unmarshaller to use for validating model objects.
classLoader - The class loader to search for class files.
Returns:
The report of the validation.
Throws:
NullPointerException - if unmarshaller or classLoader is null.
IOException - if validating model objects fails.
See Also:
validateModelObjects(org.jomc.model.Module, javax.xml.bind.Unmarshaller, java.lang.ClassLoader), ModelContext.createUnmarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Module module,
                                                                 javax.xml.bind.Unmarshaller unmarshaller,
                                                                 File classesDirectory)
                                                          throws IOException
Validates model objects of class files.

Parameters:
module - The module to process.
unmarshaller - The unmarshaller to use for validating model objects.
classesDirectory - The directory holding the class files.
Returns:
The report of the validation.
Throws:
NullPointerException - if module, unmarshaller or classesDirectory is null.
IOException - if validating model objects fails.
See Also:
validateModelObjects(org.jomc.model.Specification, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass), validateModelObjects(org.jomc.model.Implementation, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass), ModelContext.createUnmarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Module module,
                                                                 javax.xml.bind.Unmarshaller unmarshaller,
                                                                 ClassLoader classLoader)
                                                          throws IOException
Validates model objects of class files.

Parameters:
module - The module to process.
unmarshaller - The unmarshaller to use for validating model objects.
classLoader - The class loader to search for class files.
Returns:
The report of the validation.
Throws:
NullPointerException - if module, unmarshaller or classLoader is null.
IOException - if validating model objects fails.
See Also:
validateModelObjects(org.jomc.model.Specification, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass), validateModelObjects(org.jomc.model.Implementation, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass), ModelContext.createUnmarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Specification specification,
                                                                 javax.xml.bind.Unmarshaller unmarshaller,
                                                                 org.apache.bcel.classfile.JavaClass classFile)
                                                          throws IOException
Validates model objects of class files.

Parameters:
specification - The specification to process.
unmarshaller - The unmarshaller to use for validating model objects.
classFile - The class file to validate model objects of.
Returns:
The report of the validation.
Throws:
NullPointerException - if specification, unmarshaller or classFile is null.
IOException - if validating model objects fails.
See Also:
ModelContext.createUnmarshaller()

validateModelObjects

public org.jomc.model.ModelValidationReport validateModelObjects(org.jomc.model.Implementation implementation,
                                                                 javax.xml.bind.Unmarshaller unmarshaller,
                                                                 org.apache.bcel.classfile.JavaClass classFile)
                                                          throws IOException
Validates model objects of class files.

Parameters:
implementation - The implementation to process.
unmarshaller - The unmarshaller to use for validating model objects.
classFile - The class file to validate model objects of.
Returns:
The report of the validation.
Throws:
NullPointerException - if implementation, unmarshaller or classFile is null.
IOException - if validating model objects fails.
See Also:
ModelContext.createUnmarshaller()

transformModelObjects

public void transformModelObjects(javax.xml.bind.Marshaller marshaller,
                                  javax.xml.bind.Unmarshaller unmarshaller,
                                  File classesDirectory,
                                  List<Transformer> transformers)
                           throws IOException
Transforms model objects of class files.

Parameters:
marshaller - The marshaller to use for transforming model objects.
unmarshaller - The unmarshaller to use for transforming model objects.
classesDirectory - The directory holding the class files.
transformers - The transformers to use for transforming model objects.
Throws:
NullPointerException - if marshaller, unmarshaller, classesDirectory or transformers is null.
IOException - if transforming model objects fails.
See Also:
transformModelObjects(org.jomc.model.Module, javax.xml.bind.Marshaller, javax.xml.bind.Unmarshaller, java.io.File, java.util.List), ModelContext.createMarshaller(), ModelContext.createUnmarshaller()

transformModelObjects

public void transformModelObjects(org.jomc.model.Module module,
                                  javax.xml.bind.Marshaller marshaller,
                                  javax.xml.bind.Unmarshaller unmarshaller,
                                  File classesDirectory,
                                  List<Transformer> transformers)
                           throws IOException
Transforms model objects of class files.

Parameters:
module - The module to process.
marshaller - The marshaller to use for transforming model objects.
unmarshaller - The unmarshaller to use for transforming model objects.
classesDirectory - The directory holding the class files.
transformers - The transformers to use for transforming the model objects.
Throws:
NullPointerException - if module, marshaller, unmarshaller, classesDirectory or transformers is null.
IOException - if transforming model objects fails.
See Also:
transformModelObjects(org.jomc.model.Specification, javax.xml.bind.Marshaller, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass, java.util.List), transformModelObjects(org.jomc.model.Implementation, javax.xml.bind.Marshaller, javax.xml.bind.Unmarshaller, org.apache.bcel.classfile.JavaClass, java.util.List), ModelContext.createMarshaller(), ModelContext.createUnmarshaller()

transformModelObjects

public void transformModelObjects(org.jomc.model.Specification specification,
                                  javax.xml.bind.Marshaller marshaller,
                                  javax.xml.bind.Unmarshaller unmarshaller,
                                  org.apache.bcel.classfile.JavaClass classFile,
                                  List<Transformer> transformers)
                           throws IOException
Transforms model objects of class files.

Parameters:
specification - The specification to process.
marshaller - The marshaller to use for transforming model objects.
unmarshaller - The unmarshaller to use for transforming model objects.
classFile - The class file to transform model objects of.
transformers - The transformers to use for transforming the model objects.
Throws:
NullPointerException - if specification, marshaller, unmarshaller, classFile or transformers is null.
IOException - if transforming model objects fails.
See Also:
ModelContext.createMarshaller(), ModelContext.createUnmarshaller()

transformModelObjects

public void transformModelObjects(org.jomc.model.Implementation implementation,
                                  javax.xml.bind.Marshaller marshaller,
                                  javax.xml.bind.Unmarshaller unmarshaller,
                                  org.apache.bcel.classfile.JavaClass classFile,
                                  List<Transformer> transformers)
                           throws IOException
Transforms model objects of class files.

Parameters:
implementation - The implementation to process.
marshaller - The marshaller to use for transforming model objects.
unmarshaller - The unmarshaller to use for transforming model objects.
classFile - The class file to transform model objects of.
transformers - The transformers to use for transforming the model objects.
Throws:
NullPointerException - if implementation, marshaller, unmarshaller, classFile or transformers is null.
IOException - if transforming model objects fails.
See Also:
ModelContext.createMarshaller(), ModelContext.createUnmarshaller()

getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass(File classFile)
                                                 throws IOException
Parses a class file.

Parameters:
classFile - The class file to parse.
Returns:
The parsed class file.
Throws:
NullPointerException - if classFile is null.
IOException - if parsing classFile fails.
See Also:
JavaClass

getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass(URL url,
                                                        String className)
                                                 throws IOException
Parses a class file.

Parameters:
url - The URL of the class file to parse.
className - The name of the class at url.
Returns:
The parsed class file.
Throws:
NullPointerException - if url or className is null.
IOException - if parsing fails.
See Also:
JavaClass

getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass(InputStream stream,
                                                        String className)
                                                 throws IOException
Parses a class file.

Parameters:
stream - The stream to read the class file from.
className - The name of the class to read from stream.
Returns:
The parsed class file.
Throws:
NullPointerException - if stream or className is null.
IOException - if parsing fails.
See Also:
JavaClass

getClassfileAttribute

public byte[] getClassfileAttribute(org.apache.bcel.classfile.JavaClass clazz,
                                    String attributeName)
                             throws IOException
Gets an attribute from a java class.

Parameters:
clazz - The java class to get an attribute from.
attributeName - The name of the attribute to get.
Returns:
The value of attribute attributeName of clazz or null if no such attribute exists.
Throws:
NullPointerException - if clazz or attributeName is null.
IOException - if getting the attribute fails.
See Also:
JavaClass.getAttributes()

setClassfileAttribute

public void setClassfileAttribute(org.apache.bcel.classfile.JavaClass clazz,
                                  String attributeName,
                                  byte[] data)
                           throws IOException
Adds or updates an attribute in a java class.

Parameters:
clazz - The class to update.
attributeName - The name of the attribute to update.
data - The new data of the attribute to update the classFile with.
Throws:
NullPointerException - if clazz or attributeName is null.
IOException - if updating the class file fails.
See Also:
JavaClass.getAttributes()

encodeModelObject

public byte[] encodeModelObject(javax.xml.bind.Marshaller marshaller,
                                javax.xml.bind.JAXBElement<? extends org.jomc.model.ModelObject> modelObject)
                         throws IOException
Encodes a model object to a byte array.

Parameters:
marshaller - The marshaller to use for encoding the object.
modelObject - The model object to encode.
Returns:
GZIP compressed XML document for modelObject.
Throws:
NullPointerException - if marshaller or modelObject is null.
IOException - if encoding modelObject fails.

decodeModelObject

public <T extends org.jomc.model.ModelObject> T decodeModelObject(javax.xml.bind.Unmarshaller unmarshaller,
                                                                  byte[] bytes,
                                                                  Class<T> type)
                                                       throws IOException
Decodes a model object from a byte array.

Type Parameters:
T - The type of the decoded model object.
Parameters:
unmarshaller - The unmarshaller to use for decoding the object.
bytes - The encoded model object to decode.
type - The type of the encoded model object.
Returns:
Model object decoded from bytes.
Throws:
NullPointerException - if unmarshaller, bytes or type is null.
IOException - if decoding bytes fails.


Copyright © 2005-2010 The JOMC Project. All Rights Reserved.