TGL

MDWorkbench offers a template-based approach where a text template specifies a combination of static text and placeholders for data to be extracted from models. These placeholders are essentially expressions specified for metamodel entities with queries and patterns being the primary mechanisms for selecting and extracting the values from models. The language used to define text template is TGL (Text Generation Language).

TGL is a simple imperative language using markups (tags) to distinguish static text from dynamic code. A template is a mix of the following sections:

Text Static text that will be printed to the output as is.
Directives Directive tags are similar to HTML tags, but they are instructions and will not be output.
Dynamic Text These sections will be replaced with a calculated value in the output.
Dynamic text is delimited by ${ and }.
Comments Comments are similar to HTML comments, but they are delimited by [#-- and --].
Comments will be ignored, and will not be written to the output.

TGL can be used both in text templates as well as text scripts.
MQL (Model Query Language) is used to define the expressions used within TGL.

Here is a small example of a text template:

[#package com.mycompany.example]

[#-- we define a template GenerateJavaFile which expects a UML class argument --]
[#template GenerateJavaFile(class : uml21.Class)]
[#file]${class.name}.java[/#file] [#-- the file where to write generated contents --]
public class ${class.name} {

    public String toString() {
        return "${class.name} instance";
    }
}
[/#template]

For a class Account, this template would output in the file Account.java:

public class Account {

    public String toString() {
        return "Account instance";
    }
}