Home » Modeling » EMF » How to change ConstraintStatus severity
How to change ConstraintStatus severity [message #1512265] |
Mon, 15 December 2014 15:55 |
|
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 |
|
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 #1512608 is a reply to message #1512587] |
Mon, 15 December 2014 22:22 |
|
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?
|
|
| |
Goto Forum:
Current Time: Thu Mar 28 22:53:30 GMT 2024
Powered by FUDForum. Page generated in 0.04233 seconds
|