Lesson 7: Create and refine a model-to-model mapping declaration
About this task
To rename the target model that the transformation generates, you can create a custom mapping rule between the input and output objects, instead of creating a mapping rule between the features of the input and output objects.
To create a model-to-model mapping declaration:
Procedure
- If the mapping model is not open in the transformation mapping editor, in the Package Explorer view, double-click the .mapping file in the model folder.
- In the transformation mapping editor, in the Mapping Root section, right-click Generalize_Classes; then click Create Map.
- In the New Map window, in the Map name field, type Model2Model and 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 model-to-model mapping declaration
About this task
After you create the model-to-model mapping declaration, you must add an input and output object to it. In this lesson, you specify a model as the input and output object.
To add an input object and an output object to the model-to-model mapping declaration:
Procedure
- Click the Add an input object icon, which is the leftmost icon on the toolbar of the map that you are editing.
- In the Add Input window, in the Element pane, expand uml, click Model, and click OK.
- 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.
- In the Add Output window, in the Element pane, expand uml, click Model, and click OK.
- Click .
Results
Define the custom and submap mapping rules
About this task
- A custom mapping rule that renames the target model that the transformation generates
- A submap mapping rule that invokes the Package2PackageTransform transform, to transform the packages in the model
To create the mapping rules in the mapping declaration:
Procedure
Results
Change the processing order of mapping declarations
About this task
You can change the processing order of mapping declarations in a mapping model. The Outline view lists the mapping declarations in the order that they are processed when you run the generated transformation code. By changing the processing order, you can specify processing instructions for input objects that might be processed and consumed by a less specific mapping declaration.
- Model2Model
- Package2Package
- Class2Class
- Class2Interface
- Operation2Operation
- Parameter2Parameter
- Primitive2Primitive
To change the processing order of the mapping declarations:
Procedure
- If the Outline view is not visible, click .
- In the Outline view, right-click the Model2Model mapping declaration; then click Execution Order, and click Move up. Repeat this step until the Model2Model mapping declaration is at the top of the list.
- Repeat step 2 for each mapping declaration until the mapping declarations are in the same order as the list above.
- Click .