Skip to main content


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 #535839] Tue, 25 May 2010 23:23 Go to next message
Hector Chavez is currently offline Hector ChavezFriend
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 #535873 is a reply to message #535839] Wed, 26 May 2010 07:16 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
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.
Re: Validating an EMF model programatically [message #535992 is a reply to message #535873] Wed, 26 May 2010 15:10 Go to previous messageGo to next message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
Thanks Jonas,

I tried the that approach but it did not work in my example, I get an exception, this is the code I'm using:


University univ = UniversityFactory.eINSTANCE.createUniversity();
		
ValidationDelegateClientSelector.running = true;
		
IBatchValidator validator = (IBatchValidator)    ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH);
validator.setIncludeLiveConstraints(true);
		
IStatus status = validator.validate(univ);
		
ValidationDelegateClientSelector.running = false;



And the exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
at emf.examples.university.validation.adapter.EValidatorAdapter . <init>(EValidatorAdapter.java:57)
at university.tests.Main.main(Main.java:23)
Caused by: java.lang.NullPointerException
at org.eclipse.emf.validation.internal.EMFModelValidationPlugin .getPluginId(EMFModelValidationPlugin.java:201)
at org.eclipse.emf.validation.service.ModelValidationService.co nfigureConstraints(ModelValidationService.java:144)
at org.eclipse.emf.validation.service.ModelValidationService.<init >(ModelValidationService.java:134)
at org.eclipse.emf.validation.service.ModelValidationService.<clinit >(ModelValidationService.java:83)
... 2 more

Jonas wrote on Wed, 26 May 2010 03:16
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

