org.openbp.cockpit.template.standard
Class ProcessSrcJavaTemplate

java.lang.Object
  extended by org.openbp.common.template.TemplateBase
      extended by org.openbp.cockpit.template.standard.JavaSrcTemplate
          extended by org.openbp.cockpit.template.standard.ProcessSrcJavaTemplate

public class ProcessSrcJavaTemplate
extends JavaSrcTemplate

Process source code templates. Input: Process items.

Author:
Heiko Erhardt

Field Summary
protected  java.util.Map allNodes
          List of all nodes that have been encountered yet.
protected  InitialNode currentInitialNode
          Initial node that corresponds to the method
protected  java.util.Map executionPathNodes
          List of nodes that have been encountered in the current execution path, i. e. in the current block or its parent blocks.
protected  ProcessItem process
          Process
protected  JavaTemplateWriter w
          Source file writer
 
Constructor Summary
ProcessSrcJavaTemplate()
          Constructor.
 
Method Summary
protected  void addDataLinkVariable(DataLink link)
          Defines a method-local variable representing a data link.
protected  java.lang.String constructDataLinkVariableDeclaration(java.lang.String name, DataTypeItem dataType)
          Constructs the declaration for a data link variable.
protected  boolean containsPathNode(Node nodeToSearch, NodeSocket socket)
           
protected  java.lang.String determineClassName()
          Returns the fully qualified class name to use for the process class.
protected  java.lang.String expandParametrizedExpression(java.lang.String expression, NodeSocket socket)
          Expands parameters in an expression, substituting parameter names for their actual values.
protected  java.lang.String expandParametrizedExpression(java.lang.String expression, NodeSocket entrySocket, NodeSocket exitSocket)
          Expands parameters in an expression, substituting parameter names for their actual values.
protected  Node findJoiningNode(DecisionNode decisionNode, NodeSocket yesSocket, NodeSocket noSocket)
          Finds the node that joins the 'then' and the 'else' part of a decison node.
 void generate(java.lang.Object[] templateArgs)
          This method is called when the template executes.
protected  NodeSocket getNamedSocket(Node node, java.lang.String name)
          Gets a socket by its name.
protected  java.lang.String getParamValue(NodeSocket socket, java.lang.String paramName)
          Obtains the value for a named parameter.
protected  java.lang.String makeVariableName(DescriptionObject o)
          Produces a syntactically correct variable name from an arbitrary object.
protected  java.lang.String obtainExpression(java.lang.String expression, java.lang.String desiredLanguage, PrintNameProvider owner)
          Obtains an expression for this source language from the given string.
protected  void printActivityNode(ActivityNode node, NodeSocket entrySocket, NodeSocket exitSocket)
          Prints the activity node code.
protected  void printAsssignment(java.lang.String targetName, java.lang.String sourceName)
          Prints a variable asssignment.
protected  void printClassCode()
          Prints the class comment.
protected  void printDecisionNodeCondition(DecisionNode node, NodeSocket entrySocket)
          Prints the decision node condition.
protected  void printDecisionNodeElse(DecisionNode node, NodeSocket noSocket, Node joinNode)
          Prints the decision node else.
protected  void printDecisionNodeThen(DecisionNode node, NodeSocket yesSocket, Node joinNode)
          Prints the decision node then.
protected  void printExecution(NodeSocket startSocket, Node stopNode)
          Prints an execution path starting with the supplied start socket.
protected  void printFile()
          Performs the generation.
protected  void printFinalNode(FinalNode node, NodeSocket entrySocket)
          Prints the final node code.
protected  void printGlobal(ProcessVariable param)
          Prints the declaration of a process variable.
protected  void printInitialNode(InitialNode node, NodeSocket exitSocket)
          Prints the initial node code.
protected  void printMethod(InitialNode initialNode)
          Prints a method for each initial node.
protected  void printMethodBody(InitialNode initialNode, FinalNode finalNode)
          Prints the method body.
protected  void printMethodFooter(InitialNode initialNode, FinalNode finalNode)
          Prints the method footer.
protected  void printMethodHeader(InitialNode initialNode, FinalNode finalNode)
          Prints the method header including the parameter list.
protected  void printMethods()
          Prints a method for each initial node.
protected  void printProcessVariables()
          Prints declarations of process variables.
protected  Node skipDecisionNodeBranches(DecisionNode decisionNode)
          Skips decision node branches.
 
Methods inherited from class org.openbp.cockpit.template.standard.JavaSrcTemplate
adverb, createComment, createComment, determineJavaType, errMsg, errMsg, extractUnqualifiedName, printFileHeader, removeDot, singular
 
