Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » [EVL] Validation of linked model instances
[EVL] Validation of linked model instances [message #1726643] Tue, 15 March 2016 10:49 Go to next message
Glatz Martin is currently offline Glatz MartinFriend
Messages: 23
Registered: March 2016
Junior Member
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 #1726656 is a reply to message #1726643] Tue, 15 March 2016 11:27 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

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 Go to previous messageGo to next message
Glatz Martin is currently offline Glatz MartinFriend
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 #1728016 is a reply to message #1727176] Wed, 30 March 2016 09:14 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Hi Martin,

Sorry for the delay - Easter came up and all that Smile. It sounds like a bug: could you provide a minimal example that reproduces this? [1]

[1]: http://www.eclipse.org/epsilon/doc/articles/minimal-examples/

Kind regards,
Antonio
Re: [EVL] Validation of linked model instances [message #1852626 is a reply to message #1728016] Fri, 27 May 2022 19:46 Go to previous messageGo to next message
Glatz Martin is currently offline Glatz MartinFriend
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 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

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 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

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
Re: [EVL] Validation of linked model instances [message #1852670 is a reply to message #1852646] Mon, 30 May 2022 21:41 Go to previous messageGo to next message
Glatz Martin is currently offline Glatz MartinFriend
Messages: 23
Registered: March 2016
Junior Member
Hi Dimitris and Antonio,

thanks a lot for the quick and very informative answer.


The approach with
modelA.getResource().getResourceSet().getResources().add(b.eResource());
works fine.

With respect to the InMemoryEmfModel, I'm not sure if I understood correctly.

I understood, that I need to have all Ressources within one CashedRessourceSet, therefore I've built something like that:


InMemoryEmfModel modelA = createEmfModel(modelsRoot.resolve("TreeA.xmi").toAbsolutePath().toUri(), modelsRoot.resolve("TreeB.xmi").toAbsolutePath().toUri());


public static InMemoryEmfModel createEmfModel (URI ModelUriMain, URI ModelUriReferenced) throws IOException
{
			
org.eclipse.emf.common.util.URI uriA = org.eclipse.emf.common.util.URI.createURI(ModelUriMain.toString());			
org.eclipse.emf.common.util.URI uriB = org.eclipse.emf.common.util.URI.createURI(ModelUriReferenced.toString());
			
ResourceSet resourceSet = new CachedResourceSet();
			
Resource mainRessource = resourceSet.createResource(uriA);
Resource referencedRessource = resourceSet.createResource(uriB);
			
mainRessource.load(null);
referencedRessource.load(null);
			
			
InMemoryEmfModel test = new InMemoryEmfModel(mainRessource);
return test;
}


Is this approach basically correct how to use the InMemoryEmfModel for my described problem?

Thanks a lot,
Best regards,
Martin
Re: [EVL] Validation of linked model instances [message #1852671 is a reply to message #1852670] Mon, 30 May 2022 21:46 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2154
Registered: July 2009
Location: York, UK
Senior Member

Hi Martin,

Yes - this is correct.

Best,
Dimitris
Re: [EVL] Validation of linked model instances [message #1852678 is a reply to message #1852671] Tue, 31 May 2022 08:13 Go to previous message
Glatz Martin is currently offline Glatz MartinFriend
Messages: 23
Registered: March 2016
Junior Member
Hi Dimitris,
thanks a lot for the great support.
Best regards,
Martin
Previous Topic:Inheritance in ETL
Next Topic:I can't get the UML representation diagram from my .ecore model
Goto Forum:
  


Current Time: Fri Mar 29 09:56:23 GMT 2024

Powered by FUDForum. Page generated in 0.07727 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top