Chapter 9 Generation Reference Guide (GTL)


Defining templates

A template consists of plain text, variables, and may contain macros. It is a piece of text generated for an object. It behaves like a special type property whose value is recalculated each time you try to obtain it. The content of a template is code that is generated in a text format.

A template is associated with a given metaclass, you may define as many templates as you want for any given metaclass, it is available to all objects (instances) of this metaclass. A metaclass is a class of the metamodel (or abstract class). It can be an entity attribute from the Conceptual Data Model (CDM), a table from the Physical Data Model (PDM), an operation from the Object-Oriented Model (OOM), etc ...Templates give full access to the PowerDesigner metamodel attributes, collections, and all elements of the model.

Templates are used to generate files, their role is to produce text for generation purposes. During generation, the evaluation of a template always generates text which can be stored in a file and used to gather information about a given object.

A template may also refer to any template (including itself) to promote recursion and sharing of template code, the second template is evaluated and its value is located in the result of the first template.

Example

Here is an example of a template:

.foreach_item (Parameters)
%definition%
.next(", ")

Note   Examples
You will find specific examples on the use of templates in the different sections of this chapter.

A template is built with the following syntax:

template = <complex-template>
complex-template = (<block-macro> | <simple-macro> | <simple-template<)*
simple-template = (<text> | <variable-block> | <conditional-block>)*

For more information on some pieces of the above syntax, see their definition later in this chapter.

You can use simple or complex templates. A simple template does not contain any macros, whereas a complex template does.

Simple template example

Here is an example of a simple template syntax:

%Visibility% %DataType% %Code% [= %InitialValue%]

When evaluated, the above template which contains the four variables Visibility, DataType, Code and InitialValue will be replaced with the values for the current object from the model. Because the = sign and the value for the last variable InitialValue are in brackets, this section of the template will only be generated if InitialValue is not void.

Complex template example

Here is an example of a complex template syntax:


Each variable enclosed in % characters is either the name of an attribute, or a property of the current object, or the name of a template.

For more information on variables, see the "Defining variables" section.

Java templates example

In Java, open the Profile\Operation\Templates folder in the object language to display all templates used for generation for existing operations in the OOM.

 


Copyright (C) 2005. Sybase Inc. All rights reserved.