A M2MRuleset is composed by several MappingRule elements. A MappingRule defines which source Element kind will be transformed into which target element kind. The MappingRules can be created in serveral ways:
To create a MappingRule from the browser, right-click on the M2MRuleset or on the M2MPackage, and click on Add new | M2M | MappingRule
To complete the definition of the MappingRule, you can open the feature dialog box from the context menu, or you can display all the MappingRules features into a MappingRules Table as explained bellow.
It is recommended to create first a MappingRules Table. It allows to have a friendlier view of the MappingRules features. There are three kind of MappingRules table which display different kind of informations:
The MappingRules table can be created either directly in the M2MRuleset, or in a M2MPackage of your choice.
To create it, right-click on the M2MRuleset or on the M2MPackage, and click on Add new | M2M | Mapping Rules Table
Once the Mapping Rules Table is created, double-click on it, it will open an empty table with several columns like 'Source Stereotype' and the 'Target Stereotype'.
Select in the scope of the TableView, the M2MPackage where you want to create your MappingRules.
Click on 'Add model element' on the right:
'Add model element' creates a new MappingRule element and display a new line in the Mapping Rules Table:
To design your MappingRule, you need first to indicate the source metaclass (and/or Stereotype) and the target metaclass (and/or Stereotype).
The "Source" and "Target Metaclass" columns can be filled in by typing the name of a Rhapsody metaclass (e.g. Class, Package...). It will override the values of Tag AbstractRhpSourceMappingRule.sourceMetaclass and Tag AbstractRhpTargetMappingRule.targetMetaclass.
The "Source" and "Target Stereotype" columns, can be filled by selecting a Stereotype in the model via a drop-down box. It will create a sourceStereotype Dependency and a targetStereotype Dependency
If the selected source Stereotype is applicable to at least one metaclass, the source metaclass column will not be used by the M2M Engine. It supports Stereotypes which are New-Term or not, and applicable to 0..* Rhapsody metaclasses.
On target side, the target metaclass is mandatory. Either the metaclass is in the field "Applicable To"" of the selected target Stereotype, or in the column "Target Metaclass".
Selecting a target Stereotype applicable to multiple metaclass is not allowed.
By default, the drop-down boxes in Rhapsody can not display more than 500 elements. In the case there are more than 500 Stereotypes in the project, add the dedicated property in rhapsody.ini. Before editing rhapsody.ini, make sure Rhapsody is closed. Then open rhapsody.ini with a text file editor, go to the section [General], and add the line MaxComboBoxSize=5000. The value 0 means unlimited. 5000 is enough to manage AUTOSAR profiles which contains thousands of Stereotypes.
Drop-down boxes in Rhapsody tables are not always comfortable, especially when there are thousands of elements in the list. In this case, it is recommended to use the "Add New" menu on the MappingRule element:
- right-click in the browser on the MappingRule element, and then Add new | M2M | targetStereotype (targetStereotype Dependency)
- a dialog window will show up, and you will be able to search your Stereotype by typing its name in the "Depends On" field:
Filling in the source or target metaclass by hand in the table can lead to typing mistakes. To avoid this, the metaclass can be selected in the drow-down box of the Tags
AbstractRhpSourceMappingRule.sourceMetaclass and AbstractRhpTargetMappingRule.targetMetaclass. To proceed,
- Open Features dialog of the MappingRule by right-clicking on the model element, and click on "Features..."
- Click on "Tags" tab
- Click on the Tag value field, and select the metaclass in the drop-down box:
If it is needed to sort the execution of the MappingRule by the M2M Engine, the column 'Priority' must be completed with a number. It will overrides the Tag AbstractMappingRule.priority. At runtime, the M2M Engine will order all the Mapping Rules and follow this order when executing the transformation rules:
Those can be selected in the Mapping Rules Table via the model element selector:
Compared to the default naming strategy of a rule, it is possible to generate a meaningful name based on the following pattern: <source>_to_<target>(_if_<condition>)
- Select a rule, and right click on it. Then select the menu item M2M::Generate Mapping Rule name. The generated name will be set on this rule.
- Select a ruleset, and right click on it. Then select the menu item M2M::Generate Mapping Rule name. The generated name will be set on all the rules.
It is possible to enable or disable a MappingRule, by changing the value of the Tag activation via the drop-down box:
The column "Inheritance", is used to enable the source Stereotype inheritance. Selecting the value 'activated' or 'desactivated', overrides the Tag AbstractMappingRule.inheritance.
The column "Strict matching" can be used to require or not a strict matching of the elements with the MappingRule to allow the transformation:
When enabled (activated), the M2M Engine will check if there is a strict matching between an element and the MappingRule before transforming it.
For example, if the MappingRule has the metaclass "Package" as source metaclass, without selected Stereotype, and if the option "Strict matching" is activated, "Package" elements witch a Stereotype applied will not be transformed. Only new-term "Package" will be transformed.
Before implementing the MappingRules, it is possible to follow a "Specification phase".
Given that a MappingRule Stereotype is applicable to the Requirement metaclass, Requirement ID and specification description can be completed. These fields can be displayed in the Mapping Rules Table:
These fields have no effects to the transformation itself.