org.openbp.cockpit.template.standard
Class JavaSrcTemplate

java.lang.Object
  extended by org.openbp.common.template.TemplateBase
      extended by org.openbp.cockpit.template.standard.JavaSrcTemplate
Direct Known Subclasses:
ActivitySrcTemplate, ProcessSrcJavaTemplate

public abstract class JavaSrcTemplate
extends TemplateBase

Base class for Java source code templates. Input: Visual items. Note that we do not define the generate method (which creates the JavaTemplateWriter), we just provide methods to call from the generate method.

Author:
Heiko Erhardt

Constructor Summary
JavaSrcTemplate()
          Constructor.
 
Method Summary
protected  java.lang.String adverb(java.lang.String s)
          Returns an engish adverb for the given substantive.
protected  java.lang.String createComment(DisplayObject o)
          Creates a comment for the given object.
protected  java.lang.String createComment(DisplayObject o, java.lang.String text)
          Creates a comment for the given object.
protected  java.lang.String determineJavaType(JavaTemplateWriter w, DataTypeItem dataType)
          Determines the Java type of the given data type item.
protected  void errMsg(PrintNameProvider o, java.lang.String msg)
          Displays an error message to stdout, preceeded by the fully qualified name of the supplied object.
protected  void errMsg(java.lang.String msg)
          Displays an error message to stdout, preceeded by the fully qualified name of the current item.
protected  java.lang.String extractUnqualifiedName(JavaTemplateWriter w, java.lang.String qualifiedName)
          Extracts the unqualified name from the given class name.
protected  void printFileHeader(JavaTemplateWriter w)
          Prints the file header of the source code file.
protected  java.lang.String removeDot(java.lang.String s)
          Removes a trailing dot if present.
protected  java.lang.String singular(java.lang.String s)
          Returns the singular name of the given type name description string.
 
Methods inherited from class org.openbp.common.template.TemplateBase
addResultFileInfo, callTemplate, generate, getOutputDir, getProperties, getProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaSrcTemplate

public JavaSrcTemplate()
Constructor.

Method Detail

printFileHeader

protected void printFileHeader(JavaTemplateWriter w)
                        throws java.lang.Exception
Prints the file header of the source code file. The method prints the placeholders for package name ("@[package]@") and imports ("@[imports]@") and defines the placeholders.

Parameters:
w - Source file writer
Throws:
java.lang.Exception - On error

createComment

protected java.lang.String createComment(DisplayObject o,
                                         java.lang.String text)
Creates a comment for the given object. The comments contains - if defined - the display name and the description of the item and the supplied text. If no display name and description are given, the method will try to guess a display name from the object name.

Parameters:
o - Object to describe
text - Text to print in the line after the display name or null
Returns:
The generated comment contains regular text only and no comment characters (start of comment, leading starts, end of comment etc.). The last character of the comment is always a newline.

createComment

protected java.lang.String createComment(DisplayObject o)
Creates a comment for the given object. The comments contains - if defined - the display name and the description of the item. If no display name and description are given, the method will try to guess a display name from the object name.

Parameters:
o - Object to describe
Returns:
The generated comment contains regular text only and no comment characters (start of comment, leading starts, end of comment etc.). The last character of the comment is always a newline.

determineJavaType

protected java.lang.String determineJavaType(JavaTemplateWriter w,
                                             DataTypeItem dataType)
Determines the Java type of the given data type item. Reduces fully qualified type names to primitive type names if possible. Otherwise returns the unqualified type name after registering the type name as import.

Parameters:
w - Source file writer
dataType - Data type
Returns:
The type name to use for the member variable declaration.

extractUnqualifiedName

protected java.lang.String extractUnqualifiedName(JavaTemplateWriter w,
                                                  java.lang.String qualifiedName)
Extracts the unqualified name from the given class name. The method will automatically add the class name to the import list of the writer if it is fully qualified.

Parameters:
w - Source file writer
qualifiedName - Qualified or unqualified name
Returns:
The unqualified name

singular

protected java.lang.String singular(java.lang.String s)
Returns the singular name of the given type name description string. The following forms are recognized:
"list/map/table of 'type'" returns "'type'"
"'type' list/map/table" returns "'type'"
"'type's" returns "'type'"
otherwise returns 's'

Parameters:
s - String to inspect
Returns:
The singular type name

removeDot

protected java.lang.String removeDot(java.lang.String s)
Removes a trailing dot if present.

Parameters:
s - String to inspect
Returns:
The result string

adverb

protected java.lang.String adverb(java.lang.String s)
Returns an engish adverb for the given substantive.

Parameters:
s - The substantive
Returns:
'an' or 'a' dependant if the substantive starts with a vocal

errMsg

protected void errMsg(PrintNameProvider o,
                      java.lang.String msg)
Displays an error message to stdout, preceeded by the fully qualified name of the supplied object.

Parameters:
o - Display object or null for the current item
msg - Error messsage

errMsg

protected void errMsg(java.lang.String msg)
Displays an error message to stdout, preceeded by the fully qualified name of the current item.

Parameters:
msg - Error messsage


Copyright © 2011. All Rights Reserved.