org.jomc.tools
Class JomcTool

Package class diagram package JomcTool
java.lang.Object
  extended by org.jomc.tools.JomcTool
Direct Known Subclasses:
JavaBundles, JavaClasses, JavaSources

public abstract class JomcTool
extends Object

Base tool class.

Version:
$Id: JomcTool.java 739 2009-10-06 01:54:08Z schulte2005 $
Author:
Christian Schulte

Nested Class Summary
static interface JomcTool.Listener
          Listener interface.
 
Field Summary
private  String inputEncoding
          The encoding to use for reading files.
private  List<JomcTool.Listener> listeners
          The listeners of the instance.
private  ModelManager modelManager
          The model manager of the instance.
private  Modules modules
          The modules of the instance.
private static byte[] NO_BYTES
          Empty byte array.
private  String outputEncoding
          The encoding to use for writing files.
private  String profile
          The profile of the instance.
private static String TEMPLATE_PREFIX
          The prefix of the template location.
private  String templateEncoding
          The encoding to use for reading templates.
private static String VELOCITY_RESOURCE_LOADER
          Name of the velocity classpath resource loader implementation.
private  VelocityEngine velocityEngine
          VelocityEngine of the generator.
 
Constructor Summary
JomcTool()
          Creates a new JomcTool instance.
JomcTool(JomcTool tool)
          Creates a new JomcTool instance taking a JomcTool instance to initialize the new instance with.
 
Method Summary
 String getDisplayLanguage(String language)
          Gets the display language of a given language code.
 String getInputEncoding()
          Gets the encoding to use for reading files.
 String getJavaClasspathLocation(Implementation implementation)
          Gets the Java class path location of an implementation.
 String getJavaClasspathLocation(Specification specification)
          Gets the Java class path location of a specification.
 String getJavadocComment(Text text, String linebreak)
          Formats a text to a Javadoc comment.
 String getJavaGetterMethodName(Dependency dependency)
          Gets the name of a Java accessor method of a given dependency.
 String getJavaGetterMethodName(Message message)
          Gets the name of a Java accessor method of a given message.
 String getJavaGetterMethodName(Property property)
          Gets the name of a Java accessor method of a given property.
 List<String> getJavaInterfaces(Implementation implementation, boolean qualified)
          Gets all Java interfaces an implementation implements.
 String getJavaModifierName(Implementation implementation, Dependency dependency)
          Gets the name of a Java modifier of a dependency of a given implementation.
 String getJavaModifierName(Implementation implementation, Message message)
          Gets the name of a Java modifier of a message of a given implementation.
 String getJavaModifierName(Implementation implementation, Property property)
          Gets the name of a Java modifier for a given property of a given implementation.
 String getJavaPackageName(Implementation implementation)
          Gets the Java package name of an implementation.
 String getJavaPackageName(Specification specification)
          Gets the Java package name of a specification.
 String getJavaPackageName(SpecificationReference reference)
          Gets the Java package name of a specification reference.
private  String getJavaPackageName(String identifier)
           
 String getJavaString(String str)
          Formats a string to a Java string with unicode escapes.
 String getJavaTypeName(Argument argument)
          Gets the Java type name of an argument.
 String getJavaTypeName(Dependency dependency)
          Gets the name of a Java type of a given dependency.
 String getJavaTypeName(Implementation implementation, boolean qualified)
          Gets the Java type name of an implementation.
 String getJavaTypeName(Property property, boolean boxify)
          Gets the Java type name of a property.
 String getJavaTypeName(Specification specification, boolean qualified)
          Gets the Java type name of a specification.
 String getJavaTypeName(SpecificationReference reference, boolean qualified)
          Gets the name of a Java type of a given specification reference.
 List<JomcTool.Listener> getListeners()
          Gets the list of registered listeners.
 String getLongDate(Calendar calendar)
          Formats a calendar instance to a string.
 String getLongDateTime(Calendar calendar)
          Formats a calendar instance to a string.
 String getLongTime(Calendar calendar)
          Formats a calendar instance to a string.
