Chapter 4 Managing Profiles


Defining a template for generation

A generated file uses templates defined in metaclasses. The first template you have to define is on messages. The role of this template is to evaluate the message sequence number and to provide the name of the sender, the name of the message, and the name of the receiver for each message in the diagram.

The syntax for defining this template is the following:

.set_value(_tabs, "", new)
.foreach_part(%SequenceNumber%, '.')
.set_value(_tabs, "   %_tabs%")
.next
%_tabs%%SequenceNumber%) %Sender.ShortDescription% sends message "%Name%" to %Receiver.ShortDescription%

The first part of the template aims at creating indentation according to the sequence number of the message. The macro foreach_parts loops on the sequence numbers:

.foreach_part(%SequenceNumber%, '.') 
.set_value(_tabs, "   %_tabs%") 

It browses each sequence number, and whenever a dot is found, it adds 3 empty spaces automatically for indentation. This calculates the _tab variable, which is later used to create the correct indentation based on the sequence numbering.

The last line contains the actual generated text of the template: for each sequence number, the appropriate tab value is created, followed by the name of the sender (short description), the text "sends message", then the name of the message, the text "to", and the name of the receiver.

Steps To define a template used for generation:

  1. Select Model→Extended Model Definition and double-click the arrow beside Robustness Extension in the List of Extended Model Definitions to display the resource editor.
  2. Right-click the Profile category and select Add Metaclasses.

    The Metaclass Selection dialog box is displayed.
  3. Select Message in the list of metaclasses displayed in the PdOOM tab and click OK.

    The Message category is displayed under Profile.
  4. Right-click the Message category and select New→Template.

    A new template is created.
  5. Type description in the Name box of the template
  6. (optional) Type a comment in the Comment box of the template.
  7. Type the following code in the text area:

    .set_value(_tabs, "", new)
    .foreach_part(%SequenceNumber%, '.')
       .if (%Separator% == ".")
          .set_value(_tabs, "   "%_tabs%)
       .endif
    .next
    %_tabs%%SequenceNumber%) %Sender.ShortDescription% sends message "%Name%" to %Receiver.ShortDescription%

  8. Click Apply.

 


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