< Previous | Next >

Lesson 5: Create and refine the mapping declarations that the operation-to-operation mapping declaration requires

This lesson shows you how to create the mapping declarations that the operation-to-operation mapping declaration requires to transform elements in an operation. For example, you create a mapping declaration that transforms the parameters in the source model into parameters in the target model; you also create a mapping declaration that defines how to transform primitive types in the source model into primitive types in the target model. In this lesson, you also create the mapping rules for the operation-to-operation mapping declaration, which invoke the mapping declarations that you create in this lesson.
The following table lists the mapping declarations and mapping rules that you create in this lesson:
Mapping declaration Input and output object type Mapped attributes Mapping rule type Mapping rule description
Primitive2Primitive UML primitive type name move Creates a primitive type in the element whose submap invokes the Primitive2Primitive mapping declaration
Parameter2Parameter UML parameter name, visibility move Creates a parameter in the element whose submap invokes the Parameter2Parameter mapping declaration; the generated parameter has the same name and visibility as the parameter in the source input element
type submap For each type in the element whose submap invokes this mapping declaration, these are results:
  • If the parameter is of type primitive, this rule invokes the Primitive2Primitive mapping declaration
  • If the parameter is of type class, this rule invokes the Class2Class and Class2Interface mapping declarations
Operation2Operation UML operation name, visibility move Creates an operation in the element whose submap invokes the Operation2Operation mapping declaration; the generated operation has the same name and visibility as the operation in the source input element
ownedParameter submap For each parameter in the operation, this submap invokes the Parameter2Parameter mapping declaration

In this tutorial, the Paramater2Parameter mapping declaration invokes the Primitive2Primitive mapping declaration to create parameters of type primitive.

To create the primitive-type-to-primitive-type mapping declaration in the mapping model:

  1. If it is not open, in the Package Explorer view, in the model folder, double-click the Generalize_Classes.mapping file.
  2. In the transformation mapping editor, in the Mapping Root section, right-click Generalize_Classes; then click Create Map.
  3. In the New Map window, in the Map name field, type Primitive2Primitive as the name of the mapping; then click OK. The map is displayed in the Outline view, and opens under the Mapping Root in the editor area.

Add input and output objects to the Primitive2Primitive mapping declaration

After you create the Primitive2Primitive mapping declaration, you must add an input object and an output object to it. In this lesson, you specify a UML primitive type as the input and output object.

To add an input object and an output object to the Primitive2Primitive mapping declaration:

  1. Click the Add an input object icon, which is the leftmost icon on the toolbar of the map that you are editing.
  2. In the Add Input window, in the Element pane, expand uml, click PrimitiveType, and click OK.
  3. Click the Add an output object icon, which is the second icon from the left on the toolbar of the map that you are editing.
  4. In the Add Output window, in the Element pane, expand uml, click PrimitiveType, and click OK.
  5. Click File > Save.
You can now define a mapping rule between the name attribute of the PrimitiveType input and output objects.

Define mapping rules between attributes of the PrimitiveType input and output objects

For this lesson, create a move mapping rule that creates a primitive type in the target model. The generated primitive type has the same name as the primitive type in the input model; you could also think of this as creating a copy of the primitive type.

To define a move mapping rule that defines a relationship between the name attribute of the PrimitiveType input and output objects:

  1. In the editor area, in the PrimitiveType input object, click the name attribute.
  2. Drag the handle of the name attribute to the name attribute in the output object.
  3. Click File > Save.
You can now create a parameter-to-parameter mapping declaration.

Create a parameter-to-parameter mapping declaration

This section shows you how to create a mapping declaration that specifies a UML parameter as both the input and output object. This parameter-to-parameter mapping declaration contains mapping rules that, when you run the generated transformation, create a parameter in the target model whose name, visibility, and type are the same as the parameter in the element whose submap invoked this mapping declaration. In this tutorial, the Operation2Operation mapping declaration contains a submap mapping rule that invokes this mapping declaration.

To create a parameter-to-parameter mapping declaration:

  1. If it is not open, in the Package Explorer view, in the model folder, double-click the Generalize_Classes.mapping file.
  2. In the transformation mapping editor, in the Mapping Root section, right-click Generalize_Classes; then click Create Map.
  3. In the New Map window, in the Map name field, type Parameter2Parameter, and click OK. The map is displayed in the Outline view, and opens in the editor area under the Mapping Root.