private  String getMessage(String key, Object args)
           
 ModelManager getModelManager()
          Gets the model manager of the instance.
 Modules getModules()
          Gets the modules of the instance.
 String getOutputEncoding()
          Gets the encoding to use for writing files.
 String getProfile()
          Gets the profile of the instance.
 String getShortDate(Calendar calendar)
          Formats a calendar instance to a string.
 String getShortDateTime(Calendar calendar)
          Formats a calendar instance to a string.
 String getShortTime(Calendar calendar)
          Formats a calendar instance to a string.
 String getTemplateEncoding()
          Gets the encoding to use for reading templates.
 VelocityContext getVelocityContext()
          Gets the velocity context used for merging templates.
 VelocityEngine getVelocityEngine()
          Gets the VelocityEngine used for generating source code.
 Template getVelocityTemplate(String templateName)
          Gets a velocity template for a given name.
 String getYears(Calendar start, Calendar end)
          Gets a string describing the range of years for given calendars.
 boolean isJavaClassDeclaration(Implementation implementation)
          Gets a flag indicating if a given implementation declares a Java class.
 boolean isJavaClassDeclaration(Specification specification)
          Gets a flag indicating if a given specification declares a Java class.
 boolean isJavaDefaultPackage(Implementation implementation)
          Gets a flag indicating if the class of a given implementation is located in the Java default package.
 boolean isJavaDefaultPackage(Specification specification)
          Gets a flag indicating if the class of a given specification is located in the Java default package.
 boolean isJavaPrimitiveType(Property property)
          Gets a flag indicating if the type of a given property is a Java primitive.
protected  void log(Level level, String message, Throwable throwable)
          Notifies registered listeners.
 void setInputEncoding(String value)
          Sets the encoding to use for reading files.
 void setModelManager(ModelManager value)
          Sets the model manager of the instance.
 void setModules(Modules value)
          Sets the modules of the instance.
 void setOutputEncoding(String value)
          Sets the encoding to use for writing files.
 void setProfile(String value)
          Sets the profile of the instance.
 void setTemplateEncoding(String value)
          Sets the encoding to use for reading templates.
 void setVelocityEngine(VelocityEngine value)
          Sets the VelocityEngine of the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_BYTES

private static final byte[] NO_BYTES
Empty byte array.


TEMPLATE_PREFIX

private static final String TEMPLATE_PREFIX
The prefix of the template location.


VELOCITY_RESOURCE_LOADER

private static final String VELOCITY_RESOURCE_LOADER
Name of the velocity classpath resource loader implementation.


modules

private Modules modules
The modules of the instance.


modelManager

private ModelManager modelManager
The model manager of the instance.


velocityEngine

private VelocityEngine velocityEngine
VelocityEngine of the generator.


templateEncoding

private String templateEncoding
The encoding to use for reading templates.


inputEncoding

private String inputEncoding
The encoding to use for reading files.


outputEncoding

private String outputEncoding
The encoding to use for writing files.


profile

private String profile
The profile of the instance.


listeners

private List<JomcTool.Listener> listeners
The listeners of the instance.

Constructor Detail

JomcTool

public JomcTool()
Creates a new JomcTool instance.


JomcTool

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

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

getListeners

public List<JomcTool.Listener> getListeners()
Gets the list of registered listeners.

Returns:
The list of registered listeners.

getJavaPackageName

public String getJavaPackageName(Specification specification)
Gets the Java package name of a specification.

Parameters:
specification - The specification to get the Java package name of.
Returns:
The Java package name of specification.
Throws:
NullPointerException - if specification is null.

getJavaTypeName

public String getJavaTypeName(Specification specification,
                              boolean qualified)
Gets the Java type name of a specification.

Parameters:
specification - The specification to get the Java type name of.
qualified - true to return the fully qualified type name (with package name prepended); false to return the short type name (without package name prepended).
Returns:
The Java type name of specification.
Throws:
NullPointerException - if specification is null.

getJavaClasspathLocation

public String getJavaClasspathLocation(Specification specification)
Gets the Java class path location of a specification.

