Home » Modeling » Epsilon » [EVL] Validation of linked model instances
|
Re: [EVL] Validation of linked model instances [message #1726656 is a reply to message #1726643] |
Tue, 15 March 2016 11:27 |
|
This should Just Work (TM), as long as you use standard cross-resource EReferences to join up the different files and check the "Include external file references" box in the EMF model that you use in the EVL launch configuration.
I've attached a simple example that does just that: it runs an EVL validation on the main model, which has a reference to an external model. As long as you check the "Include external file references" box, it will find the tree node with a negative integer value.
Note: to create these cross-resource references, just open the main model, right-click on the background of the editor and use "Load Resource..." to load the other model into the same ResourceSet. You should be then able to select the objects of the other resource as targets to your references as well, and EVL will be able to follow those references automatically.
[Updated on: Tue, 15 March 2016 11:30] Report message to a moderator
|
|
|
Re: [EVL] Validation of linked model instances [message #1727176 is a reply to message #1726656] |
Mon, 21 March 2016 00:11 |
Glatz Martin Messages: 23 Registered: March 2016 |
Junior Member |
|
|
Hello Antonio,
sorry for late reply - thank you very much for your example.
The problem I was facing is that my input for validation is a XML based on a schema and the type of the reference is just a String:
<externalReference alias="BaseRoleClassLib" path="Libs/RoleClass Libraries/AutomationMLBaseRoleClassLib.aml">
I've created in the meantime an additional EReference within my metamodel - I load the referenced model in Java code and set the EReference - then I get:
<externalReference alias="BaseRoleClassLib" path="Libs/RoleClass Libraries/AutomationMLBaseRoleClassLib.aml">
<linkedModel href="./bin/amlValidationSuite/models/AutomationMLBaseRoleClassLib.xmi#/"/>
</externalReference>
after I call store();
But - and I'm not sure it its intentionally - if I hand over the model then to the model repository the referenced model is ignored - also a load of the same model didn't solve the problem (EmfModel.PROPERTY_CACHED is set to false during load)
After a lot of try and error I found out that I have to call disposeModel in EmfModel and reload the model that it works - dispose (in IModel) didn't work either.
The question is - is this a bug or a feature?
Best regards,
Martin
[Updated on: Mon, 21 March 2016 07:15] Report message to a moderator
|
|
| |
Re: [EVL] Validation of linked model instances [message #1852626 is a reply to message #1728016] |
Fri, 27 May 2022 19:46 |
Glatz Martin Messages: 23 Registered: March 2016 |
Junior Member |
|
|
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 12:29 |
|
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?
|
|
|
Re: [EVL] Validation of linked model instances [message #1852646 is a reply to message #1852640] |
Sun, 29 May 2022 17:47 |
|
Hi both,
> 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
As each resource can only exist under one resource set IIRC, with the proposed behaviour CachedResourceSet would potentially remove resources from their existing resource set, which could create issues elsewhere.
> b) use a regular ResourceSetImpl if the user asked for no caching?
The aim of CachedResourceSet is to avoid loading the same resource multiple times if it is referenced from different models, while the cached flag is about caching allOfKind/allOfType.
This feels like a non-trivial case for which InMemoryEmfModel could be a better fit than EmfModel.
Best,
Dimitris
|
|
| | | |
Goto Forum:
Current Time: Mon Apr 29 06:40:37 GMT 2024
Powered by FUDForum. Page generated in 0.03888 seconds
|