Add input and output objects to the Parameter2Parameter mapping declaration

After you create the mapping declaration, you must add an input object and an output object to it. In this lesson, you specify a UML parameter as the input and output object.

To add an input object and an output object to the Parameter2Parameter mapping declaration:

  1. Click the Add an input object icon, which is the leftmost icon on the toolbar of the map that you are editing.
  2. In the Add Input window, in the Element pane, expand uml, click Parameter, and click OK.
  3. Click the Add an output object icon, which is the second icon from the left on the toolbar of the map that you are editing.
  4. In the Add Output window, in the Element pane, expand uml, click Parameter, and click OK.
  5. Click File > Save.
You can now define mapping rules between the attributes of the parameter input and output objects.

Define mapping rules in the Parameter2Parameter mapping declaration

After you add the input and output objects to the mapping declaration, you can define the mapping rules between the attributes.

In this section, you create submap rules and a move mapping rule that, when you run the generated transformation, create a parameter in the target model whose name, visibility, and type are the same as the parameter in an element of the source model. In this tutorial, the Operation2Operation mapping declaration invokes this mapping declaration.

To define the mapping rules in the Parameter2Parameter mapping declaration:

  1. Create a move mapping rule between the name attribute of the input and output object:
    1. In the editor area, in the parameter input object, click the name attribute.
    2. Drag the handle of the name attribute to the name attribute in the output object.
  2. Repeat steps 1a and 1b, but replace name with visibility.
  3. Create a submap rule between the type attribute of the input and output object:
    1. In the editor area, in the parameter input object, click the type attribute.
    2. Drag the handle of the type attribute to the type attribute in the output object. Because this attribute is a complex type, a submap is created by default.
    3. If the Properties view is not open, in the editor area, right-click the new Submap element; then click Show in Properties.
    4. In the Properties view, on the Details tab, from the Map list, select Primitive2Primitive.
    This mapping rule generates code that invokes the Primitive2Primitive transform when a primitive parameter is encountered in the source model. If the parameter in the source model is not of type primitive, the parameter is not transformed into the target model.
  4. Repeat steps 3a, 3b, and 3c, and then complete the following step:
    • In the Properties view, on the Details tab, from the Map list, select Class2Class.
    This submap mapping rule generates code that creates a parameter of type class in an element in the target model, if the source parameter is of type class.
  5. Repeat steps 3a, 3b, and 3c, and then complete the following step:
    • In the Properties view, on the Details tab, from the Map list, select Class2Interface.
    This submap mapping rule creates a parameter of type interface in an element in the target model, if the source parameter is of type class.
  6. Click File > Save.
You can now define the mapping rules in the operation-to-operation mapping declaration that you created in Lesson 3: Create and refine a class-to-class mapping declaration.

Define mapping rules in the Operation2Operation mapping declaration

Lesson 3: Create and refine a class-to-class mapping declaration showed you how to create an operation-to-operation mapping declaration. In this section, you are now ready to create mapping rules in this mapping declaration. When you run the generated transformation, these mapping rules create an operation in the target model whose name, visibility, and parameters are the same as the operation in the source model. In this tutorial, the Class2Class and Class2Interface mapping declarations invoke this mapping declaration.

To define the mapping rules in the Operation2Operation mapping declaration:

  1. If it is not open, in the Package Explorer view, in the model folder, double-click the Generalize_Classes.mapping file.
  2. In the Outline view, click the Operation2Operation mapping declaration.
  3. Create a move mapping rule between the name attribute of the input and output object:
    1. In the editor area, in the operation input object, click the name attribute.
    2. Drag the handle of the name attribute to the name attribute in the output object.
  4. Repeat steps 3a and 3b, but replace name with visibility.
  5. Create a submap rule between the ownedParameter attribute of the input and output object:
    1. In the editor area, in the operation input object, click the ownedParameter attribute.
    2. Drag the handle of the ownedParameter attribute to the ownedParameter attribute in the output object. Because this attribute is a collection, a submap is created by default.
    3. If the Properties view is not open, in the editor area, right-click the new Submap element; then click Show in Properties.
    4. In the Properties view, on the Details tab, from the Map list, select Parameter2Parameter.
  6. Click File > Save.
In the next lesson, you create a package-to-package mapping declaration.
< Previous | Next >

Feedback