Methods inherited from class org.openbp.common.template.TemplateBase
addResultFileInfo, callTemplate, getOutputDir, getProperties, getProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

process

protected ProcessItem process
Process


w

protected JavaTemplateWriter w
Source file writer


currentInitialNode

protected InitialNode currentInitialNode
Initial node that corresponds to the method


executionPathNodes

protected java.util.Map executionPathNodes
List of nodes that have been encountered in the current execution path, i. e. in the current block or its parent blocks. (maps Node objects to themselves).


allNodes

protected java.util.Map allNodes
List of all nodes that have been encountered yet. Used to detect jumps between independant paths of execution (which is not allowed). (maps Node objects to themselves).

Constructor Detail

ProcessSrcJavaTemplate

public ProcessSrcJavaTemplate()
Constructor.

Method Detail

generate

public void generate(java.lang.Object[] templateArgs)
              throws java.lang.Exception
This method is called when the template executes.

Specified by:
generate in class TemplateBase
Parameters:
templateArgs - Template arguments provided by the caller (null in this case)
Throws:
java.lang.Exception - On error

determineClassName

protected java.lang.String determineClassName()
Returns the fully qualified class name to use for the process class.


printFile

protected void printFile()
                  throws java.lang.Exception
Performs the generation.

Throws:
java.lang.Exception - On error

printClassCode

protected void printClassCode()
                       throws java.lang.Exception
Prints the class comment.

Throws:
java.lang.Exception - On error

printProcessVariables

protected void printProcessVariables()
                              throws java.lang.Exception
Prints declarations of process variables.

Throws:
java.lang.Exception - On error

printGlobal

protected void printGlobal(ProcessVariable param)
                    throws java.lang.Exception
Prints the declaration of a process variable.

Parameters:
param - Process variable to declare
Throws:
java.lang.Exception - On error

addDataLinkVariable

protected void addDataLinkVariable(DataLink link)
Defines a method-local variable representing a data link.

Parameters:
link - Data link to define

constructDataLinkVariableDeclaration

protected java.lang.String constructDataLinkVariableDeclaration(java.lang.String name,
                                                                DataTypeItem dataType)
Constructs the declaration for a data link variable.

Parameters:
name - Name of the variable
dataType - Data type of the variable
Returns:
The statement

printMethods

protected void printMethods()
                     throws java.lang.Exception
Prints a method for each initial node.

Throws:
java.lang.Exception - On error

printMethod

protected void printMethod(InitialNode initialNode)
                    throws java.lang.Exception
Prints a method for each initial node.

Parameters:
initialNode - Initial node of the method
Throws:
java.lang.Exception - On error

printMethodHeader

protected void printMethodHeader(InitialNode initialNode,
                                 FinalNode finalNode)
                          throws java.lang.Exception
Prints the method header including the parameter list.

Parameters:
initialNode - Initial node of the method
finalNode - Final node of the method or null
Throws:
java.lang.Exception - On error

printMethodBody

protected void printMethodBody(InitialNode initialNode,
                               FinalNode finalNode)
                        throws java.lang.Exception
Prints the method body.

Parameters:
initialNode - Initial node of the method
finalNode - Final node of the method or null
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printMethodFooter

protected void printMethodFooter(InitialNode initialNode,
                                 FinalNode finalNode)
                          throws java.lang.Exception
Prints the method footer.

Parameters:
initialNode - Initial node of the method
finalNode - Final node of the method or null
Throws:
java.lang.Exception - On error

printExecution

protected void printExecution(NodeSocket startSocket,
                              Node stopNode)
                       throws java.lang.Exception
Prints an execution path starting with the supplied start socket.

Parameters:
startSocket - Socket to start with (can be an entry or exit socket)
stopNode - Node that ends the execution path or null. The code of the stop node is not printed. A return statement always finishes the execution path generation normally.
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printInitialNode

protected void printInitialNode(InitialNode node,
                                NodeSocket exitSocket)
                         throws java.lang.Exception
Prints the initial node code.

Parameters:
node - Initial node
exitSocket - Exit socket
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printFinalNode

protected void printFinalNode(FinalNode node,
                              NodeSocket entrySocket)
                       throws java.lang.Exception
Prints the final node code.

Parameters:
node - Final node
entrySocket - Entry socket
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printAsssignment

protected void printAsssignment(java.lang.String targetName,
                                java.lang.String sourceName)
                         throws java.lang.Exception
Prints a variable asssignment.

Parameters:
targetName - Target variable name
sourceName - Source variable name
Throws:
java.lang.Exception - On error

printActivityNode

protected void printActivityNode(ActivityNode node,
                                 NodeSocket entrySocket,
                                 NodeSocket exitSocket)
                          throws java.lang.Exception
