Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Validation] My Dynamic constraint provider gets never called
[EMF Validation] My Dynamic constraint provider gets never called [message #1462399] Wed, 05 November 2014 14:37 Go to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

I'm trying to implement a dynamic constraint Provider in order to fetch Java-coded constraints: nothing against OCL, but eventually I should be able to validate against business rules written in a Groovy-based DSL.

I'm trying for two days now to adapt the provided examples with the Validation plugins, but I don't get very far : my constraintprovider gets never called, nor even constructed.

I presume there's a problem in my plugin.xml, but I can't find out what :
<extension point="org.eclipse.emf.validation.constraintProviders">
      <category
            id="be.groups.usingEMF.test.javaconstraints"
            mandatory="true"
            name="Java Constraints"/>
      <constraintProvider
            class="be.groups.usingEMF.test.TestContraintProvider"
            mode="Batch">
            category="be.groups.usingEMF.test.javaconstraints"
         <package namespaceUri="http:///be/groups/domain/test/model/MyEmployer.ecore"/>
      </constraintProvider>
   </extension>
   <extension point="org.eclipse.emf.validation.constraintBindings">
   		<clientContext 
   			default="true"
   			id="be.groups.usingEMF.test.employercontext">
   			<selector class="be.groups.usingEMF.test.ValidationDelegateClientSelector"/>
   		</clientContext>
   		<binding 
   			context="be.groups.usingEMF.test.employercontext"
   			category="be.groups.usingEMF.test.javaconstraints"/>
   </extension>

The selector does nothing but returning true.

The validation is called in a basic way, like this :
IBatchValidator validator = (IBatchValidator) ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH) ;
validator.setIncludeLiveConstraints(true);
IStatus results = validator.validate(resource.getContents()) ;
//Prints: No constraints were evaluated
System.out.println(results.getMessage()) ;

Could anybody give me a hint about how to solve this problem?
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1462447 is a reply to message #1462399] Wed, 05 November 2014 15:30 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

Try setting your client-context to default="false". IIRC (it has been
years) I think that a default context is only tested if no other
non-default contexts match, and perhaps you have other contexts that
match?

In any case, your best bet for debugging is a breakpoint in the
ClientContextManager to see why your context selector either isn't
being invoked or isn't matching for some other reason.

HTH,

Christian


On 2014-11-05 14:37:38 +0000, Thomas Elskens said:

> Hello,
>
> I'm trying to implement a dynamic constraint Provider in order to fetch
> Java-coded constraints: nothing against OCL, but eventually I should be
> able to validate against business rules written in a Groovy-based DSL.
> I'm trying for two days now to adapt the provided examples with the
> Validation plugins, but I don't get very far : my constraintprovider
> gets never called, nor even constructed.
> I presume there's a problem in my plugin.xml, but I can't find out what :
>
> <extension point="org.eclipse.emf.validation.constraintProviders">
> <category
> id="be.groups.usingEMF.test.javaconstraints"
> mandatory="true"
> name="Java Constraints"/>
> <constraintProvider
> class="be.groups.usingEMF.test.TestContraintProvider"
> mode="Batch">
> category="be.groups.usingEMF.test.javaconstraints"
> <package
> namespaceUri="http:///be/groups/domain/test/model/MyEmployer.ecore"/>
> </constraintProvider>
> </extension>
> <extension point="org.eclipse.emf.validation.constraintBindings">
> <clientContext default="true"
> id="be.groups.usingEMF.test.employercontext">
> <selector
> class="be.groups.usingEMF.test.ValidationDelegateClientSelector"/>
> </clientContext>
> <binding context="be.groups.usingEMF.test.employercontext"
> category="be.groups.usingEMF.test.javaconstraints"/>
> </extension>
>
> The selector does nothing but returning true.
> The validation is called in a basic way, like this :
>
> IBatchValidator validator = (IBatchValidator)
> ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH)
> ;
> validator.setIncludeLiveConstraints(true);
> IStatus results = validator.validate(resource.getContents()) ;
> //Prints: No constraints were evaluated
> System.out.println(results.getMessage()) ;
>
> Could anybody give me a hint about how to solve this problem?
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1470471 is a reply to message #1462447] Wed, 12 November 2014 11:09 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

