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 10:30 |
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.
|
|
|
Re: [QVT] Calling QVT transformation from within java class [message #1008572 is a reply to message #1007526] |
Wed, 13 February 2013 06:43 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
Sorry for the slow response; busy ...
Your first problem that you solved yourself was failing to register a
Resource Factory.
Your second problem was use of a platform:/... URI in a standalone
environment.
If you are working standalone alone it is easiest to just use absolute
createFileURI s.
If you really want to use platform URIs then you need to initialize the
Ecore registries, probably using EcorePlugin.computePlatformURIMap().
None of these problems are anything to do with QVTo or Java; just normal
EMF working practice.
Regards
Ed Willink
On 06/02/2013 13:52, Gabriele Pongelli wrote:
> 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 http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava, 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
> http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/extraplugins/java/org.eclipse.papyrus.java.generator.jdtsynchronizer/src/org/eclipse/papyrus/java/generator/jdtsynchronizer/RunGenerator.java,
> 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.
|
|
| |
Re: [QVT] Calling QVT transformation from within java class [message #1009010 is a reply to message #1008608] |
Thu, 14 February 2013 09:45 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
The EMF book is very helpful in many areas, but there are so many
corners that it is impossible to cover all of them, and the minor but
significant changes in the last few years are missing.
I've not seen a clear exposition of the URI policy that causes so much
trouble for hybrid Eclipse/standalone users. I developed
org.eclipse.ocl.examples.domain.utilities.ProjectMap to hide most of the
difficulties. Very recently, the EcorePlugin functionality has been
enhanced making ProjectMap redundant for many use cases.
Regards
Ed Willink
On 13/02/2013 09:32, Gabriele Pongelli wrote:
> Hi Ed, don't worry about slow response ;)
> My comments are below.
>
>
> Ed Willink wrote on Wed, 13 February 2013 01:43
>> Hi
>>
>> Sorry for the slow response; busy ...
>>
>> Your first problem that you solved yourself was failing to register a
>> Resource Factory.
>>
>> Your second problem was use of a platform:/... URI in a standalone
>> environment.
>>
>> If you are working standalone alone it is easiest to just use
>> absolute createFileURI s.
>
> I used "platform:/.." URI because this class will be included inside a
> plugin, I've already changed to an absolute path with the remind to
> change to a relative one when this code will be merged inside plugin.
>
>
> Ed Willink wrote on Wed, 13 February 2013 01:43
>> If you really want to use platform URIs then you need to initialize
>> the Ecore registries, probably using
>> EcorePlugin.computePlatformURIMap().
>
> I'll try ;)
>
>
> Ed Willink wrote on Wed, 13 February 2013 01:43
>> None of these problems are anything to do with QVTo or Java; just
>> normal EMF working practice.
>
> Where can I find other EMF's working practice? Are there books or links?
>
>
> Thank you!
|
|
| |
Re: [QVT] Calling QVT transformation from within java class [message #1009540 is a reply to message #1009519] |
Fri, 15 February 2013 09:42 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
Yes
Regards
Ed Willink
On 15/02/2013 09:15, Gabriele Pongelli wrote:
> Ed Willink wrote on Thu, 14 February 2013 04:45
>> Hi
>>
>> The EMF book is very helpful in many areas, but there are so many
>> corners that it is impossible to cover all of them, and the minor but
>> significant changes in the last few years are missing.
>
> Did you mean EMF: Eclipse Modeling Framework - Dave Steinberg, Frank
> Budinsky, Marcelo Paternostro, Ed Merks - Second Edition 2009 ?
>
>
> Ed Willink wrote on Thu, 14 February 2013 04:45
>> I've not seen a clear exposition of the URI policy that causes so
>> much trouble for hybrid Eclipse/standalone users. I developed
>> org.eclipse.ocl.examples.domain.utilities.ProjectMap to hide most of
>> the difficulties. Very recently, the EcorePlugin functionality has
>> been enhanced making ProjectMap redundant for many use cases.
>
> I've looked at ProjectMap and EcorePlugin classes and I'm trying to
> let URI works.
>
>
>
> Thank you ;) !!
|
|
| | |
Goto Forum:
Current Time: Fri Sep 20 19:15:34 GMT 2024
Powered by FUDForum. Page generated in 0.03843 seconds
|