You can run a transformation on
an entire model or project, or on a subset of elements in a model
or project to generate the output that you expect. You can run a transformation
on the source that you specify in the transformation configuration,
or you can override the specified source by selecting elements in
the model or project and then choosing a transformation configuration
to apply.
Before you begin
Before
you can run a transformation, you must create a transformation configuration.
When you apply a transformation configuration, an instance of the
transformation is created and the transformation runs with the properties
that the configuration defines.
About this task
There are four basic methods you can
use to run a transformation:
- Run a transformation from commands in the user interface
- Run a transformation from the command line
- Run a transformation using an Ant task
- Run a transformation programmatically
If you select source elements in the model instead
of using the transformation configuration, the source elements that
you select override the source model or elements specified in the
transformation configuration. The transformation
configuration is not affected and the source that you specify on the Source
and Target page of the transformation configuration editor
or in the New Transformation Configuration wizard does not change.
- To run the transformation on the source specified in the configuration,
depending on the view that you are working 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.
- 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.
- On the Main page of the transformation configuration
editor, click Run.
- To specify a different source on which to run the transformation,
in the Modeling perspective, select and right-click
elements in the source model or project; then click Transform,
click a transformation configuration, and click a transformation.
The transformation configuration file must be in the same project
as the elements that you select.
Tip: To run this transformation
again, click . The transformation
uses the same source elements from when you last ran the transformation.
- 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"
- To run single or multiple transformations
using the com.ibm.xtools.transform.core.runTransformation Ant
task, complete the following steps:
- Create a file in your project named "build.xml".
- In build.xml, insert the following content:
<?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>
Replace the myProject variable
with the name of your target project and the myConfig.tc variable
with the name of the transformation configuration file being referenced
in that project.
For transformation types that support a reverse
transformation, if you want to run the reverse transformation, set
the reverse attribute to "true."
You can run multiple transformations
by specifying additional <com.ibm.xtools.transform.core.runTransformation> elements
in the build.xml file.
- Save and then close build.xml.
- Right-click build.xml; then click .
- 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