org.jomc.tools
Class JavaClasses

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

public class JavaClasses
extends JomcTool

Manages Java classes.

Use cases

Version:
$Id: JavaClasses.java 644 2009-10-02 16:37:57Z 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
JavaClasses()
          Creates a new JavaClasses instance.
JavaClasses(JavaClasses tool)
          Creates a new JavaClasses instance taking a JavaClasses instance to initialize the instance with.
 
Method Summary
 void commitClasses(File classesDirectory)
          Commits meta-data of the modules of the instance to compiled Java classes.
 void commitClasses(Implementation implementation, File classesDirectory)
          Commits meta-data of a given implementation of the modules of the instance to compiled Java classes.
 void commitClasses(Module module, File classesDirectory)
          Commits meta-data of a given module of the modules of the instance to compiled Java classes.
 void commitClasses(Specification specification, File classesDirectory)
          Commits meta-data of a given specification of the modules of the instance to compiled Java classes.
<T extends ModelObject>
T
decodeModelObject(byte[] bytes, Class<T> type)
          Decodes a model object from a byte array.
 byte[] encodeModelObject(JAXBElement<? extends ModelObject> modelObject)
          Encodes a model object to a byte array.
 byte[] getClassfileAttribute(JavaClass clazz, String attributeName)
          Gets an attribute from a java class.
 JavaClass getJavaClass(File classFile)
          Parses a class file.
 JavaClass getJavaClass(InputStream stream, String className)
          Parses a class file.
 JavaClass getJavaClass(URL url, String className)
          Parses a class file.
private  String getMessage(String key, Object args)
           
 void setClassfileAttribute(JavaClass clazz, String attributeName, byte[] data)
          Adds or updates an attribute in a java class.
 void transformClasses(File classesDirectory, Transformer transformer)
          Transforms committed meta-data of compiled Java classes of the modules of the instance.
 void transformClasses(Implementation implementation, JavaClass javaClass, Transformer transformer)
          Transforms committed meta-data of compiled Java classes of a given implementation of the modules of the instance.
 void transformClasses(Module module, File classesDirectory, Transformer transformer)
          Transforms committed meta-data of compiled Java classes of a given module of the modules of the instance.
 void transformClasses(Specification specification, JavaClass javaClass, Transformer transformer)
          Transforms committed meta-data of compiled Java classes of a given specification of the modules of the instance.
 void validateClasses(ClassLoader classLoader)
          Validates compiled Java classes against the modules of the instance.
 void validateClasses(File classesDirectory)
          Validates compiled Java classes against the modules of the instance.
 void validateClasses(Implementation implementation, JavaClass javaClass)
          Validates compiled Java classes against a given implementation of the modules of the instance.
 void validateClasses(Module module, ClassLoader classLoader)
          Validates compiled Java classes against a given module of the modules of the instance.
 void validateClasses(Module module, File classesDirectory)
          Validates compiled Java classes against a given module of the modules of the instance.
 void validateClasses(Specification specification, JavaClass javaClass)
          Validates compiled Java classes against a given specification of the modules of the instance.
 
Methods inherited from class org.jomc.tools.JomcTool
getDisplayLanguage, getInputEncoding, getJavaClasspathLocation, getJavaClasspathLocation, getJavadocComment, getJavaGetterMethodName, getJavaGetterMethodName, getJavaGetterMethodName, getJavaInterfaces, getJavaModifierName, getJavaModifierName, getJavaModifierName, getJavaPackageName, getJavaPackageName, getJavaPackageName, getJavaString, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getJavaTypeName, getListeners, getLongDate, getLongDateTime, getLongTime, getModelManager, getModules, getOutputEncoding, getProfile, getShortDate, getShortDateTime, getShortTime, getTemplateEncoding, getVelocityContext, getVelocityEngine, getVelocityTemplate, getYears, isJavaClassDeclaration, isJavaClassDeclaration, isJavaDefaultPackage, isJavaDefaultPackage, isJavaPrimitiveType, log, setInputEncoding, setModelManager, 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

JavaClasses

public JavaClasses()
Creates a new JavaClasses instance.


JavaClasses

public JavaClasses(JavaClasses tool)
Creates a new JavaClasses instance taking a JavaClasses instance to initialize the instance with.

Parameters:
tool - The instance to initialize the new instance with,
Method Detail

commitClasses

public void commitClasses(File classesDirectory)
                   throws IOException
Commits meta-data of the modules of the instance to compiled Java classes.

Parameters:
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if classesDirectory is null.
IOException - if committing meta-data fails.
See Also:
commitClasses(org.jomc.model.Module, java.io.File)

commitClasses

public void commitClasses(Module module,
                          File classesDirectory)
                   throws IOException
Commits meta-data of a given module of the modules of the instance to compiled Java classes.

Parameters:
module - The module to process.
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if module or classesDirectory is null.
IOException - if committing meta-data fails.
See Also:
commitClasses(org.jomc.model.Specification, java.io.File), commitClasses(org.jomc.model.Implementation, java.io.File)

commitClasses

public void commitClasses(Specification specification,
                          File classesDirectory)
                   throws IOException
Commits meta-data of a given specification of the modules of the instance to compiled Java classes.

Parameters:
specification - The specification to process.
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if specification or classesDirectory is null.
IOException - if committing meta-data fails.

commitClasses

public void commitClasses(Implementation implementation,
                          File classesDirectory)
                   throws IOException
Commits meta-data of a given implementation of the modules of the instance to compiled Java classes.

