empty Resource? [message #478168] |
Thu, 06 August 2009 08:45 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
I'm trying to rogrammatically execute a QVT transformation. Therefore I
took the example code from the wiki [1]. My method looks like this:
private void executeTransformation(URI transformationURI, URI
selectedModel){
TransformationExecutor executor = new
TransformationExecutor(transformationURI);
Resource inResource = new ResourceImpl(selectedModel);
EList<EObject> inObjects = inResource.getContents();
ModelExtent input = new BasicModelExtent(inObjects);
ExecutionContextImpl context = new ExecutionContextImpl();
context.setConfigProperty("keepModeling", true);
ExecutionDiagnostic result = executor.execute(context, input);
}
The problem is that inResource has no contents. That's why inObjects is
an empty Elist and the transformation does nothing. No exceptions is
thrown - it just happens nothing. I don't know why the contents is
empty. Maybe the URI is generated wrong. I contributed a command to the
context menu of the EMF generated editor. In the command handler I
retrieve the active model in this way:
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String transFile = event.getParameter(Activator.TRANSFORMATION_PARAM_ID);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor.getEditorInput() instanceof FileEditorInput){
URI emfURI = convertIFiletoEmfURI(((FileEditorInput)
editor.getEditorInput()).getFile());
executeTransformation(getTransformation(transFile), emfURI);
}
return null;
}
The transFile is a qvto file contained in the plugin. The generation of
the URI is:
private static URI convertIFiletoEmfURI(IFile file) {
if(file == null){
return null;
}
URI emfURI =
URI.createPlatformResourceURI(file.getFullPath().toString(), true);
return emfURI;
}
I can't see why the contents is empty - but maybe anyone of you knows it?
[1] http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava
|
|
|
Re: empty Resource? [message #478698 is a reply to message #478168] |
Thu, 06 August 2009 12:34 |
Ed Merks Messages: 33147 Registered: July 2009 |
Senior Member |
|
|
Gilbert,
Comments below.
Gilbert Mirenque wrote:
> I'm trying to rogrammatically execute a QVT transformation. Therefore I
> took the example code from the wiki [1]. My method looks like this:
>
> private void executeTransformation(URI transformationURI, URI
> selectedModel){
> TransformationExecutor executor = new
> TransformationExecutor(transformationURI);
> Resource inResource = new ResourceImpl(selectedModel);
> EList<EObject> inObjects = inResource.getContents();
> ModelExtent input = new BasicModelExtent(inObjects);
> ExecutionContextImpl context = new ExecutionContextImpl();
> context.setConfigProperty("keepModeling", true);
> ExecutionDiagnostic result = executor.execute(context, input);
> }
>
I won't be able to say much about QVT itself, but this is not a good way
to load a resource. Create a resource set and use getResource(<uri>,
true) for that purpose.
> The problem is that inResource has no contents. That's why inObjects is
> an empty Elist and the transformation does nothing.
ResourceImpl isn't even capable of loading anything. You'll find
isLoaded is false and that calling load fails.
> No exceptions is
> thrown - it just happens nothing. I don't know why the contents is
> empty.
You didn't load it, nor use an appropriate resource implementation, nor
is simply newing a resource implementation the ideal way.
> Maybe the URI is generated wrong. I contributed a command to the
> context menu of the EMF generated editor. In the command handler I
> retrieve the active model in this way:
>
> @Override
> public Object execute(ExecutionEvent event) throws ExecutionException {
> String transFile = event.getParameter(Activator.TRANSFORMATION_PARAM_ID);
> IEditorPart editor = HandlerUtil.getActiveEditor(event);
> if(editor.getEditorInput() instanceof FileEditorInput){
> URI emfURI = convertIFiletoEmfURI(((FileEditorInput)
> editor.getEditorInput()).getFile());
> executeTransformation(getTransformation(transFile), emfURI);
> }
> return null;
> }
>
> The transFile is a qvto file contained in the plugin. The generation of
> the URI is:
>
> private static URI convertIFiletoEmfURI(IFile file) {
> if(file == null){
> return null;
> }
> URI emfURI =
> URI.createPlatformResourceURI(file.getFullPath().toString(), true);
> return emfURI;
> }
>
> I can't see why the contents is empty - but maybe anyone of you knows it?
>
If you generate the *.tests project for some model, you'll see and
XyzExample.java that better illustrates what's needed.
>
> [1] http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: empty Resource? [message #478752 is a reply to message #478698] |
Thu, 06 August 2009 16:39 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
Hi Ed,
Ed Merks wrote:
> If you generate the *.tests project for some model, you'll see and
> XyzExample.java that better illustrates what's needed.
Thanks a lot for this hint. It works.
|
|
|
Powered by
FUDForum. Page generated in 0.03705 seconds