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 09:37  |
Eclipse User |
|
|
|
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 10:30   |
Eclipse User |
|
|
|
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 #1472092 is a reply to message #1470715] |
Thu, 13 November 2014 10:41   |
Eclipse User |
|
|
|
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 #1473313 is a reply to message #1473233] |
Fri, 14 November 2014 09:15  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Tue Jul 01 08:58:18 EDT 2025
Powered by FUDForum. Page generated in 0.04079 seconds
|