Running transformations

You can run a Java-to-Service-Model transformation by applying a transformation configuration, or by selecting a Java class or interface in a Java project or a class diagram.

Before you begin

To run a Java-to-Service-Model transformation by applying a transformation configuration, a transformation configuration file must exist in the workspace or as a file that you can access by specifying a URL. To run the transformation by selecting a Java class or interface, the selected Java element must be a Java interface or a Java class that implements an interface in a Java project in the current workspace.

About this task

The Java-to-Service-Model transformation uses the comparing and merging functionality to determine the differences between the target model and the temporary model that the transformation generates. When you run the Java-to-Service-Model transformation, the merge editor displays the differences between the two models. In the merge editor window, you can select the changes that the transformation merges into the target model.

Procedure

To run a transformation, complete the steps for one of the options in the following table:
Option Description
Use a transformation configuration Depending on the view that you are in, complete one of the following steps:
  • In the navigation view, right-click a transformation configuration (.tc) file; then click Transform and click a transformation. When you apply a transformation configuration, an instance of the transformation is created and the transformation runs with the properties that the configuration defines.
    Note: You can also apply a transformation configuration from the transformation configuration editor: On the Main tab, click Run, or, in the toolbar in the upper right corner, click the icon that displays the name of the transformation.
  • In the Pattern Explorer view, right-click a transformation; then click Run Transformation. In the Select configuration dialog box, specify the transformation configuration to run, and click OK.
Run the transformation from the Project Explorer view To run the transformation from the Project Explorer view, complete the following steps:
  1. In the Project Explorer view, in a Java project, right-click a Java class file or Java interface file; then click Add UML > Generate Service Model.
  2. In the Generate a Service Model window, specify the services model transformation to run and file name for the generated services model.
Run the transformation from a class diagram in a Java project To run the transformation from a class diagram in a Java project, complete the following steps:
  1. In a class diagram, right-click a visual representation of a Java class or Java interface; then click Generate Service Model.
  2. In the Generate a Service Model window, specify the services model transformation to run and file name for the generated services model.
Run the transformation from the command line To run a transformation from a command line, use the following syntax:
eclipse -data workspace-path -application com.ibm.xtools.transform.core.transformationRunner -transformConfigs "[-R]transformation-configuration-path1,[-R]transformation-configuration-path2,..." 

In the -transformConfigs parameter, you must specify the complete workspace path and configuration file name, not the file-system path name, of one or more transformation configurations.

Running a transformation from a command line suppresses all dialog boxes that the transformation generates.

As an example, a transformation configuration called MyConfig.tc is in a project called MyProject in a workspace called MyWorkspace. This transformation configuration specifies the configuration information for a transformation called MyTransformation, and for a corresponding reverse transformation called MyReverseTransformation.
  • To invoke MyTransformation, you can run the MyConfig.tc configuration by typing the following text at the command line:
    eclipse -data /MyWorkspace -application com.ibm.xtools.transform.core.transformationRunner -transformConfigs "MyProject/MyConfig.tc"  
  • To run the reverse transformation, specify the -R option at the beginning of the transformation configuration path, as in this example:
    eclipse -data /MyWorkspace -application com.ibm.xtools.transform.core.transformationRunner -transformConfigs "-RMyProject/MyConfig.tc"
  • To run multiple transformations, in the -transformConfigs parameter, specify a comma-separated list of transformation configurations, including the workspace path name for each configuration. You can run forward or reverse transformations, as in this example:
    eclipse -data /MyWorkspace -application com.ibm.xtools.transform.core.transformationRunner -transformConfigs "MyProject/MyConfig.tc, -RMyProject/MyConfig.tc"
Invoke the transformation API To run the transformation as part of an application, you can invoke the transformation API, as in the following example:
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/MyWorkspace/MyConfig.tc"));
try {
		ITransformConfig config = TransformConfigUtil.loadConfiguration(file);
		IStatus status = TransformController.getInstance().execute(config, null, false, null);
}
catch (IOException e) {
// The config file could not be read.
}
You can also load a transformation configuration by specifying a URL, as in the following example:
try {
	URL url= new URL(platform:/plugin/myPluginID/myConfig.tc);
	ITransformConfig config = TransformConfigUtil.loadConfiguration(url);
	}
	catch (MalformedURLException malURLEx) {
		// Handle exception.
	}
	catch (IOException ioEx) {
		// Handle exception.
}
You can specify a URL that uses different protocols, as in the following examples:
  • platform:/plugin/myPluginID/myConfig.tc
  • http://myServer.myCompany.com/myConfig.tc
  • ftp://myUsername:myPassword@myServer.myCompany.com/myConfig.tc
  • jar:file:c:/myFolder/myJar.jar!/myConfig.tc
  • file:c:/myFolder/myConfig.tc
Run a transformation configuration from an Ant script
To run a transformation from an Ant script or build.xml file, complete the following steps:
<?xml version="1.0" encoding="UTF-8"?>
   <project name="myProject" default="generate" basedir=".">
      <target name="generate">
         <echo>Running transformation 'myProject/myConfig.tc' ...</echo>
         <com.ibm.xtools.transform.core.runTransformation transformConfig="myProject/myConfig.tc" reverse="false"/>
      </target>
</project>

In the build.xml file, in the project element, set the default attribute equal to the value that you specify for the name attribute in the target element.

The transformConfig attribute must specify a valid workspace path.

For transformation types that support a reverse transformation, to run the reverse transformation, set the reverse attribute to true.
Note: The transformation configuration must implement the Reconciled Modeling design contract management protocol (DCMP).

To run the Ant script, right-click the build.xml file; then click Run As > Ant Build.


Feedback