Skip to main content



      Home
Home » Modeling » EMF » How to change ConstraintStatus severity
How to change ConstraintStatus severity [message #1512265] Mon, 15 December 2014 10:55 Go to next message
Eclipse UserFriend
Hi all,

I'd like to use Java classes to do most of my model validation. Because the model I'm working with is HUGE, I would like to define just a single class to validate, and report all possible validation severities (INFO, WARNING, ERROR, etc.) for a given model type.

Currently, the only way I can figure out how to set the severity is in the <constraint> extension point element (e.g. severity="ERROR", etc.) If my model has a hundred or so types, does that mean I need to write a constraint class for each severity level/type combination? In other words, if I have a type "A" do I need a validateAInfos, validateAErrors, validateAWarnings, etc. etc.? This seems like it would lead to an awful lot of duplicated code.

Thanks in advance,
Bob
Re: How to change ConstraintStatus severity [message #1512431 is a reply to message #1512265] Mon, 15 December 2014 13:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Bob,

A couple of the ConstraintStatus factory method signatures include a
severity parameter. I'm fairly certain that I have at one time or
another used this to return different messages and severities from a
single constraint, depending on various factors.

So, rather than asking the IValidationContext to create the result
status for you, you can just invoke one of these factory methods to
customize the result.

HTH,

Christian


On 2014-12-15 15:55:57 +0000, Robert Brodt said:

> Hi all,
>
> I'd like to use Java classes to do most of my model validation. Because
> the model I'm working with is HUGE, I would like to define just a
> single class to validate, and report all possible validation severities
> (INFO, WARNING, ERROR, etc.) for a given model type.
> Currently, the only way I can figure out how to set the severity is in
> the <constraint> extension point element (e.g. severity="ERROR", etc.)
> If my model has a hundred or so types, does that mean I need to write a
> constraint class for each severity level/type combination? In other
> words, if I have a type "A" do I need a validateAInfos,
> validateAErrors, validateAWarnings, etc. etc.? This seems like it would
> lead to an awful lot of duplicated code.
>
> Thanks in advance,
> Bob
Re: How to change ConstraintStatus severity [message #1512587 is a reply to message #1512431] Mon, 15 December 2014 16:56 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the quick reply Christian. I've thought of that too. The problem is that the validate(IValidationContext) method of my AbstractModelConstraint implementation is passed an IValidationContext, but unfortunately all of the ConstraintStatus constructors require the IModelConstraint contained in the validation context, which is not available (publicly). Thus, you are forced to use IValidationContext#createFailureStatus() or IValidationContext#createSuccessStatus() to construct the IStatus object returned by validate(). This seems really restrictive to me Sad

I don't really see any way around this - am I missing something?

EDIT: Oops, yes I am missing something Wink I just noticed the static createStatus() methods which, indeed, accept a context and severity. Never mind Smile

[Updated on: Mon, 15 December 2014 17:04] by Moderator

Re: How to change ConstraintStatus severity [message #1512608 is a reply to message #1512587] Mon, 15 December 2014 17:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Bob,

Don't use the ConstraintStatus constructors, but the static factory
methods. To these you pass the validation context, not the current
IModelConstraint. Although, you could just get the IModelConstraint
like this:

ConstraintRegistry.getInstance().getDescriptor(
ctx.getCurrentConstraintId())

which is what the static factory methods do. That's all public API.

HTH,

Christian



On 2014-12-15 21:56:48 +0000, Robert Brodt said:

> Thanks for the quick reply Christian. I've thought of that too. The
> problem is that the validate(IValidationContext) method of my
> AbstractModelConstraint implementation is passed an IValidationContext,
> but unfortunately all of the ConstraintStatus constructors require the
> IModelConstraint contained in the validation context, which is not
> available (publicly). Thus, you are forced to use
> IValidationContext#createFailureStatus() or
> IValidationContext#createSuccessStatus() to construct the IStatus
> object returned by validate(). This seems really restrictive to me :(
>
> I don't really see any way around this - am I missing something?
Re: How to change ConstraintStatus severity [message #1512749 is a reply to message #1512608] Mon, 15 December 2014 20:11 Go to previous message
Eclipse UserFriend
Yes, that does help - thanks Christian! Smile
Previous Topic:Copyright notice not generated
Next Topic:Making URIHandlerImpl more REST-able
Goto Forum:
  


Current Time: Tue Jul 15 03:06:43 EDT 2025

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

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

Back to the top