Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Executing QVTo Programmatically
icon5.gif  Executing QVTo Programmatically [message #1407004] Mon, 11 August 2014 16:39
Sama Elrawy is currently offline Sama ElrawyFriend
Messages: 9
Registered: February 2014
Junior Member
Hello,

I'm trying to execute a QVTo transformation using Java where I have 2 xmi files as an input and another xmi file as an output.

My problem is how to define 2 input xmi files? and how to register the xmi package?

For example, If I'm registering UML, I should use this line of code:
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);


What about XMI?

Here is the full code that I currently have:
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
		Map<String, Object> m = reg.getExtensionToFactoryMap();
		m.put("http://www.eclipse.org/emf/2002/XMI", new XMIResourceFactoryImpl());
		ExecutionContextImpl context= new ExecutionContextImpl();
		context.setConfigProperty("keepModeling", true);
		URI transformationURI = URI.createURI("file:///C:/Users/sama.elrawy/EclipsJEEworkspace/Multi_project/transforms/multi_generation.qvto");
		TransformationExecutor executor = new TransformationExecutor(transformationURI);
		ResourceSet resourceSet = new ResourceSetImpl();

		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
	
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
		Resource inResource = resourceSet.getResource(URI.createURI("file:///C:/Users/sama.elrawy/EclipsJEEworkspace/Multi_project/models/input1.xmi"), true);		
		EList<EObject> inObjects = inResource.getContents();
		ModelExtent input = new BasicModelExtent(inObjects);		
		ModelExtent output = new BasicModelExtent();
		ExecutionDiagnostic result = executor.execute(context, input, output);

		if(result.getSeverity() == Diagnostic.OK) {
			List<EObject> outObjects = output.getContents();
		        ResourceSet resourceSet2 = new ResourceSetImpl();
			Resource outResource = resourceSet2.getResource(
			URI.createURI("file:///C:/Users/sama.elrawy/EclipsJEEworkspace/Multi_project/models/output.xmi"), true);
			outResource.getContents().addAll(outObjects);
			outResource.save(Collections.emptyMap());
		} 

[Updated on: Mon, 11 August 2014 16:58]

Report message to a moderator

Previous Topic:Timeout exception while debugging CDO
Next Topic: Executing QVTo Programmatically
Goto Forum:
  


Current Time: Thu Apr 25 22:06:16 GMT 2024

Powered by FUDForum. Page generated in 0.02598 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top