Home » Modeling » Epsilon » [EVL] Validation of linked model instances
[EVL] Validation of linked model instances [message #1726643] |
Tue, 15 March 2016 06:49  |
Eclipse User |
|
|
|
Hello,
I'm interested whats the most simple/straightforward solution to overcome following situation and would appreciate tipps:
I'm having a metamodel which basically stores 4 different "libaries" as trees, and in addition can have external references, which comply to the same metamodel. The problem is - the reference in the model instance is a URi to the file, where the referenced model instance is located.
So basically:
root
-externalReferenceTolib1a
-externalReferenceToLib2a
-lib1
-lib2
-lib3
-lib4
The EVL rules have to apply for the "root" model instance as well as the external referenced models (it is not enough to vaidate each model on it's own).
Is there a simple way to dynamically load the models which are referenced with the URi's and "link" it to the root-model?
Thanks a lot in advance,
Best regards
Martin
|
|
| | | |
Re: [EVL] Validation of linked model instances [message #1852626 is a reply to message #1728016] |
Fri, 27 May 2022 15:46   |
Eclipse User |
|
|
|
Hi Antonio,
the apologies for late reply is fully on my side.
Thanks for your answer back then - I found a workaround with epsilon 0.9, which from my point of view isn't working anymore with Epsilon Core version 2.4.0.202203041826 (or I already used the framework wrong back then).
I tried to put the a minimal example to present the problem I'm facing.
I have a project treegraph, which is based on a simple ecore model and a project LinkedTrees, which reads two independent model instances (TreeA-_tree1) and (TreeB - _tree4) based on xmi-Files.
Basically I'd like to execute a EVL file on interlinked models (whereas I'd like to execute the evl only on the root model, and the referenced models are considered automatically).
To achive this I put a reference from TreeA to TreeB
(a.getReferences().add(b);)
To check the in memory model I save the model TreeA via store and then register TreeA at the model repository and execute the Demo.evl file.
Altough the updated model TreeA looks fine, the evaluation result of the evl File is empty.
If I execute the sourcefile a second time (with the already updated TreeA.xmi) and remove a.getReferences().add(b); (so the reference from TreeA to TreeB isn't added during runtime, but already exists at load) the execute model returns as expected "[Invariant IsPositive failed for treegraph.impl.TreeImpl@45752059 (positiveNumber: -3)]".
Am I doing something wrong, or why is in the first case the reference between the two trees not considered during evl evalution?
Best regards,
Martin
|
|
|
Re: [EVL] Validation of linked model instances [message #1852640 is a reply to message #1852626] |
Sun, 29 May 2022 08:29   |
Eclipse User |
|
|
|
I had a look at the example, and poked around with the debugger a bit. In short, it's best to break up models into fragments across containment references, otherwise you need to make sure that all the various containment trees are in your model's resource set before EVL runs. Your example just so happens to naturally do that from its second run, but it's more of a happy accident than reliable and intentional behaviour :-). I'll try to explain what's going on.
In the first run, TreeA.xmi and TreeB.xmi are both loaded into memory, and then a reference from TreeA to TreeB is added but without changing the resource set of modelA, which still only contains TreeA.xmi. EVL will traverse the containment tree of all resources in modelA's resource set to find the Tree objects, and so it will not find the invalid Tree in TreeB.xmi.
In the second run, while loading TreeA.xmi into modelA, EMF will automatically load TreeB.xmi during proxy resolution. Since this is the first time TreeB.xmi is loaded in the whole program, the CachedResourceSet class in Epsilon will load the file and add it to modelA's resource set. Everything works fine now, since modelA's resource set has both TreeA.xmi and TreeB.xmi.
However, this is not reliable: if you simply swap the loading of modelA and modelB in your sample program, you will have loaded modelB *before* modelA. modelA and modelB use different CachedResourceSet objects but they both pull resources from the same global Cache. Since TreeB.xmi will have been loaded by the time TreeA.xmi wants to do proxy resolution, you will get your proxies resolved correctly but modelA's resource set will only have TreeA.xmi again, and you will never see the invalid object from TreeA.xmi no matter how many times you run this.
What *actually* always works is to specifically add modelB's resource to modelA's resource set any time before you run EVL:
modelA.getResource().getResourceSet().getResources().add(b.eResource());
As I said above, you'll need to ensure the model's resource set has at least the root fragments of all your containment hierarchies. Here, TreeA.xmi and TreeB.xmi are two separate containment hierarchies.
@Dimitris: the fact that CachedResourceSet's behaviour results in slightly different results depending on model loading is a bit odd. Should we a) make it so CachedResourceSet always adds the new resource to its resource set if it wasn't already there, regardless of whether it is newly loaded or not, and/or b) use a regular ResourceSetImpl if the user asked for no caching?
|
|
| | | | |
Goto Forum:
Current Time: Wed Jul 23 21:13:22 EDT 2025
Powered by FUDForum. Page generated in 0.28600 seconds
|