Parameters:
specification - The specification to return the Java class path location of.
Returns:
the Java class path location of specification.
Throws:
NullPointerException - if specification is null.

getJavaPackageName

public String getJavaPackageName(SpecificationReference reference)
Gets the Java package name of a specification reference.

Parameters:
reference - The specification reference to get the Java package name of.
Returns:
The Java package name of reference.
Throws:
NullPointerException - if reference is null.

getJavaTypeName

public String getJavaTypeName(SpecificationReference reference,
                              boolean qualified)
Gets the name of a Java type of a given specification reference.

Parameters:
reference - The specification reference to get a Java type name of.
qualified - true to return the fully qualified type name (with package name prepended); false to return the short type name (without package name prepended).
Returns:
The Java type name of reference.
Throws:
NullPointerException - if reference is null.

getJavaPackageName

public String getJavaPackageName(Implementation implementation)
Gets the Java package name of an implementation.

Parameters:
implementation - The implementation to get the Java package name of.
Returns:
The Java package name of implementation.
Throws:
NullPointerException - if implementation is null.

getJavaTypeName

public String getJavaTypeName(Implementation implementation,
                              boolean qualified)
Gets the Java type name of an implementation.

Parameters:
implementation - The implementation to get the Java type name of.
qualified - true to return the fully qualified type name (with package name prepended); false to return the short type name (without package name prepended).
Returns:
The Java type name of implementation.
Throws:
NullPointerException - if implementation is null.

getJavaClasspathLocation

public String getJavaClasspathLocation(Implementation implementation)
Gets the Java class path location of an implementation.

Parameters:
implementation - The implementation to return the Java class path location of.
Returns:
The Java class path location of implementation.
Throws:
NullPointerException - if implementation is null.

getJavaInterfaces

public List<String> getJavaInterfaces(Implementation implementation,
                                      boolean qualified)
Gets all Java interfaces an implementation implements.

Parameters:
implementation - The implementation to get all implemented Java interfaces of.
qualified - true to return the fully qualified type names (with package name prepended); false to return the short type names (without package name prepended).
Returns:
All interfaces implemented by implementation.
Throws:
NullPointerException - if implementation is null.

getJavaTypeName

public String getJavaTypeName(Argument argument)
Gets the Java type name of an argument.

Parameters:
argument - The argument to get the Java type name of.
Returns:
The Java type name of argument.
Throws:
NullPointerException - if argument is null.

getJavaTypeName

public String getJavaTypeName(Property property,
                              boolean boxify)
Gets the Java type name of a property.

Parameters:
property - The property to get the Java type name of.
boxify - true to return the name of the Java wrapper class when the type is a Java primitive type; false to return the exact binary name (unboxed name) of the Java type.
Returns:
The Java type name of property.
Throws:
NullPointerException - if property is null.

isJavaPrimitiveType

public boolean isJavaPrimitiveType(Property property)
Gets a flag indicating if the type of a given property is a Java primitive.

Parameters:
property - The property to query.
Returns:
true if the type of property is a Java primitive; false if not.
Throws:
NullPointerException - if property is null.

getJavaGetterMethodName

public String getJavaGetterMethodName(Property property)
Gets the name of a Java accessor method of a given property.

Parameters:
property - The property to get a Java accessor method name of.
Returns:
The Java accessor method name of property.
Throws:
NullPointerException - if property is null.

getJavaTypeName

public String getJavaTypeName(Dependency dependency)
Gets the name of a Java type of a given dependency.

Parameters:
dependency - The dependency to get a dependency Java type name of.
Returns:
The Java type name of dependency.
Throws:
NullPointerException - if dependency is null.

getJavaGetterMethodName

public String getJavaGetterMethodName(Dependency dependency)
Gets the name of a Java accessor method of a given dependency.

Parameters:
dependency - The dependency to get a Java accessor method name of.
Returns:
The Java accessor method name of dependency.
Throws:
NullPointerException - if dependency is null.

getJavaGetterMethodName