Re: Validating an EMF model programatically [message #535999 is a reply to message #535992] Wed, 26 May 2010 15:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Hector,

Not all the frameworks support running stand alone. I think you'll need
to run this as an Eclipse application.



Hector Chavez wrote:
> Thanks Jonas,
> I tried the that approach but it did not work in my example, I get an
> exception, this is the code I'm using:
>
>
>
> University univ = UniversityFactory.eINSTANCE.createUniversity();
>
> ValidationDelegateClientSelector.running = true;
>
> IBatchValidator validator = (IBatchValidator)
> ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
> validator.setIncludeLiveConstraints(true);
>
> IStatus status = validator.validate(univ);
>
> ValidationDelegateClientSelector.running = false;
>
>
>
> And the exception:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at emf.examples.university.validation.adapter.EValidatorAdapter .
> <init>(EValidatorAdapter.java:57)
> at university.tests.Main.main(Main.java:23)
> Caused by: java.lang.NullPointerException
> at org.eclipse.emf.validation.internal.EMFModelValidationPlugin
> .getPluginId(EMFModelValidationPlugin.java:201)
> at org.eclipse.emf.validation.service.ModelValidationService.co
> nfigureConstraints(ModelValidationService.java:144)
> at org.eclipse.emf.validation.service.ModelValidationService.<init
> >(ModelValidationService.java:134)
> at
> org.eclipse.emf.validation.service.ModelValidationService.<clinit
> >(ModelValidationService.java:83)
> ... 2 more
>
> Jonas wrote on Wed, 26 May 2010 03:16
>> 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
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Validating an EMF model programatically [message #536002 is a reply to message #535999] Wed, 26 May 2010 15:45 Go to previous message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
I see, after searching for a while on the internet that seems to be the consensus. I'll see if I can find an alternative. Thanks for your help.

Hector

Ed Merks wrote on Wed, 26 May 2010 11:26
Hector,

Not all the frameworks support running stand alone. I think you'll need
to run this as an Eclipse application.

Hector Chavez wrote:
> Thanks Jonas,
> I tried the that approach but it did not work in my example, I get an
> exception, this is the code I'm using:
>
>
>
> University univ = UniversityFactory.eINSTANCE.createUniversity();
>
> ValidationDelegateClientSelector.running = true;
>
> IBatchValidator validator = (IBatchValidator)
> ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
> validator.setIncludeLiveConstraints(true);
>
> IStatus status = validator.validate(univ);
>
> ValidationDelegateClientSelector.running = false;
>
>
>
> And the exception:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at emf.examples.university.validation.adapter.EValidatorAdapter .
> <init>(EValidatorAdapter.java:57)
> at university.tests.Main.main(Main.java:23)
> Caused by: java.lang.NullPointerException
> at org.eclipse.emf.validation.internal.EMFModelValidationPlugin
> .getPluginId(EMFModelValidationPlugin.java:201)
> at org.eclipse.emf.validation.service.ModelValidationService.co
> nfigureConstraints(ModelValidationService.java:144)
> at org.eclipse.emf.validation.service.ModelValidationService.<init
> >(ModelValidationService.java:134)
> at
> org.eclipse.emf.validation.service.ModelValidationService.<clinit
> >(ModelValidationService.java:83)
> ... 2 more
>
> Jonas wrote on Wed, 26 May 2010 03:16
>> 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
>

Re: Validating an EMF model programatically [message #622938 is a reply to message #535873] Wed, 26 May 2010 15:10 Go to previous message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
Thanks Jonas,

I tried the that approach but it did not work in my example, I get an exception, this is the code I'm using:



University univ = UniversityFactory.eINSTANCE.createUniversity();

ValidationDelegateClientSelector.running = true;

IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
validator.setIncludeLiveConstraints(true);

IStatus status = validator.validate(univ);

ValidationDelegateClientSelector.running = false;



And the exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
at emf.examples.university.validation.adapter.EValidatorAdapter . <init>(EValidatorAdapter.java:57)
at university.tests.Main.main(Main.java:23)
Caused by: java.lang.NullPointerException
at org.eclipse.emf.validation.internal.EMFModelValidationPlugin .getPluginId(EMFModelValidationPlugin.java:201)
at org.eclipse.emf.validation.service.ModelValidationService.co nfigureConstraints(ModelValidationService.java:144)
at org.eclipse.emf.validation.service.ModelValidationService.<init >(ModelValidationService.java:134)
at org.eclipse.emf.validation.service.ModelValidationService.<clinit >(ModelValidationService.java:83)
... 2 more

Jonas wrote on Wed, 26 May 2010 03:16
> 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
Re: Validating an EMF model programatically [message #622939 is a reply to message #622938] Wed, 26 May 2010 15:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Hector,

Not all the frameworks support running stand alone. I think you'll need
to run this as an Eclipse application.



Hector Chavez wrote:
> Thanks Jonas,
> I tried the that approach but it did not work in my example, I get an
> exception, this is the code I'm using:
>
>
>
> University univ = UniversityFactory.eINSTANCE.createUniversity();
>
> ValidationDelegateClientSelector.running = true;
>
> IBatchValidator validator = (IBatchValidator)
> ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
> validator.setIncludeLiveConstraints(true);
>
> IStatus status = validator.validate(univ);
>
> ValidationDelegateClientSelector.running = false;
>
>
>
> And the exception:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at emf.examples.university.validation.adapter.EValidatorAdapter .
> <init>(EValidatorAdapter.java:57)
> at university.tests.Main.main(Main.java:23)
> Caused by: java.lang.NullPointerException
> at org.eclipse.emf.validation.internal.EMFModelValidationPlugin
> .getPluginId(EMFModelValidationPlugin.java:201)
> at org.eclipse.emf.validation.service.ModelValidationService.co
> nfigureConstraints(ModelValidationService.java:144)
> at org.eclipse.emf.validation.service.ModelValidationService.<init
> >(ModelValidationService.java:134)
> at
> org.eclipse.emf.validation.service.ModelValidationService.<clinit
> >(ModelValidationService.java:83)
> ... 2 more
>
> Jonas wrote on Wed, 26 May 2010 03:16
>> 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
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Validating an EMF model programatically [message #622940 is a reply to message #535999] Wed, 26 May 2010 15:45 Go to previous message
Hector Chavez is currently offline Hector ChavezFriend
Messages: 34
Registered: February 2010
Member
I see, after searching for a while on the internet that seems to be the consensus. I'll see if I can find an alternative. Thanks for your help.

Hector

Ed Merks wrote on Wed, 26 May 2010 11:26
> Hector,
>
> Not all the frameworks support running stand alone. I think you'll need
> to run this as an Eclipse application.
>
> Hector Chavez wrote:
> > Thanks Jonas,
> > I tried the that approach but it did not work in my example, I get an
> > exception, this is the code I'm using:
> >
> >
> >
> > University univ = UniversityFactory.eINSTANCE.createUniversity();
> >
> > ValidationDelegateClientSelector.running = true;
> >
> > IBatchValidator validator = (IBatchValidator)
> > ModelValidationService.getInstance().newValidator(Evaluation Mode.BATCH);
> > validator.setIncludeLiveConstraints(true);
> >
> > IStatus status = validator.validate(univ);
> >
> > ValidationDelegateClientSelector.running = false;
> >
> >
> >
> > And the exception:
> >
> > Exception in thread "main" java.lang.ExceptionInInitializerError
> > at emf.examples.university.validation.adapter.EValidatorAdapter .
> > <init>(EValidatorAdapter.java:57)
> > at university.tests.Main.main(Main.java:23)
> > Caused by: java.lang.NullPointerException
> > at org.eclipse.emf.validation.internal.EMFModelValidationPlugin
> > .getPluginId(EMFModelValidationPlugin.java:201)
> > at org.eclipse.emf.validation.service.ModelValidationService.co
> > nfigureConstraints(ModelValidationService.java:144)
> > at org.eclipse.emf.validation.service.ModelValidationService.<init
> > >(ModelValidationService.java:134)
> > at
> > org.eclipse.emf.validation.service.ModelValidationService.<clinit
> > >(ModelValidationService.java:83)
> > ... 2 more
> >
> > Jonas wrote on Wed, 26 May 2010 03:16
> >> 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
> >
Previous Topic:Class invoked when attribute value is changed
Next Topic:[Texo] not possible to define Embedded-id in orm
Goto Forum:
  


Current Time: Thu Mar 28 12:36:46 GMT 2024

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

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

Back to the top