[EOL] Model objects manipulation (copying...) [message #1065765] |
Thu, 27 June 2013 12:31 |
Gaëtan Pruvost Messages: 19 Registered: June 2013 |
Junior Member |
|
|
Hi guys,
I'm trying to make some operations upon models inside an EOL script and I need some guidance here. My problem should be common but I haven't seen anything in book/articles/forum about it.
A little background
I'm trying to copy a model IN to a model OUT. My eol script is run with both model described correctly in the eclipse run configuration.
Problem:
I can't find a proper way of copying model instances. I tried the following Native tools:
- ECoreUtil.copy
EmfTool.getECoreUtil().copy(...my root in IN...);
I get a copy of instances but they still relate to the IN model (via owningModel()) and I can't change it.
- EmfTool.createModel2
System.context.getModelRepository().removeModel(OUT);
var m = EmfTool.createModel2(...my root in IN..., "OUT", fileURI);
m.readOnLoad = false;
m.storedOnDisposal = true;
This one works to make the copy, the stored file is valid. However I can't navigate the model in the rest of the script. For instance, if I write OUT!A.all, I get zero instances even though my model has some.
Is my approach to the problem wrong, or have I missed a trivial solution to the problem?
Subsidiary questions
- Could you give me pointers for java native tools? The article that introduces them doesn't give any doc of them and looking at the sources only lead me to uncertain guesses.
- I don't understand the behaviour of the OUT variable. How does the script engine resolve model names? It looks like it is dynamically resolved to an IModel instance based on the model repository. However, I checked in debug, my context seems to be ok.
Moreover, I don't get why the script crashes if I try to write m!A when m is an IModel variable and A a concept name.
Thanks a lot
Cheers
[Updated on: Thu, 27 June 2013 12:35] Report message to a moderator
|
|
|
Re: [EOL] Model objects manipulation (copying...) [message #1065888 is a reply to message #1065765] |
Fri, 28 June 2013 07:22 |
|
Hi Gaëtan,
The following might work:
var root = EmfTool.getECoreUtil().copy(...my root in IN...);
OUT.resource.contents.add(root);
> - Could you give me pointers for java native tools? The article that introduces them doesn't give any doc of them and looking at the sources only lead me to uncertain guesses.
There's no additional documentation for native tools I'm afraid - mostly because I can't think of what else we should add. Any thoughts?
> - I don't understand the behaviour of the OUT variable. How does the script engine resolve model names? It looks like it is dynamically resolved to an IModel instance based on the model repository.
That is correct.
> However, I checked in debug, my context seems to be ok.
> Moreover, I don't get why the script crashes if I try to write m!A when m is an IModel variable and A a concept name.
Could you please attach some code so that I can test?
Cheers,
Dimitris
|
|
|
Re: [EOL] Model objects manipulation (copying...) [message #1065937 is a reply to message #1065888] |
Fri, 28 June 2013 12:08 |
Gaëtan Pruvost Messages: 19 Registered: June 2013 |
Junior Member |
|
|
Hi Dimitris,
Your solution partly works: the copy is done properly (the stored file has the instances) but I still can't access my data in the following of the script
OUT!A.all returns an empty sequence.
On the other hand, I can create a new model with
emfTool.createModel2(IN!Root.all.first()
, "OUT2"
, "/epsilon.ztests/forum/gen-model2.model");
var m = System.context.getModelRepository().getModelByName("OUT2");
m.readOnLoad = false;
m.storedOnDisposal = true;
But then it works only if I give the model a different name than the one defined in the "run configuration".
Attached is a minimal example where both solutions are tested.
Please, setup the "run configuration" with IN and OUT before running the script.
[Updated on: Wed, 03 July 2013 09:10] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01580 seconds