OCL Constraint evaluation fail [message #65087] |
Sun, 07 December 2008 20:50 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Franco Bergomi![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=franco.bergomi%40thalesaleniaspace.com) Messages: 6 Registered: July 2009 |
Junior Member |
|
|
Hello all,
Christian, thanks for your help about lazy constraint providers, I now
have my own "ocl constraint providers" that provides all my .ocl files
defined constraints and all needed messages, severities, categories, etc...
I now have one question about ocl constraints executions:
for the moment all of my constraints are well parsed and taken in account
by emf validation, and all of them behave when needed.
I think I did some mistake in one constraint, and each time it is
evaluated, it returns an IStatus with the "ERROR" severity, telling that
the current object violates the rule (with my own message),
Actually these objects don't violate the constraints, but I finally saw
that in the .log file (in workspace/.metadata/) there were some traces
(one per this constraint ERRORs) that show that there is a Class cast
exception. (nothing exceptional, my ocl may contains mistakes)
Here is my question :
How can I catch these exceptions at runtime ? (while evaluating the
constraint)?
I tried to surround the "super.validate()" with some try catch :
(in the OCLConstraint class taken from the examples extending
AbstractOCLModelConstraint)
@Override
public IStatus validate(IValidationContext ctx) {
//TODO handle error
IStatus status=null;
try {
status = super.validate(ctx);
} catch (Exception e) {
System.out.println("Rule evaluation failed :
"+getDescriptor().getName());
e.printStackTrace();
}
return status;
}
but I didn't get any message.
Is there any way to be notified of EMF Validation constriant excecution
exceptions throws?
Thanks again for your help!
Franco
|
|
|
Re: OCL Constraint evaluation fail [message #65175 is a reply to message #65087] |
Wed, 10 December 2008 14:37 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Franco,
See some replies in-line, below.
HTH,
Christian
Franco Bergomi wrote:
> Hello all,
> Christian, thanks for your help about lazy constraint providers, I now
> have my own "ocl constraint providers" that provides all my .ocl files
> defined constraints and all needed messages, severities, categories, etc...
Oo! Very good.
> I now have one question about ocl constraints executions: for the moment
> all of my constraints are well parsed and taken in account by emf
> validation, and all of them behave when needed.
> I think I did some mistake in one constraint, and each time it is
> evaluated, it returns an IStatus with the "ERROR" severity, telling that
> the current object violates the rule (with my own message), Actually
> these objects don't violate the constraints, but I finally saw that in
> the .log file (in workspace/.metadata/) there were some traces (one per
> this constraint ERRORs) that show that there is a Class cast exception.
> (nothing exceptional, my ocl may contains mistakes)
heh heh ...
> Here is my question : How can I catch these exceptions at runtime ?
> (while evaluating the constraint)?
Well, as these are RuntimeExceptions, they are, by definition,
programming mistakes. So, you shouldn't need to catch them at run-time.
While you're developing your library of OCL constraints, you can use the
Eclipse platform's tracing infrastructure to find out which
sub-expression is at fault. Enable the org.eclipse.ocl/debug/evaluation
option, validate, then look through the console output to see which
sub-expression first evaluates to OclInvalid. That's the one that
bombed with a RuntimeException.
> I tried to surround the "super.validate()" with some try catch :
>
>
> (in the OCLConstraint class taken from the examples extending
> AbstractOCLModelConstraint)
> @Override
> public IStatus validate(IValidationContext ctx) {
> //TODO handle error
> IStatus status=null;
> try {
> status = super.validate(ctx);
> } catch (Exception e) {
> System.out.println("Rule evaluation failed :
> "+getDescriptor().getName());
> e.printStackTrace();
> }
> return status;
> }
>
> but I didn't get any message.
That's right. RuntimeExceptions don't burble up to the client. Perhaps
it would be useful for development time to add an evaluation option that
propagates these exceptions to the client.
Feel free to raise an enhancement request on the MDT OCL component in
bugzilla. I think this could be a valuable tool.
> Is there any way to be notified of EMF Validation constriant excecution
> exceptions throws?
Yes. If you add in IConstraintListener to the ConstraintRegistry, you
will be notified when any constraint is disabled, and then you can check
the IConstraintDescriptor attached to the event to see whether he
constraint isError(). This indicates that it was disabled because it
threw an uncaught exception. The exception is available in the descriptor.
> Thanks again for your help!
> Franco
>
|
|
|
Powered by
FUDForum. Page generated in 0.03805 seconds