Model-to-text transformation sample details

This sample contains the following three transformations:

Transformation

Description

Class to Text -> Console This transformation accepts a UML class as its source and writes a description of the class (the name of the class and its attributes and operations, and the parameters of the operations) to the Console view.
Class to Text -> File This transformation is the same as the Class to Text Console transformation, but it writes the results to a file instead of the Console view.
State to JSP This transformation accepts a state machine as its source and generates a JSP page for each state that has a stereotype from the ScreenFlow profile.

To understand how the transformations are constructed, you should run the transformations and explore the source code. When you read the source code, you should follow these guidelines:

  • Look first at the Java classes that implement the rules. The classes appear in packages whose names end with .rules.
  • A set of rules is combined into one or more transforms. The transforms are implemented by Java classes in packages whose names end with .transforms. You might want to read the code for the transform classes first and then read the code for the root transforms.
  • Finally, look at the plug-in manifest file, plugin.xml, and the code for the TransformationProvider class to understand how transformations are connected to the Transformation Service.

Class to Text Transformation

This transformation accepts a UML class, a package, or a model as its source and writes the names of the classes and their attributes and operations, and the parameters of the operations to either the Console view or a file. If you choose a model or a package as the source, the transformation writes the details of all the classes that the model or package contains.

This transformation has two variations:

  1. Class to Text -> Console: This transformation writes the output to the Console view and it does not need a target.

    This sample transformation shows you how to do the following things:

    • Create simple rules and combine them into one or more transforms
    • Create a transformation provider
    • Describe a transformation and its provider in the plug-in manifest file, plugin.xml

  2. Class to Text -> File: This transformation writes the output to a file and requires a project as its target. By default, it creates a file named class2text.txt in the ClassToTextOutput folder, in the project that you specify. You can use the transformation property, Target File Name, to change the default name of the file.

    This sample transformation shows you how to do these additional things:

    • Describe the transformation properties in the plug-in manifest file, plugin.xml
    • Manipulate the transformation properties inside a rule

State to JSP Transformation

This transformation accepts a UML state in a state machine as its source and generates a Web page in the form of a JSP file using Java Emitter Templates (JET). If you choose a state machine or a region as the source, the transformation generates a JSP file for each state in the state machine or the region that has a stereotype from the ScreenFlow profile applied to it.

This sample transformation shows you how to do the following things:

  • Use stereotypes and keywords to trigger rules selectively
  • Combine JET functionality and the transformation to generate text

To prepare the source state machine for the transformation, you must apply the ScreenFlow profile to the UML model that contains the state machine and mark up the state machine by applying the stereotypes in ScrrenFlow profile to its states. The ScreenFlow profile contains four stereotypes: form, editform, selectlist, and display. These stereotypes determine the display style of the dynamic contents of the generated page. The sample uses the stereotypes to determine whether the display style is an editable form or a selectable list, and so on. If you apply more than one stereotype to a state, the transformation only considers the first stereotype.

The sample also uses the properties of the stereotypes to determine the data that is exchanged through the JSP pages. The transformation generates a JSP page that corresponds to a state only if one of the four stereotypes is applied to the state. If the JSP files already exist, the transformation does not overwrite them when it runs. You can change whether the transformation overwrites files by setting the value of the transformation property, Overwrite Output Files, to true.

ScreenFlow Profile

The following table shows the stereotypes in the ScreenFlow profile and their properties. The values in the table are for illustration purposes only.

Stereotype

Base Class

Properties:Values

Description

display
<<display>>
State entity:Contact
fields:name, address
Indicates that the generated JSP page displays the contact details: name and address
editform
<<editform>>
State entity:Contact
fields:name, address
Indicates that the generated JSP page contains an editable form in which a user can enter or edit contact details: name and address
form
<<form>>
State fields:userName Indicates that the generated JSP page contains a form to enter the user's name
selectlist
<<selectlist>>
State entity:Contact
fields:name, address
selectfield:id
Indicates that the generated JSP page contains a list of contacts that can be used to select a contact with a specific ID