Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Validation Framework and reading a file(Validating model elements against information read from a file.)
EMF Validation Framework and reading a file [message #1807799] Mon, 10 June 2019 00:25 Go to next message
James Clark is currently offline James ClarkFriend
Messages: 15
Registered: December 2016
Junior Member
I've implemented several model constraints by extending the class AbstractModelConstraint. Now I would like to validate some elements against some information read from a CSV file. I would put the validation info read into an in-memory collection to be accessed by the validate() method. For efficiency I'd like to read the file only once from storage. Could someone suggest an appropriate place to read the file/code design?
Re: EMF Validation Framework and reading a file [message #1807801 is a reply to message #1807799] Mon, 10 June 2019 05:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30686
Registered: July 2009
Senior Member
Is there only one such file? Is that file in the workspace (where it can change over time), or is it bundled with the plug-in that's implementing this validation (so it's effectively a constant)? Are you wanting to share this information across multiple constraints?

When org.eclipse.emf.validation.AbstractModelConstraint.validate(IValidationContext) is called, it's passed the context and there you can use org.eclipse.emf.validation.IValidationContext.putCurrentConstraintData(Object) to cache data. Is that sufficient for your purpose?
Re: EMF Validation Framework and reading a file [message #1807831 is a reply to message #1807801] Mon, 10 June 2019 13:30 Go to previous messageGo to next message
James Clark is currently offline James ClarkFriend
Messages: 15
Registered: December 2016
Junior Member
Yes, one file for one constraint generally. It would be available in the workspace and the contents would change over time, so I'd want to to read it when Eclipse starts. I think I might want to share it amongst several constraints.

putCurrentConstraintData()/getCurrentConstraintData() calls might work for me. So when getCurrentConstraintData() returns null would be the appropriate time to read the file, set up my collection, and pass it to putCurrentConstraintData()?
Re: EMF Validation Framework and reading a file [message #1807836 is a reply to message #1807831] Mon, 10 June 2019 15:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6534
Registered: July 2009
Senior Member
Hi

The EMF Validation Framework (EMFv) is a very old approach to model validation that motivated the EMF EValidator functionality and the EMF ValidationDelegates. Are you sure you really mean to struggle with EMFv? Have you been misled by some vintage Eclipse corner articles, which should have a disclaiming prefix?

If you are are Java programmer, you may find that embedding Java in your Ecore models is easier. You may find that Xcore gives a friendlier programming language.

If you like OCL you may want to use OCLinEcore to embed and code generate OCL constraints direct into your code generated Java.

If you want an independent validation tool you might try the Epsilon Validation language.

Xtext also provides a Checks language that you might find helpful.

But I really wouldn't recommend EMFv for new developments, the project is on life support.

Regards

Ed Willink



Re: EMF Validation Framework and reading a file [message #1807837 is a reply to message #1807836] Mon, 10 June 2019 16:33 Go to previous messageGo to next message
James Clark is currently offline James ClarkFriend
Messages: 15
Registered: December 2016
Junior Member
I didn't share the fact that this validation work is being done within the IBM Rational Software Architect v9.1.x product on BPMN and UML models. So not on the leading edge of Eclipse for sure.
Re: EMF Validation Framework and reading a file [message #1807958 is a reply to message #1807837] Thu, 13 June 2019 09:11 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 309
Registered: December 2015
Senior Member
There are some issues with putCurrentConstraintData()/getCurrentConstraintData(). For one, this data is local to every single constraint, so if you have 2 constraints, they can't share the same information, which is maybe puristic, but it sucks in practice. Then, there is a bug that makes putCurrentConstraintData fail on its first invocation, so the first _two_ getCurrentConstraintData calls will be a miss. I'm not sure how the Eclipse Resources plugin handles reading files multiple times, doesn't it already implement some sort of caching, so maybe you don't need to worry actually?
Re: EMF Validation Framework and reading a file [message #1807963 is a reply to message #1807958] Thu, 13 June 2019 11:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30686
Registered: July 2009
Senior Member
As you can see, things don't get fixed in this framework. :-( No, as far as I know, te resources framework will not cache anything. Reading a file twice will read it from disk twice.
Previous Topic:Finding the edit resource locator for an EAttribute
Next Topic:Over-riding EContentAdapter#addAdapter - side effects?
Goto Forum:
  


Current Time: Sun Dec 08 21:48:16 GMT 2019

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

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

Back to the top