Home » Modeling » OCL » Custom validation failure messages
Custom validation failure messages [message #671951] |
Thu, 19 May 2011 12:43 |
Darie Moldovan Messages: 67 Registered: November 2010 Location: Darmstadt, Germany |
Member |
|
|
Hi,
after reading the discussion here, I tried the feature of defining custom messages for the validation myself. Although I followed the steps mentioned there, I still didn't get to see my message when constraints are violated.
I checked this bug and read pages 87-88 from this presentation, to be sure I'm not omitting something. The custom messages are simply not shown in my xtext editor.
Here's what I tried: after defining an invariant, I wanted to show a custom message when the validation returns an error, something like (in oclinecore)
invariant OrdinalIsUnique('Ordinals must be unique.'):
ElemA.allInstances()->excluding(self).ordinal->excludes(ordinal);
or, in Ecore
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
<details key="OrdinalIsUnique" value="(((ElemA.allInstances())->excluding(self))->collect(ordinal))->excludes(ordinal)"/>
<details key="OrdinalIsUnique$message" value="'Ordinals must be unique.'"/>
</eAnnotations>
but the custom message is not shown in the xtext editor. If I define
ElemA one (
ordinal 0
)
ElemA two (
ordinal 1
)
ElemA three(
ordinal 0 // not valid, according to the invariant
)
the marker is shown at the right line and the validation returns the following error:
The 'OrdinalIsUnique' constraint is violated on 'MyDSL.impl.ElemAImpl @ 677646{platform:/resource/TestOCLXtext2/src/basic.MyDSL#//@elements.0}'
which is correct, because the constraint is, indeed, violated. But why isn't my message shown? As I said, my generated validator inherits OCLinEcoreEObjectValidator, I checked that the class is not generated and I added org.eclipse.ocl.examples.xtext.oclinecore as a dependency in the manifest. In my case, it does not work.
Tested with:
Eclipse Indigo Build id: 20110505-1223
Xtext 2.0.0.v201105170444
OCL 3.1.0.v20110502-1445
Any clues why this might still not work?
Thanks in advance.
Darie
|
|
| | | | | | | |
Re: Custom validation failure messages [message #1059449 is a reply to message #672370] |
Sat, 18 May 2013 17:20 |
|
Ed Willink wrote on Fri, 20 May 2011 17:38
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.bindConstant().annotatedWith(Names.named(org.eclipse.xtext.validation.CompositeEValidator.USE_EOBJECT_VALIDATOR)).to(false);
}
Is it still valid on Juno SR2? I can't make it work with the following tooling, and can't find out if it's either incompatibility or a silly mistake:
* Eclipse Juno
Version: 4.2.2
Build id: M20130204-1200
* Eclipse Modeling Framework Runtime and Tools
Version: 2.8.3.v20130125-0826
Build id: R201301250826
* Xtext SDK
Version: 2.4.1.v201304180855
* OCL (Object Constraint Language)
Version: 3.2.2.v20130128-1158
Build id: M201301281158
The source code (and more details) is available at this github repo: https://github.com/juniorz/playing-with-eclipse-mdt
Thanks for any help!
|
|
| | |
Re: Custom validation failure messages [message #1059820 is a reply to message #1059632] |
Tue, 21 May 2013 18:01 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
You need to use the OCLinEcoreEObjectValidator , which you are
source-wise, but you also need to use it at run-time, so you must run in
a nested Eclipse.
When I do that and fix JRE consistency, rebuild to expose the icons, I
get failures from a CDO CCE. I've never seen CDO in action so I'll look
a little further, but ...
https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615 raised against CDO.
That fixed it still doesn't work. Changing the nsURI and rebuilding
fixes it.
Using the same URI for your example as for the original tutorial is very
very foolish (and 'illegal'; org.eclipse... is reserved for Eclipse
Foundation usage).
Regards
Ed Willink
On 21/05/2013 01:39, Reinaldo Junior wrote:
> I guess I haven't elaborated it properly.
>
> I'm able to violate the OCL constraint (by creating multiple loans) on
> both xmi and xtext files but I'm not able to see the custom message
> ("not enough copies") as specified in the ecore file
> (https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24)
>
> I've followed the instructions provided in the presentation (and
> summarised in this topic):
>
> 1. Change the Xtext validator to inherit from
> OCLinEcoreEObjectValidator -
> https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27
> 2. Override the configure method on XXXRuntimeModule[/url] -
> https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15
>
> If I override the configure method, I have no validation at all. If I
> don't do it, I see the usual "The 'CONSTRAINT_NAME' constraint is
> violated on 'OBJECT NAME'" message.
>
> I'm using the latest Eclipse modeling release (a version different
> from the used in the tutorial).
>
> Thank you
|
|
|
Re: Custom validation failure messages [message #1059822 is a reply to message #1059820] |
Tue, 21 May 2013 18:05 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi<br>
<br>
You've also missed the<br>
<br>
Note the <span class="bold"><strong>@generated not</strong></span>
that indicates that the class interface is manually defined. Do
not use <span class="bold"><strong>@generated NOT</strong></span>
since that indicates that the whole class is manually defined.<br>
<br>
comment in the (current) documentation.<br>
<br>
Regards<br>
<br>
Ed Willink<br>
<br>
On 21/05/2013 19:01, Ed Willink wrote:<br>
</div>
<blockquote cite="mid:kngcps$ui4$1@xxxxxxxxe.org" type="cite">Hi
<br>
<br>
You need to use the OCLinEcoreEObjectValidator , which you are
source-wise, but you also need to use it at run-time, so you must
run in a nested Eclipse.
<br>
<br>
When I do that and fix JRE consistency, rebuild to expose the
icons, I get failures from a CDO CCE. I've never seen CDO in
action so I'll look a little further, but ...
<a class="moz-txt-link-freetext" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615">https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615</a> raised
against CDO.
<br>
<br>
That fixed it still doesn't work. Changing the nsURI and
rebuilding fixes it.
<br>
<br>
Using the same URI for your example as for the original tutorial
is very very foolish (and 'illegal'; org.eclipse... is reserved
for Eclipse Foundation usage).
<br>
<br>
Regards
<br>
<br>
Ed Willink
<br>
<br>
<br>
On 21/05/2013 01:39, Reinaldo Junior wrote:
<br>
<blockquote type="cite">I guess I haven't elaborated it properly.
<br>
<br>
I'm able to violate the OCL constraint (by creating multiple
loans) on both xmi and xtext files but I'm not able to see the
custom message ("not enough copies") as specified in the ecore
file
(<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24</a>)<br>
<br>
I've followed the instructions provided in the presentation (and
summarised in this topic):
<br>
<br>
1. Change the Xtext validator to inherit from
OCLinEcoreEObjectValidator -
<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27</a><br>
2. Override the configure method on XXXRuntimeModule[/url] -
<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15</a><br>
<br>
If I override the configure method, I have no validation at all.
If I don't do it, I see the usual "The 'CONSTRAINT_NAME'
constraint is violated on 'OBJECT NAME'" message.
<br>
<br>
I'm using the latest Eclipse modeling release (a version
different from the used in the tutorial).
<br>
<br>
Thank you
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>
|
|
|
Re: Custom validation failure messages [message #1059830 is a reply to message #1059820] |
Tue, 21 May 2013 19:01 |
|
Ed Willink wrote on Tue, 21 May 2013 15:01Hi
You need to use the OCLinEcoreEObjectValidator , which you are
source-wise, but you also need to use it at run-time, so you must run in
a nested Eclipse.
Thank you Ed,
Does it mean I have to build my Xtext project from a nested Eclipse (started from running my Ecore project as an Eclipse application)? Why isn't enough to add the plugins which provides OCLinEcoreEObjectValidator as a dependency? Do you have any additional reference on that?
Quote:
That fixed it still doesn't work. Changing the nsURI and rebuilding
fixes it.
Using the same URI for your example as for the original tutorial is very
very foolish (and 'illegal'; org.eclipse... is reserved for Eclipse
Foundation usage).
I would never imagine this could make any harm.
|
|
| |
Re: Custom validation failure messages [message #1059849 is a reply to message #1059844] |
Tue, 21 May 2013 22:24 |
|
This is what I've tried:
1) Change the package name and URI for both the Ecore and Xtext projects.
2) Run the Ecore project as an "Eclipse Application" to start a nested eclipse (that is what I've understood from "using OCLinEcoreEObjectValidator at run-time")
3) From inside this first Eclipse-inception, create the Xtext project.
4) Imported my Ecore in the Xtext using the URI (and not the "platform:/resource/..." path) and
5) Change the JRE of every Xtext project (was J2SE-1.5) to the same JRE used on the Ecore projects (JavaSE-1.7)
That is what I've understood from "[fixing] JRE consistency". Rebuild
6) Run the Xtext project as an "Eclipse Application" (second Eclipse-inception)
7) Created a new project to test my DSL.
AND IT WORKED.
I had tried all the steps except (5) and it didn't work. It's really tricky...
One last question: is all this Eclipse-inception really required? I mean, It's not comfortable to have 3 eclipses running to be able to test something DSL.
Thank you.
|
|
|
Re: Custom validation failure messages [message #1059894 is a reply to message #1059830] |
Wed, 22 May 2013 06:47 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
I don't understand how you are using your code so I don't understand why
you need three Eclipses. I endeavour to make dynamic EMF work so that
you can often use just one for modeling. But if your tooling generates
Java you need one for the producer and one for the consumer.
The U in URI is for Unique, If you have duplicates, all bets are off.
The namespace reservation of java.* for Java, org.eclipse.* for Eclipse
etc is to make duplicates easy to avoid.
Regards
Ed Willink
On 21/05/2013 20:01, Reinaldo Junior wrote:
> Ed Willink wrote on Tue, 21 May 2013 15:01
>> Hi
>>
>> You need to use the OCLinEcoreEObjectValidator , which you are
>> source-wise, but you also need to use it at run-time, so you must run
>> in a nested Eclipse.
>
>
> Thank you Ed,
>
> Does it mean I have to build my Xtext project from a nested Eclipse
> (started from running my Ecore project as an Eclipse application)? Why
> isn't enough to add the plugins which provides
> OCLinEcoreEObjectValidator as a dependency? Do you have any additional
> reference on that?
>
> Quote:
>> That fixed it still doesn't work. Changing the nsURI and rebuilding
>> fixes it.
>>
>> Using the same URI for your example as for the original tutorial is
>> very very foolish (and 'illegal'; org.eclipse... is reserved for
>> Eclipse Foundation usage).
>
>
> I would never imagine this could make any harm.
|
|
| | |
Goto Forum:
Current Time: Tue Apr 23 10:32:18 GMT 2024
Powered by FUDForum. Page generated in 0.04399 seconds
|