Running QVTo in a standalone JAVA project [message #1733631] |
Mon, 30 May 2016 14:24 |
Mouna Lab Messages: 4 Registered: May 2016 |
Junior Member |
|
|
Hi,
I am trying to run a QVTo M2M transformation from a standalone JAVA project:
I have tried to follow the code specified by the link https://wiki.eclipse.org/QVTOML/Examples/InvokeInJava . My main method goes as follows:
public static void main(String[] args) {
// Refer to an existing transformation via URI
URI transformationURI = URI
.createFileURI("../transformation.M2M.RoleOperations/transforms/RoleOperations.qvto");
// create executor for the given transformation
TransformationExecutor executor = new TransformationExecutor(transformationURI);
try {
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource inResource = set.getResource(
URI.createFileURI("../model.UseCase/AC.uml"),
true);
EList<EObject> inObjects = inResource.getContents();
// create the input extent with its initial contents
ModelExtent input = new BasicModelExtent(inObjects);
// create an empty extent to catch the output
ModelExtent output = new BasicModelExtent();
// setup the execution environment details ->
// configuration properties, logger, monitor object etc.
ExecutionContextImpl context = new ExecutionContextImpl();
context.setConfigProperty("keepModeling", true);
// run the transformation assigned to the executor with the given
// input and output and execution context
ExecutionDiagnostic result = executor.execute(context, input, output);
// check the result for success
if (result.getSeverity() == Diagnostic.OK) {
// the output objects got captured in the output extent
List<EObject> outObjects = output.getContents();
// let's persist them using a resource
ResourceSet resourceSet2 = new ResourceSetImpl();
Resource outResource = resourceSet2.getResource(
URI.createURI(
"../transformation.M2M.RoleOperations/TestJAVA.RoleOperation"),
true);
outResource.getContents().addAll(outObjects);
outResource.save(Collections.emptyMap());
System.out.println("RoleOperations model saved");
} else {
System.out.println("*** " + result.getMessage());
}
} catch (IOException e) {
System.out.println("Saving failed");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
The line where i run the transformation assigned to the executor "ExecutionDiagnostic result = executor.execute(context, input, output);" throws a java.lang.IllegalArgumentException.
where the stacktrace goes as follows:
java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base
at org.eclipse.emf.common.util.URI$Hierarchical.resolve(URI.java:3516)
at org.eclipse.emf.common.util.URI.resolve(URI.java:5547)
at org.eclipse.m2m.internal.qvt.oml.compiler.URIUnitResolver.doResolveUnit(URIUnitResolver.java:111)
at org.eclipse.m2m.internal.qvt.oml.compiler.URIUnitResolver.doResolveUnit(URIUnitResolver.java:93)
at org.eclipse.m2m.internal.qvt.oml.compiler.DelegatingUnitResolver.resolveUnit(DelegatingUnitResolver.java:45)
at org.eclipse.m2m.internal.qvt.oml.compiler.DelegatingUnitResolver.resolveUnit(DelegatingUnitResolver.java:37)
at org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory.findUnit(UnitResolverFactory.java:39)
at org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory.access$0(UnitResolverFactory.java:37)
at org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory$Registry$BasicRegistry.getUnit(UnitResolverFactory.java:117)
at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doLoad(InternalTransformationExecutor.java:282)
at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.loadTransformation(InternalTransformationExecutor.java:142)
at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:195)
at org.eclipse.m2m.qvt.oml.TransformationExecutor.execute(TransformationExecutor.java:152)
at execution.qvto.main.MainClass.main(MainClass.java:80)
Does anybody have an idea where is the problem (i'm actually new to EMF). I have assumed that the path string is wrong so i changed it with (platform:/resource/transformation.M2M.RoleOperations/transforms/RoleOperations.qvto) but still the same.
Thank you in advance!
[Updated on: Tue, 31 May 2016 06:51] Report message to a moderator
|
|
|
Re: Running QVTo in a standalone JAVA project [message #1733669 is a reply to message #1733631] |
Mon, 30 May 2016 22:25 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
You will generally do much better if you ask QVTo questions on the QVTo
newsgroup.
If you use the debugger you can see which two URIs are resolved and may
understand which is incomatible with the resolve API.
Using platform:/resurce is not usually helpful in simple standalone
applications. Using relative URIs is also unhelpful. Convert URIs to
absolute before passing to simple EMF-based tools.
(In more complex applications that have an ability to resolve platform:
as a virtual location, using platform: is a good idea.)
Regards
Ed Willink
On 30/05/2016 21:46, Mouna LAB wrote:
> Hi,
>
> I am trying to run a QVTo M2M transformation from a standalone JAVA
> project:
> I have tried to follow the code specified by the link
> https://wiki.eclipse.org/QVTOML/Examples/InvokeInJava . My main method
> goes as follows:
> public static void main(String[] args) {
>
> // Refer to an existing transformation via URI
> URI transformationURI = URI
>
> .createFileURI("../transformation.M2M.RoleOperations/transforms/RoleOperations.qvto");
>
>
> // create executor for the given transformation
> TransformationExecutor executor = new
> TransformationExecutor(transformationURI);
>
> try {
> ResourceSet set = new ResourceSetImpl();
> set.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
> set.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
> .put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> Resource inResource = set.getResource(
> URI.createFileURI("../model.UseCase/AC.uml"),
> true);
>
> EList<EObject> inObjects = inResource.getContents();
>
> // create the input extent with its initial contents
> ModelExtent input = new BasicModelExtent(inObjects);
> // create an empty extent to catch the output
> ModelExtent output = new BasicModelExtent();
>
> // setup the execution environment details ->
> // configuration properties, logger, monitor object etc.
> ExecutionContextImpl context = new ExecutionContextImpl();
> context.setConfigProperty("keepModeling", true);
>
> // run the transformation assigned to the executor with the
> given
> // input and output and execution context
> ExecutionDiagnostic result = executor.execute(context, input, output);
>
> // check the result for success
> if (result.getSeverity() == Diagnostic.OK) {
> // the output objects got captured in the output extent
> List<EObject> outObjects = output.getContents();
> // let's persist them using a resource
> ResourceSet resourceSet2 = new ResourceSetImpl();
> Resource outResource = resourceSet2.getResource(
> URI.createURI(
>
> "../transformation.M2M.RoleOperations/TestJAVA.RoleOperation"),
> true);
> outResource.getContents().addAll(outObjects);
>
> outResource.save(Collections.emptyMap());
> System.out.println("RoleOperations model saved");
>
> } else {
> System.out.println("*** " + result.getMessage());
> }
> } catch (IOException e) {
> System.out.println("Saving failed");
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> The line where i run the transformation assigned to the executor
> "ExecutionDiagnostic result = executor.execute(context, input, output);"
> throws a java.lang.IllegalArgumentException.
>
> where the stacktrace goes as follows:
> java.lang.IllegalArgumentException: resolve against non-hierarchical or
> relative base
> at org.eclipse.emf.common.util.URI$Hierarchical.resolve(URI.java:3516)
> at org.eclipse.emf.common.util.URI.resolve(URI.java:5547)
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.URIUnitResolver.doResolveUnit(URIUnitResolver.java:111)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.URIUnitResolver.doResolveUnit(URIUnitResolver.java:93)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.DelegatingUnitResolver.resolveUnit(DelegatingUnitResolver.java:45)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.DelegatingUnitResolver.resolveUnit(DelegatingUnitResolver.java:37)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory.findUnit(UnitResolverFactory.java:39)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory.access$0(UnitResolverFactory.java:37)
>
> at
> org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory$Registry$BasicRegistry.getUnit(UnitResolverFactory.java:117)
>
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doLoad(InternalTransformationExecutor.java:282)
>
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.loadTransformation(InternalTransformationExecutor.java:142)
>
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:195)
>
> at
> org.eclipse.m2m.qvt.oml.TransformationExecutor.execute(TransformationExecutor.java:152)
>
> at fr.lig.vasco.execution.qvto.main.MainClass.main(MainClass.java:80)
>
> Does anybody have an idea where is the problem (i'm actually new to
> EMF). I have assumed that the path string is wrong so i changed it with
> (platform:/resource/transformation.M2M.RoleOperations/transforms/RoleOperations.qvto)
> but still the same.
>
> Thank you in advance!
|
|
|
|
Powered by
FUDForum. Page generated in 0.03568 seconds