public String getJavaGetterMethodName(Message message)
Gets the name of a Java accessor method of a given message.

Parameters:
message - The message to get a Java accessor method name of.
Returns:
The Java accessor method name of message.
Throws:
NullPointerException - if message is null.

getJavaModifierName

public String getJavaModifierName(Implementation implementation,
                                  Dependency dependency)
Gets the name of a Java modifier of a dependency of a given implementation.

Parameters:
implementation - The implementation to get a dependency Java modifier name of.
dependency - The dependency to get a Java modifier name of.
Returns:
The Java modifier name of dependency of implementation.
Throws:
NullPointerException - if implementation or dependency is null.

getJavaModifierName

public String getJavaModifierName(Implementation implementation,
                                  Message message)
Gets the name of a Java modifier of a message of a given implementation.

Parameters:
implementation - The implementation to get a message Java modifier name of.
message - The message to get a Java modifier name of.
Returns:
The Java modifier name of message of implementation.
Throws:
NullPointerException - if implementation or message is null.

getJavaModifierName

public String getJavaModifierName(Implementation implementation,
                                  Property property)
Gets the name of a Java modifier for a given property of a given implementation.

Parameters:
implementation - The implementation declaring property.
property - The property to get a Java modifier name for.
Returns:
The Java modifier name for property of implementation.
Throws:
NullPointerException - if implementation or property is null.

getJavadocComment

public String getJavadocComment(Text text,
                                String linebreak)
Formats a text to a Javadoc comment.

Parameters:
text - The text to format to a Javadoc comment.
linebreak - The text to replace line breaks with.
Returns:
text formatted as a Javadoc comment.
Throws:
NullPointerException - if text or linebreak is null.

getJavaString

public String getJavaString(String str)
Formats a string to a Java string with unicode escapes.

Parameters:
str - The string to format to a Java string or null.
Returns:
str formatted as a Java string or null.

isJavaClassDeclaration

public boolean isJavaClassDeclaration(Specification specification)
Gets a flag indicating if a given specification declares a Java class.

Parameters:
specification - The specification to test.
Returns:
true if specification is declaring the Java class with name specification.getClazz(); false if specification does not declare that class.
Throws:
NullPointerException - if specification is null.

isJavaClassDeclaration

public boolean isJavaClassDeclaration(Implementation implementation)
Gets a flag indicating if a given implementation declares a Java class.

Parameters:
implementation - The implementation to test.
Returns:
true if implementation is declaring the Java class with name implementation.getClazz(); false if implementation.getClazz() is null or implementation does not declare that class.
Throws:
NullPointerException - if implementation is null.

isJavaDefaultPackage

public boolean isJavaDefaultPackage(Specification specification)
Gets a flag indicating if the class of a given specification is located in the Java default package.

Parameters:
specification - The specification to test.
Returns:
true if the class of specification is located in the Java default package; false if not.
Throws:
NullPointerException - if specification is null.

isJavaDefaultPackage

public boolean isJavaDefaultPackage(Implementation implementation)
Gets a flag indicating if the class of a given implementation is located in the Java default package.

Parameters:
implementation - The implementation to test.
Returns:
true if the class of implementation is located in the Java default package; false if not.
Throws:
NullPointerException - if implementation is null.

getDisplayLanguage

public String getDisplayLanguage(String language)
Gets the display language of a given language code.

Parameters:
language - The language code to get the display language of.
Returns:
The display language of language.
Throws:
NullPointerException - if language is null.

getShortDate

