Skip to main content
Jump to: navigation, search


Revision as of 07:18, 17 June 2009 by (Talk | contribs) (New page: An example of launching QVT Operational transformations programatically in Java.<br/> See the <code>org.eclipse.m2m.qvt.oml.TransformationExecutor</code> class for details. <code><pre> //...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

An example of launching QVT Operational transformations programatically in Java.
See the org.eclipse.m2m.qvt.oml.TransformationExecutor class for details.

// Refer to an existing transformation via URI
URI transformationURI = URI.createURI("platform:/resources/myqvtprj/ChangeTheWorld.qvto");
// create executor for the given transformation
TransformationExecutor executor = new TransformationExecutor(transformationURI);

// define the transformation input
// Remark: we take the objects from a resource, however
// a list of arbitrary in-memory EObjects may be passed
Resource inResource = resourceSet.getResource(
		URI.createURI("platform:/resources/myqvtprj/"), true);		
EList<EObject> inObjects = inResource.getContents();

// create the input extent with its initial contents
ModelExtent input = new BasicModelExtent(inObjects);		
// create an empty extent to catch the output
ModelExtent output = new BasicModelExtent();

// setup the execution environment details -> 
// configuration properties, logger, monitor object etc.
ExecutionContextImpl context = new ExecutionContextImpl();
context.setConfigProperty("keepModeling", true);

// run the transformation assigned to the executor with the given 
// input and output and execution context -> ChangeTheWorld(in, out)
// Remark: variable arguments count is supported
ExecutionDiagnostic result = executor.execute(context, input, output);

// check the result for success
if(result.getSeverity() == Diagnostic.OK) {
	// the output objects got captured in the output extent
	List<EObject> outObjects = output.getContents();
	// let's persist them using a resource 
	Resource outResource = resourceSet.getResource(
			URI.createURI("platform:/resources/myqvtprj/tomorrow.betterWorld"), true);
} else {
	// turn the result diagnostic into status and send it to error log			
	IStatus status = BasicDiagnostic.toIStatus(result);

Back to the top