Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Validating an EMF model programatically
Validating an EMF model programatically [message #622929] Tue, 25 May 2010 19:23 Go to next message
Hector Chavez is currently offline Hector Chavez
Messages: 34
Registered: February 2010
Member
Hi everyone, I posted this question a couple of days ago in the UML forum but it seems that I should have used the EMF newsgroup instead, so I'm just moving the message.

------------------------------------------------------------ ----------------------------------------

I was going over the EMF Validation Framework example and I was able to set everything up and add a few extra constraints. Then I run the plugin as an eclipse application, I create the model and then in the editor menu I can select validate to check the constraints and everything works fine.

But I was wondering if it is possible to validate a model programmatically, without using the editor.

// For example, create a few objects:

Book myBook = EXTLibraryFactory.eINSTANCE.createBook();
myBook.setTitle("EMF Validation");
Writer writer = EXTLibraryFactory.eINSTANCE.createWriter();
writer.setName("Hector");

//And then do the validation

I've been searching the web with no luck. Can something like this be done? I would appreciate any hints.

Thanks.
Re: Validating an EMF model programatically [message #622930 is a reply to message #622929] Wed, 26 May 2010 03:16 Go to previous message
Jonas Helming is currently offline Jonas Helming
Messages: 410
Registered: July 2009
Senior Member
Hi,
it should work like this:

YourValidationClientSelector.setRunning(true);
IBatchValidator validator = (IBatchValidator)
ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
validator.setIncludeLiveConstraints(true);
IStatus status = validator.validate(object);
ValidationClientSelector.setRunning(false);

Furthermore I would look into the existing handler of the editor...
Cheers
Jonas



Hector Chavez wrote:
> Hi everyone, I posted this question a couple of days ago in the UML
> forum but it seems that I should have used the EMF newsgroup instead, so
> I'm just moving the message.
> ------------------------------------------------------------
> ----------------------------------------
>
> I was going over the EMF Validation Framework example and I was able to
> set everything up and add a few extra constraints. Then I run the plugin
> as an eclipse application, I create the model and then in the editor
> menu I can select validate to check the constraints and everything works
> fine.
> But I was wondering if it is possible to validate a model
> programmatically, without using the editor.
>
> // For example, create a few objects:
>
> Book myBook = EXTLibraryFactory.eINSTANCE.createBook();
> myBook.setTitle("EMF Validation");
> Writer writer = EXTLibraryFactory.eINSTANCE.createWriter();
> writer.setName("Hector");
>
> //And then do the validation
>
> I've been searching the web with no luck. Can something like this be
> done? I would appreciate any hints.
>
> Thanks.
Previous Topic:[Texo] not possible to define Embedded-id in orm
Next Topic:EConstraint in Ecore Model
Goto Forum:
  


Current Time: Mon Jul 28 16:34:44 EDT 2014

Powered by FUDForum. Page generated in 0.03798 seconds