Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to change ConstraintStatus severity
How to change ConstraintStatus severity [message #1512265] Mon, 15 December 2014 15:55 Go to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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 18:51 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

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 21:56 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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 22:04]

Report message to a moderator

Re: How to change ConstraintStatus severity [message #1512608 is a reply to message #1512587] Mon, 15 December 2014 22:22 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

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] Tue, 16 December 2014 01:11 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Yes, that does help - thanks Christian! Smile
Previous Topic:Copyright notice not generated
Next Topic:Making URIHandlerImpl more REST-able
Goto Forum:
  


Current Time: Thu Mar 28 22:53:30 GMT 2024

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

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

Back to the top