Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Validation best practices
Validation best practices [message #1490960] Fri, 28 November 2014 15:41 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Hi there,

does anyone have best practices for doing *simple* validation rules for
EMF ecore models?

I tried using the "constraints" EAnnotation which generates an empty
validation method that has to be implemented in Java.

First, this is quite effort prone, compared for example to restrictions
to simple types in an XSD.

Second, I have many data types that are restricted in the same way, e.g.
an integer that may have a value between 0 and 63 where a generic error
message would be sufficient. The generated validation methods, however,
have to be implemented for every class again, so I cannot reuse the same
validation method.

Any best practices? Or is the question too general?

Cheers,
Hauke
Re: Validation best practices [message #1491913 is a reply to message #1490960] Sat, 29 November 2014 10:54 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Hi Hauke,

I don't know if this is too over-engineered for your use case, but the latest developer builds of Sphinx contain a new validation/check framework that might also be usable for plain EMF.
The basic concept is, that you register validator classes for your meta-model and the framework finds the relevant checks by annotations/reflection:
public class Hummingbird20BasicCheckValidator extends AbstractCheckValidator {

	@Check
	void checkApplicationName(Application application) {
		error("Application name is not valid", application, Common20Package.Literals.IDENTIFIABLE__NAME); //$NON-NLS-1$
		
	}
}

You can find a demo project at
http://git.eclipse.org/c/sphinx/org.eclipse.sphinx.git/tree/examples/org.eclipse.sphinx.examples.hummingbird20.check.withcatalog


Re: Validation best practices [message #1494164 is a reply to message #1490960] Mon, 01 December 2014 08:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30467
Registered: July 2009
Senior Member
Hauke,

The constraints generated for XSD are driven by extended metadata
annotations (facets), so you could use those same annotations on your
own model.


On 28/11/2014 4:41 PM, Hauke Fuhrmann wrote:
> Hi there,
>
> does anyone have best practices for doing *simple* validation rules
> for EMF ecore models?
>
> I tried using the "constraints" EAnnotation which generates an empty
> validation method that has to be implemented in Java.
>
> First, this is quite effort prone, compared for example to
> restrictions to simple types in an XSD.
>
> Second, I have many data types that are restricted in the same way,
> e.g. an integer that may have a value between 0 and 63 where a generic
> error message would be sufficient. The generated validation methods,
> however, have to be implemented for every class again, so I cannot
> reuse the same validation method.
>
> Any best practices? Or is the question too general?
>
> Cheers,
> Hauke
Previous Topic:XMI Resource & "OutOfMemoryError: GC Overhead limit exceeded"
Next Topic:XMI file
Goto Forum:
  


Current Time: Mon Sep 23 11:51:07 GMT 2019

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

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

Back to the top