Executing QVTo in java [message #1407013] |
Mon, 11 August 2014 17:02 |
Sama Elrawy 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 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03535 seconds