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 1087 2009-12-05 23:36:48Z schulte2005 $
Author:
Christian Schulte

Nested Class Summary
static interface JomcTool.Listener
          Listener interface.
 
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
static Level getDefaultLogLevel()
          Gets the default log level events are logged at.
 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(org.jomc.model.Implementation implementation)
          Gets the Java class path location of an implementation.
 String getJavaClasspathLocation(org.jomc.model.Specification specification)
          Gets the Java class path location of a specification.
 String getJavadocComment(org.jomc.model.Text text, String linebreak)
          Formats a text to a Javadoc comment.
 String getJavaGetterMethodName(org.jomc.model.Dependency dependency)
          Gets the name of a Java accessor method of a given dependency.
 String getJavaGetterMethodName(org.jomc.model.Message message)
          Gets the name of a Java accessor method of a given message.
 String getJavaGetterMethodName(org.jomc.model.Property property)
          Gets the name of a Java accessor method of a given property.
 List<String> getJavaInterfaceNames(org.jomc.model.Implementation implementation, boolean qualified)
          Gets all Java interfaces an implementation implements.
 String getJavaModifierName(org.jomc.model.Implementation implementation, org.jomc.model.Dependency dependency)
          Gets the name of a Java modifier of a dependency of a given implementation.
 String getJavaModifierName(org.jomc.model.Implementation implementation, org.jomc.model.Message message)
          Gets the name of a Java modifier of a message of a given implementation.
 String getJavaModifierName(org.jomc.model.Implementation implementation, org.jomc.model.Property property)
          Gets the name of a Java modifier for a given property of a given implementation.
 String getJavaPackageName(org.jomc.model.Implementation implementation)
          Gets the Java package name of an implementation.
 String getJavaPackageName(org.jomc.model.Specification specification)
          Gets the Java package name of a specification.
 String getJavaPackageName(org.jomc.model.SpecificationReference reference)
          Gets the Java package name of a specification reference.
 String getJavaString(String str)
          Formats a string to a Java string with unicode escapes.
 String getJavaTypeName(org.jomc.model.Argument argument)
          Gets the Java type name of an argument.
 String getJavaTypeName(org.jomc.model.Dependency dependency)
          Gets the name of a Java type of a given dependency.
 String getJavaTypeName(org.jomc.model.Implementation implementation, boolean qualified)
          Gets the Java type name of an implementation.
 String getJavaTypeName(org.jomc.model.Property property, boolean boxify)
          Gets the Java type name of a property.
 String getJavaTypeName(org.jomc.model.Specification specification, boolean qualified)
          Gets the Java type name of a specification.
 String getJavaTypeName(org.jomc.model.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.
 Level getLogLevel()
          Gets the log level of the instance.
 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.
 org.jomc.model.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.
 org.apache.velocity.VelocityContext getVelocityContext()
          Gets the velocity context used for merging templates.
 org.apache.velocity.app.VelocityEngine getVelocityEngine()
          Gets the VelocityEngine used for generating source code.
 org.apache.velocity.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(org.jomc.model.Implementation implementation)
          Gets a flag indicating if a given implementation declares a Java class.
 boolean isJavaClassDeclaration(org.jomc.model.Specification specification)
          Gets a flag indicating if a given specification declares a Java class.
 boolean isJavaDefaultPackage(org.jomc.model.Implementation implementation)
          Gets a flag indicating if the class of a given implementation is located in the Java default package.
 boolean isJavaDefaultPackage(org.jomc.model.Specification specification)
          Gets a flag indicating if the class of a given specification is located in the Java default package.
 boolean isJavaPrimitiveType(org.jomc.model.Property property)
          Gets a flag indicating if the type of a given property is a Java primitive.
 boolean isLoggable(Level level)
          Checks if a message at a given level is provided to the listeners of the instance.
protected  void log(Level level, String message, Throwable throwable)
          Notifies registered listeners.
static void setDefaultLogLevel(Level value)
          Sets the default log level events are logged at.
 void setInputEncoding(String value)
          Sets the encoding to use for reading files.
 void setLogLevel(Level value)
          Sets the log level of the instance.
 void setModules(org.jomc.model.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(org.apache.velocity.app.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
 

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.

This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the object. This is why there is no set method for the listeners property.

Returns:
The list of registered listeners.
See Also:
log(java.util.logging.Level, java.lang.String, java.lang.Throwable)

getDefaultLogLevel

public static Level getDefaultLogLevel()
Gets the default log level events are logged at.

The default log level is controlled by system property org.jomc.tools.JomcTool.defaultLogLevel holding the log level to log events at by default. If that property is not set, the WARNING default is returned.

Returns:
The log level events are logged at by default.
See Also:
getLogLevel(), Level.parse(java.lang.String)

setDefaultLogLevel

public static void setDefaultLogLevel(Level value)
Sets the default log level events are logged at.

Parameters:
value - The new default level events are logged at or null.
See Also:
getDefaultLogLevel()

getLogLevel

public Level getLogLevel()
Gets the log level of the instance.

Returns:
The log level of the instance.
See Also:
getDefaultLogLevel(), setLogLevel(java.util.logging.Level), isLoggable(java.util.logging.Level)

setLogLevel

public void setLogLevel(Level value)
Sets the log level of the instance.

Parameters:
value - The new log level of the instance or null.
See Also:
getLogLevel(), isLoggable(java.util.logging.Level)

isLoggable

public boolean isLoggable(Level level)
Checks if a message at a given level is provided to the listeners of the instance.

Parameters:
level - The level to test.
Returns:
true if messages at level are provided to the listeners of the instance; false if messages at level are not provided to the listeners of the instance.
Throws:
NullPointerException - if level is null.
See Also:
getLogLevel(), setLogLevel(java.util.logging.Level), log(java.util.logging.Level, java.lang.String, java.lang.Throwable)

getJavaPackageName

public String getJavaPackageName(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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.

getJavaInterfaceNames

public List<String> getJavaInterfaceNames(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.Implementation implementation,
                                  org.jomc.model.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(org.jomc.model.Implementation implementation,
                                  org.jomc.model.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(org.jomc.model.Implementation implementation,
                                  org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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(org.jomc.model.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 org.jomc.model.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(org.jomc.model.Modules value)
Sets the modules of the instance.

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

getVelocityEngine

public org.apache.velocity.app.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(org.apache.velocity.app.VelocityEngine value)
Sets the VelocityEngine of the instance.

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

getVelocityContext

public org.apache.velocity.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 org.apache.velocity.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 of 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 or null.
throwable - The throwable of the event or null.
Throws:
NullPointerException - if level is null.
See Also:
getListeners()


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