Prints the activity node code.

Parameters:
node - Activity node
entrySocket - Entry socket
exitSocket - Exit socket
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printDecisionNodeCondition

protected void printDecisionNodeCondition(DecisionNode node,
                                          NodeSocket entrySocket)
                                   throws java.lang.Exception
Prints the decision node condition.

Parameters:
node - Decision node
entrySocket - Entry socket
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printDecisionNodeThen

protected void printDecisionNodeThen(DecisionNode node,
                                     NodeSocket yesSocket,
                                     Node joinNode)
                              throws java.lang.Exception
Prints the decision node then.

Parameters:
node - Decision node
yesSocket - Socket that refers to the 'then' path of the statement
joinNode - Node that joins the 'then' and the 'else' path
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

printDecisionNodeElse

protected void printDecisionNodeElse(DecisionNode node,
                                     NodeSocket noSocket,
                                     Node joinNode)
                              throws java.lang.Exception
Prints the decision node else.

Parameters:
node - Decision node
noSocket - Socket that refers to the 'else' path of the statement
joinNode - Node that joins the 'then' and the 'else' path
Throws:
java.lang.Exception - On error
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

skipDecisionNodeBranches

protected Node skipDecisionNodeBranches(DecisionNode decisionNode)
                                 throws CodeGeneratorException
Skips decision node branches.

Parameters:
decisionNode - Decision node
Throws:
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

findJoiningNode

protected Node findJoiningNode(DecisionNode decisionNode,
                               NodeSocket yesSocket,
                               NodeSocket noSocket)
                        throws CodeGeneratorException
Finds the node that joins the 'then' and the 'else' part of a decison node.

Parameters:
decisionNode - Decision node
yesSocket - Yes socket
noSocket - No socket
Returns:
The first common node or null if no common node has been encountered
Throws:
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

containsPathNode

protected boolean containsPathNode(Node nodeToSearch,
                                   NodeSocket socket)
                            throws CodeGeneratorException
Throws:
CodeGeneratorException

expandParametrizedExpression

protected java.lang.String expandParametrizedExpression(java.lang.String expression,
                                                        NodeSocket entrySocket,
                                                        NodeSocket exitSocket)
                                                 throws CodeGeneratorException
Expands parameters in an expression, substituting parameter names for their actual values.

Parameters:
expression - Expression to evaluate
entrySocket - Entry socket
exitSocket - Exit socket
Returns:
The expanded expression
Throws:
CodeGeneratorException - On error

expandParametrizedExpression

protected java.lang.String expandParametrizedExpression(java.lang.String expression,
                                                        NodeSocket socket)
                                                 throws CodeGeneratorException
Expands parameters in an expression, substituting parameter names for their actual values.

Parameters:
expression - Expression to evaluate
socket - socket that hosts the parameters
Returns:
The expanded expression
Throws:
CodeGeneratorException - On error

getParamValue

protected java.lang.String getParamValue(NodeSocket socket,
                                         java.lang.String paramName)
                                  throws CodeGeneratorException
Obtains the value for a named parameter.

Parameters:
socket - Socket that hosts the parameter
paramName - Parameter name
Returns:
The parameter value or null if no such parameter exists
Throws:
CodeGeneratorException - If the value could not be resolved

getNamedSocket

protected NodeSocket getNamedSocket(Node node,
                                    java.lang.String name)
                             throws CodeGeneratorException
Gets a socket by its name.

Parameters:
name - Name
Returns:
The socket or null
Throws:
CodeGeneratorException - If there is a severe error that prevents the generation of meaningful source code

obtainExpression

protected java.lang.String obtainExpression(java.lang.String expression,
                                            java.lang.String desiredLanguage,
                                            PrintNameProvider owner)
                                     throws CodeGeneratorException
Obtains an expression for this source language from the given string. The string is expected to either contain a number of expressions - each separated by $$language$$ prefices - or a single Java expression.

Parameters:
expression - Expresssion
desiredLanguage - The language we are looking for (e. g. "Java")
Returns:
The language-specific expression or null if no appropriate expression was found.
Throws:
CodeGeneratorException - If there is no definition for the specified language

makeVariableName

protected java.lang.String makeVariableName(DescriptionObject o)
Produces a syntactically correct variable name from an arbitrary object.

Parameters:
o - Object to create a name for.
The original object name (o.getName ()) should be pretty fine, since allowed for Java identifiers only.
However, we have to make sure that it doesn't conflict with the name of a reserved word by prepending an underscore if we have to.
Returns:
The name (first character decapitalized)


Copyright © 2011. All Rights Reserved.