< Previous | Next >

Lesson 1: Generate and compile the transformation source code

This lesson shows you how to generate and compile the transformation source code.

Before you generate the transformation source code, in the Generalize Classes project, examine the contents of the src folder. These packages and files were generated when you created the project; other files are created when you edit the Generalize_Classes.mapping file.

You can incrementally add mapping rules and generate implementations for the mapping rules in a mapping declaration. You do not have to define all mapping rules before you can generate the transformation source code. For example, after you complete this tutorial, you might add mapping rules that create a realization relationship from the implementation class to the interface.

When you generate the transformation source code, for each mapping declaration in the mapping model, the transformation authoring framework generates a Java source file with the name nTransform.java, where n represents the name of a mapping declaration. Collectively, these Java files compose the transformation code. In addition to generating the implementation code for the transformation, the transformation authoring framework also generates code to register the transformation with the transformation service.

To generate and compile the transformation source code:

  1. If it is not open already, open the Plug-in Development perspective: Click Window > Open Perspective > Other > Plug-in Development; then click OK.
  2. If the Generalize_Classes.mapping file is not open in the mapping editor, in the Package Explorer view, double-click the file.
  3. In the mapping editor area, right-click in the Mapping Root section; then click Generate transformation source code.
    Tip: You can also generate the transformation source code by completing these steps: In the Package Explorer view, right-click the .mapping file; then click Transform > Generate Transformation Code.
    In the Package Explorer view, examine the packages and files in the src folder. The generated transforms are displayed in the src/generalize_classes.transforms folder.
  4. To compile the generated source code, in the Package Explorer view, click the Generalize Classes project, and click Project > Build Project. By default, Eclipse projects build automatically when you save changes to a project. If you did not change the build preferences for the workspace or project, you do not have to complete this step.
    Tip: To change the preferences for building projects, click Window > Preferences, expand General, and click Workspace. After you change the preferences, click OK.
  5. Examine the contents of the src folder for errors.
  6. If a compilation error occurs in the Class2Interface transform code, you might need to import the VisibilityKind package:
    1. In the Package Explorer view, in the src/generalize_classes.transforms/Class2InterfaceTransform.java file, double-click the method that has the error adornment.
    2. In the editor area, in the left margin, right-click the error adornment; then click Quick Fix, and double-click Import "VisibilityKind" (org.eclipse.uml2.uml).
    3. Click File > Save.
  7. In the Package Explorer view, click the Generalize Classes project and click Project > Build Project.

Review the files in the src/generalize_classes.transforms folder of the project. A Java transform is generated for each mapping declaration in the mapping model. In the MainTransform.java file, the MainTransform method adds an instance of each generated transform in the order that you specify in the Outline view.

You can now configure a runtime workbench.

< Previous | Next >

Feedback