Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Model-to-Model Transformation » [QVT] Calling QVT transformation from within java class
[QVT] Calling QVT transformation from within java class [message #1007526] Wed, 06 February 2013 05:30 Go to previous message
Gabriele Pongelli is currently offline Gabriele Pongelli
Messages: 9
Registered: February 2013
Junior Member
Hi all, this is my first post in Eclipse forum.
I've a question regarding QVT execution from within a java class.

I've to transform an ecore model to an ecorediag model programmatically, I've created an "Operational QVT Project" that contains my ecore model and qvto transformation file that I run with "Run As -> Run Configuration -> Operational QVT Interpreter" that lead to generate ecorediag as expected.

After that I've created a java project with a single java class having only main method, just to call qvto transformation.
I've followed this example, my code is

URI transformationURI = URI.createURI("platform:/resource/myPrj/transforms/myTrasf.qvto", true);
TransformationExecutor executor = new TransformationExecutor(transformationURI);
ExecutionContextImpl context = new ExecutionContextImpl();

ResourceSet resourceSet = new ResourceSetImpl();
Resource inResource = resourceSet.getResource(
URI.createURI("platform:/resource/modelPrj/model/myModel.ecore"), true);		
EList<EObject> inObjects = inResource.getContents();

As you can see it's basically the same code, but this throws an exception on

Resource inResource = resourceSet.getResource(URI.createURI("platform:/resource/modelPrj/model/myModel.ecore"), true);


The exception is
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'platform:/resource/modelPrj/model/myModel.ecore'; a registered resource factory is needed


Another test I did, following "loadUmlModel" method from this code, I've changed my code to
EcorePackage.eINSTANCE.getClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("http://www.eclipse.org/emf/2002/Ecore", new EcoreResourceFactoryImpl());

URI transformationURI = URI.createURI("platform:/resource/myPrj/transforms/myTrasf.qvto", true);
TransformationExecutor executor = new TransformationExecutor(transformationURI);
ExecutionContextImpl context = new ExecutionContextImpl();

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new EcoreResourceFactoryImpl());

URI inUri = URI.createURI("platform:/resource/org.elt.ecore2html/model/tat.ecore");
Resource inResource = resourceSet.getResource(inUri, Boolean.TRUE);

try {
	inResource.load(m);
} catch (IOException e) {
	e.printStackTrace();
}

This code throws an exception on
Resource inResource = resourceSet.getResource(inUri, Boolean.TRUE);
with message Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.io.IOException: The path '/modelPrj/model/myModel.ecore' is unmapped.
I don't know how to map that path, and what map it with.


Does anyone know how to solve this issue and how to execute QVT transformation from within a java class?

Thank you,
Gabriele Pongelli.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:"Many-Model to Model" transformation with qvto?
Next Topic:using blackbox in a qvt transformation called by java
Goto Forum:
  


Current Time: Wed May 22 14:49:21 EDT 2013

Powered by FUDForum. Page generated in 0.02066 seconds