Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Executing QVTo in java
Executing QVTo in java [message #1407013] Mon, 11 August 2014 17:02 Go to next message
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());
		} 
Re: Executing QVTo in java [message #1407198 is a reply to message #1407013] Tue, 12 August 2014 04:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sama,

It's best to ask about QVTo on the eclipse.qvto forum.


On 11/08/2014 7:02 PM, Sama Elrawy wrote:
> 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());
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic: Executing QVTo Programmatically
Next Topic:Copying cross references
Goto Forum:
  


Current Time: Thu Apr 25 13:57:52 GMT 2024

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

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

Back to the top