Specifying implementation code for custom mapping rules in mapping projects

You can specify whether the custom mapping rule invokes inline or external code that calculates the value of an output property in a model-to-model transformation. You can specify semantic refinements by using Java™ code fragments or classes.

Before you begin

You must have a mapping model open. A mapping model has .mapping as a file name extension. The mapping model must contain at least one mapping declaration, and a custom mapping rule must be defined in the mapping declaration.

Procedure

  1. In the editor area, right-click the mapping rule; then click Show in Properties.
  2. In the Properties view, click the Details tab.
  3. Complete one of the following steps:
    • Click Inline to enter the code in the text area below the Code option. Specify the code that implements the custom mapping rule when you run the transformation; then click Apply.
      Tip: To see a list of valid variable names, in the text area below the Inline button, press Ctrl+Space.
    • Click External if the code for the custom mapping rule is located in a Java class. In the Class field, specify the Java class that contains the code to apply for the custom mapping rule. Click Browse to select a valid class from the workspace.
      Note: The Java class that you specify must extend the com.ibm.xtools.transform.authoring.RuleExtension class. The execute(EObject source, EObject target) method of the class that you specify is invoked with instances of the type of the mapped input feature and the type of the mapped output feature.
      Tip: To create a class that implements a custom mapping rule, click New; then complete the fields in the New Java Class window.
  4. Click File > Save.

Feedback