Parameters:
implementation - The implementation to process.
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if implementation or classesDirectory is null.
IOException - if committing meta-data fails.

validateClasses

public void validateClasses(File classesDirectory)
                     throws IOException,
                            ModelException
Validates compiled Java classes against the modules of the instance.

Parameters:
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if classesDirectory is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.
See Also:
validateClasses(org.jomc.model.Module, java.io.File)

validateClasses

public void validateClasses(ClassLoader classLoader)
                     throws IOException,
                            ModelException
Validates compiled Java classes against the modules of the instance.

Parameters:
classLoader - The class loader to search for classes.
Throws:
NullPointerException - if classLoader is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.
See Also:
validateClasses(org.jomc.model.Module, java.lang.ClassLoader)

validateClasses

public void validateClasses(Module module,
                            File classesDirectory)
                     throws IOException,
                            ModelException
Validates compiled Java classes against a given module of the modules of the instance.

Parameters:
module - The module to process.
classesDirectory - The directory holding the compiled class files.
Throws:
NullPointerException - if module or classesDirectory is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.
See Also:
validateClasses(org.jomc.model.Specification, org.apache.bcel.classfile.JavaClass), validateClasses(org.jomc.model.Implementation, org.apache.bcel.classfile.JavaClass)

validateClasses

public void validateClasses(Module module,
                            ClassLoader classLoader)
                     throws IOException,
                            ModelException
Validates compiled Java classes against a given module of the modules of the instance.

Parameters:
module - The module to process.
classLoader - The class loader to search for classes.
Throws:
NullPointerException - if module or classLoader is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.
See Also:
validateClasses(org.jomc.model.Specification, org.apache.bcel.classfile.JavaClass), validateClasses(org.jomc.model.Implementation, org.apache.bcel.classfile.JavaClass)

validateClasses

public void validateClasses(Specification specification,
                            JavaClass javaClass)
                     throws IOException,
                            ModelException
Validates compiled Java classes against a given specification of the modules of the instance.

Parameters:
specification - The specification to process.
javaClass - The class to validate.
Throws:
NullPointerException - if specification or javaClass is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.

validateClasses

public void validateClasses(Implementation implementation,
                            JavaClass javaClass)
                     throws IOException,
                            ModelException
Validates compiled Java classes against a given implementation of the modules of the instance.

Parameters:
implementation - The implementation to process.
javaClass - The class to validate.
Throws:
NullPointerException - if implementation or javaClass is null.
IOException - if reading class files fails.
ModelException - if invalid classes are found.

transformClasses

public void transformClasses(File classesDirectory,
                             Transformer transformer)
                      throws IOException,
                             TransformerException
Transforms committed meta-data of compiled Java classes of the modules of the instance.

Parameters:
classesDirectory - The directory holding the compiled class files.
transformer - The transformer to use for transforming the classes.
Throws:
NullPointerException - if classesDirectory or transformer is null.
IOException - if accessing class files fails.
TransformerException - if transforming class files fails.
See Also:
transformClasses(org.jomc.model.Module, java.io.File, javax.xml.transform.Transformer)

transformClasses

public void transformClasses(Module module,
                             File classesDirectory,
                             Transformer transformer)
                      throws IOException,
                             TransformerException
Transforms committed meta-data of compiled Java classes of a given module of the modules of the instance.

Parameters:
module - The module to process.
classesDirectory - The directory holding the compiled class files.
transformer - The transformer to use for transforming the classes.
Throws:
NullPointerException - if module, classesDirectory or transformer is null.
IOException - if accessing class files fails.
TransformerException - if transforming class files fails.
See Also:
transformClasses(org.jomc.model.Specification, org.apache.bcel.classfile.JavaClass, javax.xml.transform.Transformer), transformClasses(org.jomc.model.Implementation, org.apache.bcel.classfile.JavaClass, javax.xml.transform.Transformer)

transformClasses

public void transformClasses(Specification specification,
                             JavaClass javaClass,
                             Transformer transformer)
                      throws IOException,
                             TransformerException
Transforms committed meta-data of compiled Java classes of a given specification of the modules of the instance.

Parameters:
specification - The specification to process.
javaClass - The java class to process.
transformer - The transformer to use for transforming the classes.
Throws:
NullPointerException - if specification, javaClass or transformer is null.
IOException - if accessing class files fails.
TransformerException - if transforming class files fails.

transformClasses

public void transformClasses(Implementation implementation,
                             JavaClass javaClass,
                             Transformer transformer)
                      throws TransformerException,
                             IOException
Transforms committed meta-data of compiled Java classes of a given implementation of the modules of the instance.

Parameters:
implementation - The implementation to process.
javaClass - The java class to process.
transformer - The transformer to use for transforming the classes.
Throws:
NullPointerException - if implementation, javaClass or transformer is null.
IOException - if accessing class files fails.
TransformerException - if transforming class files fails.

getJavaClass

public 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.

getJavaClass

public 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.

getJavaClass

public 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.

getClassfileAttribute

public byte[] getClassfileAttribute(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.

setClassfileAttribute

public void setClassfileAttribute(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.

encodeModelObject

public byte[] encodeModelObject(JAXBElement<? extends ModelObject> modelObject)
                         throws IOException
Encodes a model object to a byte array.

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

decodeModelObject

public <T extends ModelObject> T decodeModelObject(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:
bytes - The encoded model object to decode.
type - The type of the encoded model object.
Returns:
Model object decoded from bytes.
Throws:
NullPointerException - if bytes or type is null.
IOException - if decoding bytes fails.

getMessage

private String getMessage(String key,
                          Object args)


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