public String getShortDate(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Date of calendar formatted using a short format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.SHORT

getLongDate

public String getLongDate(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Date of calendar formatted using a long format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.LONG

getShortTime

public String getShortTime(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Time of calendar formatted using a short format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.SHORT

getLongTime

public String getLongTime(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Time of calendar formatted using a long format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.LONG

getShortDateTime

public String getShortDateTime(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Date and time of calendar formatted using a short format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.SHORT

getLongDateTime

public String getLongDateTime(Calendar calendar)
Formats a calendar instance to a string.

Parameters:
calendar - The calendar to format.
Returns:
Date and time of calendar formatted using a long format style pattern.
Throws:
NullPointerException - if calendar is null.
See Also:
DateFormat.LONG

getYears

public String getYears(Calendar start,
                       Calendar end)
Gets a string describing the range of years for given calendars.

Parameters:
start - The start of the range.
end - The end of the range.
Returns:
Formatted range of the years of start and end.
Throws:
NullPointerException - if start or end is null.

getModules

public Modules getModules()
Gets the modules of the instance.

Returns:
The modules of the instance.
See Also:
setModules(org.jomc.model.Modules)

setModules

public void setModules(Modules value)
Sets the modules of the instance.

Parameters:
value - The new modules of the instance.
See Also:
getModules()

getModelManager

public ModelManager getModelManager()
Gets the model manager of the instance.

Returns:
The model manager of the instance.
See Also:
setModelManager(org.jomc.model.ModelManager)

setModelManager

public void setModelManager(ModelManager value)
Sets the model manager of the instance.

Parameters:
value - The new model manager of the instance.
See Also:
getModelManager()

getVelocityEngine

public VelocityEngine getVelocityEngine()
Gets the VelocityEngine used for generating source code.

Returns:
The VelocityEngine used for generating source code.
Throws:
IllegalStateException - if initializing a new velocity engine fails.
See Also:
setVelocityEngine(org.apache.velocity.app.VelocityEngine)

setVelocityEngine

public void setVelocityEngine(VelocityEngine value)
Sets the VelocityEngine of the instance.

Parameters:
value - The new VelocityEngine of the instance.
See Also:
getVelocityEngine()

getVelocityContext

public VelocityContext getVelocityContext()
Gets the velocity context used for merging templates.

Returns:
The velocity context used for merging templates.

getTemplateEncoding

public String getTemplateEncoding()
Gets the encoding to use for reading templates.

Returns:
The encoding to use for reading templates.
See Also:
setTemplateEncoding(java.lang.String)

setTemplateEncoding

public void setTemplateEncoding(String value)
Sets the encoding to use for reading templates.

Parameters:
value - The encoding to use for reading templates.
See Also:
getTemplateEncoding()

getInputEncoding

public String getInputEncoding()
Gets the encoding to use for reading files.

Returns:
The encoding to use for reading files.
See Also:
setInputEncoding(java.lang.String)

setInputEncoding

public void setInputEncoding(String value)
Sets the encoding to use for reading files.

Parameters:
value - The encoding to use for reading files.
See Also:
getInputEncoding()

getOutputEncoding

public String getOutputEncoding()
Gets the encoding to use for writing files.

Returns:
The encoding to use for writing files.
See Also:
setOutputEncoding(java.lang.String)

setOutputEncoding

public void setOutputEncoding(String value)
Sets the encoding to use for writing files.

Parameters:
value - The encoding to use for writing files.
See Also:
getOutputEncoding()

getProfile

public String getProfile()
Gets the profile of the instance.

Returns:
The profile of the instance.
See Also:
setProfile(java.lang.String)

setProfile

public void setProfile(String value)
Sets the profile of the instance.

Parameters:
value - The profile of the instance.
See Also:
getProfile()

getVelocityTemplate

public Template getVelocityTemplate(String templateName)
                             throws IOException
Gets a velocity template for a given name.

This method returns the template corresponding to the profile of the instance. If that template is not found, the template corresponding to the default profile is returned so that only templates differing from the default templates need to be provided when exchanging templates.

Parameters:
templateName - The name of the template to get.
Returns:
The template matching templateName.
Throws:
NullPointerException - if templateName is null.
IOException - if getting the template fails.
See Also:
getProfile(), getTemplateEncoding()

log

protected void log(Level level,
                   String message,
                   Throwable throwable)
Notifies registered listeners.

Parameters:
level - The level of the event.
message - The message of the event.
throwable - The throwable of the event.
See Also:
getListeners()

getJavaPackageName

private String getJavaPackageName(String identifier)

getMessage

private String getMessage(String key,
                          Object args)


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