Sample configuration for a model-to-model transformation that generates multiple objects from a single input object

This sample shows you how to use interdependent mapping declarations to generate multiple objects from a single input object.

Before you begin

To set up the sample, use the instructions in "Setup instructions for a model-to-model transformation that generates multiple objects from a single input object."

About this task

The transformation generates multiple related objects from a single input object without requiring the transformation author to write extensive custom code.

Procedure

  1. In the runtime workbench, in the Package Explorer view, expand the source project, expand Models, and expand Source1. Source1 contains a package with two classes in it: A and B.
  2. Expand the target project and double-click the transformation configuration file named transform source1 to target1.tc.
  3. In the transformation configuration editor, click Run.
  4. In the target project, expand Models, and expand Target1. Notice that for each class in the input model, the transformation created the following elements:
    • An interface, where the name of the interface is the name of the source class preceded by the letter "I"
    • An implementation class, where the name of the implementation class is the name of the source class followed by "Impl"
    • An interface realization from the implementation class to the interface

Results

To see how the transformation works, consider the problem it solves: Assume that you are authoring a transformation, and want to use the Class2InterfaceRealization mapping declaration in the Package2Package mapping declaration to create the interface realization. However, the target feature for the submap mapping, an interface realization of a UML class, is not visible in the Package2Package mapping declaration. How can you map to the missing target feature?

Note: The item numbers in the following text refer to items in the accompanying figure.

To provide interface realization as a target, you create a submap from the packagedElement feature to the packagedElement feature in the Package2Package mapping declaration (item 1 on the figure). This submap references its parent Package2Package mapping declaration, recursively, and in this way provides support for nested packages and their contents. As a result, you can now define additional submaps from the packagedElement feature to the packagedElement feature. The submaps can reference other mapping declarations: Class2Class (item 2) and Class2Interface (item 3).

When you create the Class2Class mapping declaration, you can use a submap (item 4) that has as its input the entire Class element. For the output, select interfaceRealization. The result of this is to make available the Class2InterfaceRealization mapping declaration, with which you create two additional submaps (items 5 and 6) that also have as their input the entire Class element and as their output the supplier feature and the client feature. When you generate the transformation code, the submaps that are defined here do not create output objects, but create references to output objects that are created by transforms that are generated from other mapping declarations.

When you generate the transformation code, both the supplier and client output features must reference the UML objects that were generated from the input UML objects. To specify the output objects to reference, write the submap definitions so that they identify the mapping declaration, Class2Class or Class2Interface, whose generated transform is responsible for generating the specific output object, Class or Interface, from the same input.

For details, examine the sample transformation configuration. In the figure, the arrows that point from a submap to the top of a mapping declaration indicate that the submap references the mapping declaration. For example, the arrow labeled "1" references the Package2Package mapping declaration.

Composite diagram that shows relationships between mapping declarations in the sample

Feedback