Running templates using J scripts

 

Introduction

Templates can be used to create diagrams, generate documentations or code and can be launched in J code.

To execute templates using J code, you should use the wizard to create commands defined in the “Creating commands” section. The operation created by the wizard contains the J code to execute templates.

 

UML 2.0 diagram templates

UML 2.0 diagram templates, also known as view templates, are used to create or update collaboration diagrams, deployment diagrams, object diagrams and class diagrams.

Diagram templates are applied by calling the “runDiagramTemplate” method, using the name of the file to be used as the parameter.

StaticDiagram runDiagramTemplate (

Object template,

boolean isRecursive)

 

If the “isRecursive” is “true”, the diagram template is applied on all “NameSpace” components. For exemple, for a package, the template is applied on sub-packages, classes, etc.).

The operation returns the created or updated diagram. For a recursive execution, only the diagram of the element, on which the template is executed, is returned.

 

Example:

StaticDiagram diagram;

diagram = runDiagramTemplate (

projectFindFromIds ("", "12335092:89574"),

false);

 

UML 1.4 diagram templates

UML 1.4 diagram templates, also known as view templates, are used to create or update activity diagrams, sequence diagrams, state diagrams and use case diagrams.

Diagram templates are applied by calling the “runViewFile” method, using the name of the file to be used as the parameter.

 

Example:

String viewFile = getCurrentModuleSubDirectory ("templates");

viewFile.strcat ("\packageView.view.xml");

StdOut.write ("Apply template : ", viewFile, " on element ", Name, NL);

sessionBegin ("Diagram creation", true);

#external#MDATemplates#runViewFile (viewFile);

sessionEnd();

 

Documentation templates created with MDA Modeler 2.0.00 and above

Documentation templates can be run by calling the “runDocTemplate”:

boolean runDocTemplate (

in    Object template,

inout string filename,

in    string format)

 

where,

·         template is the template to execute in order to produce documentation.

·         filename is a J expression. It is evaluated in the context of the element on which the operation is launched. After template execution, “filename” contains the result of the evaluation. For more information on entering J code, please see “Inserting J code”.

·         format is the format of the generated documentation: “xml”, “html” (all documentation in multiple files), “simplehtml” (all documentation in a single file), “rtf”, “roundtrip_rtf” (with round-trip tags to retrieve the documentation after editing it in an external editor), “pdf”.

 

Example:

String filename = "~"C:\tmp\~" + Name + ~".rtf~"";

runDocTemplate (

projectFindFromIds ("", "12335092:89604"),

filename,

"xml");

 

After template execution on the “myPackage” element, filename has the value: “C:\tmp\myPackage.rtf”.

 

Documentation templates created with MDA Modeler 1.4.d and below

In these versions with Objecteering 5.3, documentation templates are represented by an XML file and run by calling the “runDocFile” function with the following parameters:

·         The template name.

·         The directory where the files will be generated.

·         The name of the entry file.

·         A boolean to indicate if you want only XML generation or also documentation generation.

 

runDocFile (

in string  template,

in string  targetDirectory,

in string  targetFile,

in boolean onlyXMLFile)

 

Example:

String docFile = getCurrentModuleSubDirectory ("templates");

String resDir = "d:\mda";

String resFile;

 

docFile.strcat ("\DocStatic.doc.xml");

StdOut.write ("Apply template : ", docFile, " on element ", Name, NL);

sessionBegin ("gendoc", true);

#external#MDATemplates#TEngine#TEngine_doc#setDocFormat ("Multiple HTML - generation in several files");

#external#MDATemplates#runDocFile (docFile, resDir, resFile, false);

sessionEnd ();

StdOut.write ("Generated file: ", resDir,"\", resFile,NL);

 

Code templates

Code templates can be run by calling the “runCodeTemplate”:

boolean runCodeTemplate (

in    Object template,

inout string filename)

 

where,

·         template is the template to execute in order to produce documentation,

·         filename is a J expression. It is evaluated in the context of the element on which the operation is launched. After template execution, “filename” contains the result of the evaluation. For more information on entering J code, please see “Inserting J code”.

 

Example:

String filename = "~"C:\project\java\~" + Name + ~".java~"";

runCodeTemplate (

projectFindFromIds ("", "12335092:90314"),

filename);

 

After template execution on the “myClass” element, filename has the value: “C:\project\java\myClass.java”.