I started all over again, this time with a static constraint, and in fact my problem happens to be even more basic : even the client selector is never called.
But what can I do more to get it called than declare it in the constraintBindings extension point ? The plugin.xml is almost a copy from the tutorial from IBM Knowledge Center (http://www-01.ibm.com/support/knowledgecenter/SS8PJ7_7.0.0/org.eclipse.emf.validation.doc/tutorials/validationTutorial.html?lang=en) :
<plugin>
   <extension point="org.eclipse.emf.validation.constraintProviders">
   		<category name="static employer constraints" id="test.validation.standalone.constraints.static"/>
   		<constraintProvider>
   			<package namespaceUri="http:///be/groups/domain/test/model/MyEmployer.ecore"/>
   			<constraints categories="test.validation.standalone.constraints.static">
   				<constraint
   					lang="Java"
   					class="constraints.TestConstraint"
   					severity="ERROR"
   					mode="Batch"
   					name="Test constraint must be respected"
   					id="test.validation.standalone.testconstraint"
   					statusCode="1">
   					<description>Test constraints should be validated</description>
   					<message>This is a message from test constraint</message>
   					<target class="Portefeuille"/>
   					<target class="Employer"/>
   				</constraint>
   			</constraints>
   		</constraintProvider>
   </extension>
   <extension point="org.eclipse.emf.validation.constraintBindings">
   		<clientContext 
   			default="true"
   			id="test.validation.standalone.employercontext">
   			<selector class="test.validation.standalone.ValidationDelegateClientSelector"/>
   		</clientContext>
   		<binding 
   			context="test.validation.standalone.employercontext"
   			category="test.validation.standalone.constraints.static"/>
   </extension>
</plugin>

The contraint always creates a FailureStatus, and the Client Selector (but which isn't called) returns always true, upon batch validation it should thus logically fail.

Some missing dependencies perhaps ? Besides my model classes, I have the following ones in my manifest.mf :

  • org.eclipse.core.expressions
  • org.eclipse.core.runtime
  • org.eclipse.emf.ecore.xmi.impl
  • org.eclipse.emf.edit.domain
  • org.eclipse.emf.edit.provider
  • org.eclipse.emf.validation
  • org.eclipse.emf.validation.model
  • org.eclipse.emf.validation.service

Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1470618 is a reply to message #1470471] Wed, 12 November 2014 13:31 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

Your report that the client-selector isn't invoked suggests that the
problem is in the client-context registration in concert with whatever
other registrations are in your installation. I can only repeat my
previous advice to try making it non-default and to put a breakpoint in
the ClientContextManager. Did you do this?

Christian


On 2014-11-12 11:09:39 +0000, Thomas Elskens said:

> Hello,
>
> I started all over again, this time with a static constraint, and in
> fact my problem happens to be even more basic : even the client
> selector is never called. But what can I do more to get it called than
> declare it in the constraintBindings extension point ? The plugin.xml
> is almost a copy from the tutorial from IBM Knowledge Center
> (http://www-01.ibm.com/support/knowledgecenter/SS8PJ7_7.0.0/org.eclipse.emf.validation.doc/tutorials/validationTutorial.html?lang=en)
> :
> <plugin>
> <extension point="org.eclipse.emf.validation.constraintProviders">
> <category name="static employer constraints"
> id="test.validation.standalone.constraints.static"/>
> <constraintProvider>
> <package
> namespaceUri="http:///be/groups/domain/test/model/MyEmployer.ecore"/>
> <constraints categories="test.validation.standalone.constraints.static">
> <constraint
> lang="Java"
> class="constraints.TestConstraint"
> severity="ERROR"
> mode="Batch"
> name="Test constraint must be respected"
> id="test.validation.standalone.testconstraint"
> statusCode="1">
> <description>Test constraints should be validated</description>
> <message>This is a message from test constraint</message>
> <target class="Portefeuille"/>
> <target class="Employer"/>
> </constraint>
> </constraints>
> </constraintProvider>
> </extension>
> <extension point="org.eclipse.emf.validation.constraintBindings">
> <clientContext default="true"
> id="test.validation.standalone.employercontext">
> <selector
> class="test.validation.standalone.ValidationDelegateClientSelector"/>
> </clientContext>
> <binding context="test.validation.standalone.employercontext"
> category="test.validation.standalone.constraints.static"/>
> </extension>
> </plugin>
>
> The contraint always creates a FailureStatus, and the Client Selector
> (but which isn't called) returns always true, upon batch validation it
> should thus logically fail.
> Some missing dependencies perhaps ? Besides my model classes, I have
> the following ones in my manifest.mf :
>
> org.eclipse.core.expressions
> org.eclipse.core.runtime
> org.eclipse.emf.ecore.xmi.impl
> org.eclipse.emf.edit.domain
> org.eclipse.emf.edit.provider
> org.eclipse.emf.validation
> org.eclipse.emf.validation.model
> org.eclipse.emf.validation.service
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1470715 is a reply to message #1470618] Wed, 12 November 2014 15:20 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

Yes I made it non-default (the first thing I tried), but unfortunately without effect.

I do see something a bit peculiar in the ClientContextManager, more precisely the Set<IClientContext> clientContexts : it contains a total of 677 EntrySets, all of which have the same id and point to the ClientContextManager itself (see attached screenshot). I don't know if this is an expected behaviour ?

ClientContextMap, on the other hand, remains empty.

Something I should take a look at ... ?

Thomas
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1472092 is a reply to message #1470715] Thu, 13 November 2014 15:41 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Thomas,

See some replies in-line, below.

HTH,

Christian

On 2014-11-12 15:20:12 +0000, Thomas Elskens said:

> Hello,
>
> Yes I made it non-default (the first thing I tried), but unfortunately
> without effect.
>
> I do see something a bit peculiar in the ClientContextManager, more
> precisely the Set<IClientContext> clientContexts : it contains a total
> of 677 EntrySets, all of which have the same id and point to the
> ClientContextManager itself (see attached screenshot). I don't know if
> this is an expected behaviour ?

I think you're misinterpreting what the debugger is showing. A HashSet
is implemented internally as a HashMap in which the members of the set
are just the map's keys trivially mapped to something unimportant.
Your screenshot shows a cyclic expansion of the bidirectional
references between the HashSet, its HashMap storage, and that map's
EntrySet which is just the original HashSet instance.

If you engage the Variables view's "Show Logical Structure" toggle
option in the view toolbar, then it will present the set as an array of
its members, which is more useful.

There will not be 677 client-contexts in the set. How many are there
actually? And does any of them bear your context's ID?


> ClientContextMap, on the other hand, remains empty.

This suggests that either (a) your client-context was never loaded from
the extension point because your plug-in isn't in the run-time OSGi
configuration or it couldn't be resolved because of some dependency
resolution problem, or (b) a previous attempt to match it threw an
exception that got the context booted from the system (see the
exception handling in the
ClientContextManager::getClientContextsFor(EObject) method).


>
> Something I should take a look at ... ?
>
> Thomas
> <image>
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1473233 is a reply to message #1472092] Fri, 14 November 2014 12:55 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Thanks a lot for the hint ! Infact I made a very stupid mistake : I was testing the Validation framework outside of my RCP-application and, of course, the plugin.xml was not read.

Sorry for bothering, I'm doing a lot of testing for RCP recently but I'm very new to OSGI and the Eclipse environment.

Clientselector and constraint are being called now as expected.

Thanks again,

Thomas
Re: [EMF Validation] My Dynamic constraint provider gets never called [message #1473313 is a reply to message #1473233] Fri, 14 November 2014 14:15 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Thomas,

No worries! I'm just glad that it is working for you.

Christian


On 2014-11-14 12:55:39 +0000, Thomas Elskens said:

> Thanks a lot for the hint ! Infact I made a very stupid mistake : I was
> testing the Validation framework outside of my RCP-application and, of
> course, the plugin.xml was not read.
> Sorry for bothering, I'm doing a lot of testing for RCP recently but
> I'm very new to OSGI and the Eclipse environment.
> Clientselector and constraint are being called now as expected.
> Thanks again,
>
> Thomas
Previous Topic:[CDO] eIsSet is ko for eOpposite structural feature ?
Next Topic:Org.xml.sax.SAXException when saving resource
Goto Forum:
  


Current Time: Thu Apr 18 22:00:22 GMT 2024

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

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

Back to the top