Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Validation service: Excluding a client context
EMF Validation service: Excluding a client context [message #926038] Fri, 28 September 2012 08:48 Go to next message
Abhinaw Sachan is currently offline Abhinaw SachanFriend
Messages: 9
Registered: July 2009
Junior Member
Hi All,

I am trying to validate my EMF model.

To do that I wrote some constraints using eclipse ext-point "org.eclipse.emf.validation.constraintProviders"

Then I did a binding between these constraints to a client context using "org.eclipse.emf.validation.constraintBindings"
I also used excludeCategory so that other Validators are not used to validate my model like this:

<extension
         point="org.eclipse.emf.validation.constraintBindings">
      <binding
            category="my.category"
            context="my.context">
         [i]<excludeCategory
               ref="org.eclipse.bpmn2.modeler.core.validation">
         </excludeCategory>[/i]
      </binding>
      <clientContext
            default="false"
            id="cmy.context">
         <selector class="my.SelectorClass"/>
      </clientContext>
</extension>


However, ClientContextManager.getClientContextsFor(EObject eObject) method takes all contributed contexts by all clients, and all IClientSelector implementations are checked for.

The problem is, one of the IClientSelector (which I excluded above) is throwing NullPointerException Sad

Am I doing something wrong, Or the behavior is like this ?
Then when these excluded contexts are used ?

Also, is there any other way that I can prevent this excluded context from execution while validating my model ?

Can someone tell me about it?

Thanks much
Abhinaw

[Updated on: Fri, 28 September 2012 08:49]

Report message to a moderator

Re: EMF Validation service: Excluding a client context [message #926261 is a reply to message #926038] Fri, 28 September 2012 13:17 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Abhinaw,

Your constraint bindings can exclude named categories of constraints,
but there is no concept of excluding another client's context. Is
"org.eclipse.bpmn2.modeler.core.validation" the identifier of a client
context or a constraint category? If it's a context ID, then it will
have no effect (unless it also happens to be a category ID).

The determination of which constraints are applicable to an object has
two phases: first, finding the client contexts that match an object,
then finding the constraints that are bound to *any* matching context.
Thus, the resulting set of constraints is the union of all of the
constraints bound to the matching client contexts.

So, if your context is trying to exclude a category that another client
context (also matching your model elements) includes, then your
exclusion doesn't matter.

But, the context extension can help, here. If your models are a kind
of BPMN model, then it makes sense for your context to extend the BPMN
Modeler's client context using the <extendClientContext> element. The
context-matching phase only takes the most specific matching context in
a hierarchy because an extending context inherits all of the bindings
on its parent. It can additionally *exclude* constraints and
categories that are bound to its parent to override those bindings.

So, what you need to do is something like this:

<extension
point="org.eclipse.emf.validation.constraintBindings">
<binding
context="my.context">

<category ref="my.category"/>

<!-- Inherit all of the bindings of BPMN Modeler so that we
can override some -->
<extendClientContext ref="org.eclipse.bpmn2.modeler.context"

<!-- Exclude these constraints that are inherited from BPMN
Modeler -->
<excludeCategory
ref="org.eclipse.bpmn2.modeler.core.validation">
</excludeCategory>

</binding>

<clientContext
default="false"
id="cmy.context">
<selector class="my.SelectorClass"/>
</clientContext>
</extension>

where I'm just guessing at BPMN Modeler's client-context ID (you'll
need to look it up). Make sure that your context selector doesn't
match models that are BPMN Modeler's own, otherwise you'll hijack the
constraints in that application. Your context should still only match
your models, but when it does, then you'll override BPMN Modeler's
bindings.

On the subject of the NullPointerException: if an application's
client-context selector throws NPEs, then that's a bug in that
application. There's not really anything that the validation framework
can do to help with that.

HTH,

Christian


On 2012-09-28 08:48:46 +0000, Abhinaw Sachan said:

> Hi All,
>
> I am trying to validate my EMF model.
>
> To do that I wrote some constraints using eclipse ext-point
> "org.eclipse.emf.validation.constraintProviders"
>
> Then I did a binding between these constraints to a client context
> using "org.eclipse.emf.validation.constraintBindings"
> I also used excludeCategory so that other Validators are not used to
> validate my model like this:
>
> <extension
> point="org.eclipse.emf.validation.constraintBindings">
> <binding
> category="my.category"
> context="my.context">
> <excludeCategory
> ref="org.eclipse.bpmn2.modeler.core.validation">
> </excludeCategory>

> </binding>
> <clientContext
> default="false"
> id="cmy.context">
> <selector class="my.SelectorClass"/>
> </clientContext>
> </extension>
>
> However, ClientContextManager.getClientContextsFor(EObject eObject)
> method takes all contributed contexts by all clients, and all
> IClientSelector implementations are checked for.
>
> The problem is, one of the IClientSelector (which I excluded above) is
> throwing NullPointerException :(
>
> Am I doing something wrong, Or the behavior is like this ?
> Then when these excluded contexts are used ?
>
> Can someone tell me about it?
>
> Thanks much
> Abhinaw
Re: EMF Validation service: Excluding a client context [message #928938 is a reply to message #926261] Mon, 01 October 2012 04:51 Go to previous messageGo to next message
Abhinaw Sachan is currently offline Abhinaw SachanFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Christian,

Thanks for your detailed reply.

I could understand the extendClientContext, However what I understand is, I cannot avoid an IClientSelector implementation from execution, no matter if I extentClientContext & exclude constraints/categories.

Am I correct ?

Regards
Abhinaw
Re: EMF Validation service: Excluding a client context [message #929455 is a reply to message #928938] Mon, 01 October 2012 13:21 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Abhinaw,

All client contexts are always tested to see whether they match the
object being validated. Afterwards, the contexts that matched are
filtered to exclude any that are extended by other contexts that also
matched. Perhaps this could be improved by changing the
ClientContextManager to maintain a partial ordering of client contexts
based on the extends relationship, so that it can short-circuit tests
for extended contexts when an extending context has already matched.
You might raise an enhancement request for that, I suppose.

I do see, also, that in the case of a client selector throwing an
uncaught exception, the ClientContextManager traps it and doesn't let
it disrupt the validation operation. So, I don't think you need to
worry about selectors from other third parties interfering with your
application. Can you be specific about the consequences you're seeing
from a NullPointerException in an IClientSelector?

HTH,

Christian


On 2012-10-01 04:51:58 +0000, Abhinaw Sachan said:

> Hi Christian,
>
> Thanks for your detailed reply.
>
> I could understand the extendClientContext, However what I understand
> is, I cannot avoid an IClientSelector implementation from execution, no
> matter if I extentClientContext & exclude constraints/categories.
>
> Am I correct ?
>
> Regards
> Abhinaw
Re: EMF Validation service: Excluding a client context [message #929528 is a reply to message #929455] Mon, 01 October 2012 14:41 Go to previous messageGo to next message
Abhinaw Sachan is currently offline Abhinaw SachanFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Christian,

Thanks a ton for the explanation. That helped Smile

The scenario is: We have an extended BPMN model, hence BPMN2 Validation contributed by BPMN2 Modeler applies to our model as well. BPMN2 Modeler's selector (ValidationDelegateClientSelector) also applies when we validate our model.

This selector uses org.eclipse.bpmn2.modeler.core.runtime.TargetRuntime to read org.eclipse.bpmn2.modeler.core.runtime.ModelDescriptor to get the EPackage.

ValidationDelegateClientSelector has something like this:
ModelDescriptor md = TargetRuntime.getCurrentRuntime().getModelDescriptor();


Here, there is no explicit TargetRuntime set, hence TargetRuntime.getCurrentRuntime() is null, and in turn throws NullPointer.

Unfortunately, ClientContextManager does not catch-and-continue Sad
And a ConcurrentModificationException is thrown.

I have already raised an issue on BPMN2 Modeler project

That's the issue is.

Thanks & Kind Regards,
Abhinaw
Re: EMF Validation service: Excluding a client context [message #929626 is a reply to message #929528] Mon, 01 October 2012 16:11 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Abhinaw,

I see that in the ClientContextManager::getClientContextsFor(EObject)
method, any exception thrown by an IClientSelector is caught and logged
and the selector is booted from the system. This may seem harsh, but
it was deemed important for performance as this method is called a lot.
Creating and throwing exceptions is costly, and there's no reason not
to expect that a client selector would throw the exception every time
it's invoked.

However, this leads to the ConcurrentModificationException that you're
seeing that breaks the validation operation. For some reason, the
attempt to copy the set of IClientSelectors doesn't actually make a
copy at all. That looks like a bug. Moreover, rather than copying on
every invocation, because modifying the set of selectors is a very rare
case, this should be a copy-on-write collection. Then this method
could just use the Iterator::remove() API to give a misbehaving
selector the boot while maintaining thread safety.

Cheers,

Christian


On 2012-10-01 14:41:58 +0000, Abhinaw Sachan said:

> Hi Christian,
>
> Thanks a ton for the explanation. That helped :)
>
> The scenario is: We have an extended BPMN model, hence BPMN2 Validation
> contributed by BPMN2 Modeler applies to our model as well. BPMN2
> Modeler's selector (ValidationDelegateClientSelector) also applies when
> we validate our model.
>
> This selector uses org.eclipse.bpmn2.modeler.core.runtime.TargetRuntime
> to read org.eclipse.bpmn2.modeler.core.runtime.ModelDescriptor to get
> the EPackage.
>
> ValidationDelegateClientSelector has something like this:
> ModelDescriptor md = TargetRuntime.getCurrentRuntime().getModelDescriptor();
>
> Here, there is no explicit TargetRuntime set, hence
> TargetRuntime.getCurrentRuntime() is null, and in turn throws
> NullPointer.
>
> Unfortunately, ClientContextManager does not catch-and-continue :(
> And a ConcurrentModificationException is thrown.
>
> I have already raised an issue on
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=390751
>
> That's the issue is.
>
> Thanks & Kind Regards,
> Abhinaw
Previous Topic:EMF 2.8.1?
Next Topic:[CDO] 'Decoration Calculation' error using CDO Sessions View
Goto Forum:
  


Current Time: Fri Apr 19 04:04:43 GMT 2024

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

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

Back to the top