After you add an input and output object to the class-to-interface
mapping declaration, you can define the mapping rules between the attributes
of the input and output objects.
For this lesson, you create a custom
mapping rule that creates an interface called IClassName.
You also create a submap mapping rule that invokes the operation-to-operation
submap that you create in Lesson 3: Create and refine a class-to-class mapping declaration,
and add an input filter to the submap mapping rule to specify that only public
operations are transformed into the target interface.
To define the
mapping rules between the attributes of the input and output objects:
- Create a custom mapping rule between the name attribute
of the input and output object:
- In the editor area, in the class input object,
click the name attribute.
- Drag the handle of the name attribute to the name attribute
in the interface output object. A move mapping rule is created.
- On the Move element that connects the name attributes,
click the down arrow, and click Custom.
- Right-click the Custom element; then
click Show in Properties.
- In the Properties view, on the Details tab,
click In-line, and in the text area under the method
signature, type the following code: Interface_tgt.setName("I"+Class_src.getName());
Note: To invoke the content assist functionality, as you type the code,
press Ctrl+Space.
- Click Apply.
- Create a submap mapping
rule between the ownedOperation attribute of the input and output
object.
- In the editor area, in the class input
object, click the ownedOperation attribute.
- Drag the handle of the ownedOperation attribute to
the ownedOperation attribute in the interface output object. Because
the ownedOperation attribute is a collection, a submap mapping rule
is created by default.
- If the Properties view is not open, right-click
the new Submap element; then click Show
in Properties.
- If it is not selected already, in the Properties view,
on the Details tab, from the Map list,
select Operation2Operation.
- To the submap mapping rule that you create in step 2,
add an input filter that transforms only the public operations into the target
interface:
- In the Properties view, on the Input Filter tab,
click Filter Input Elements, and click In-line.
- In the text area under the Code option,
under the method signature, type the following code: if (ownedOperation_src.getVisibility().equals(VisibilityKind.PUBLIC_LITERAL))
{ return true; } return false;
Note: The code that
you specify for an input or output filter must return a Boolean value. You
can specify only the method body; the transformation authoring framework defines
the method signature. To see a list of valid variable names, in the text area
under the Inline button, press Ctrl+Space.
- Click Apply.
- Click .
In the next lesson, you create several mapping declarations in the
Generalize_Classes.mapping model; these mapping declarations define how parameters
and primitive types are transformed when you run the generated transformation.