Sample configuration for a model-to-model transformation that uses a diagram to specify input

This sample shows how to use a diagram to specify input for a model-to-model transformation. This topic explains both how to run and how to set up this kind of transformation.

Before you begin

Use the instructions in the topic "Setup instructions for a model-to-model transformation that uses a diagram to specify input" to set up the sample.

Procedure

  1. In the runtime workbench, examine the source and the transformation configuration.
    1. Expand Diagrams and Models and note that both diagram and model elements are included in the source project.
    2. Right-click run test.tc; then click Open > Transformation Configuration Editor.
    3. In the transformation configuration editor, click the Properties tab. Notice that the value specified for the property DiagramName is Main1, which is one of the diagrams in the project.
    4. In the transformation configuration editor, click the Main tab, and then click Run.
    5. Examine the output from the transformation. The output includes Class2, Class4, and Class6, as specified in the input diagram named Main1.
  2. To understand how the transformation is set up, examine the project that you imported into your workspace.
    1. Expand src, expand com.ibm.xtools.transform.authoring.examples.classesindiagram, and open the TransformationProvider class,ClassesInDiagramTransformationProvider.
    2. Note that the TransformationProvider class retrieves the name of the diagram from the transformation context and stores it in a global variable. The code looks like this:
      protected RootTransformation createRootTransformation(ITransformationDescriptor descriptor) {
            return new RootTransformation(descriptor, new MainTransform() {
      		@Override
      		public void execute(ITransformContext context) throws Exception {
      			diagramName = (String)context.getPropertyValue("diagramname");
      			super.execute(context);
      		}        	
             });
         }
      
         public static String diagramName = null;
    3. Expand the model and open the mapping file, which is named ClassesInDiagram.mapping.
    4. In the Model2Model mapping declaration, right-click the second packagedElement-to-packagedElement submap, and click Show in Properties. This submap is the Class2Class mapping.
    5. In the Properties window, click the Custom Extractor tab. Note that the custom extractor uses the global variable to determine which classes should be processed by referring to the contents of the specified diagram. The same global variable is also used by the custom extractor in the Class2Class submap of the Package2Package mapping declaration.
  3. In the runtime workbench, in the transformation configuration editor, on the Properties page, replace the value in the diagramName field with "Main2" and rerun the transformation. This time, the transformation fails.

    The transformation fails when the Main2 diagram is named in the configuration because the source model contains a generalization from Class5 to Class; however, Class1 was not copied to the target model because it did not appear in the specified diagram.

    When you author a transformation, note that the transformation must include all referenced objects that are contained in the same model so that all intra-model references can be resolved.


Feedback