Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Custom OCL messages
Custom OCL messages [message #1460384] Mon, 03 November 2014 14:10 Go to next message
Eclipse UserFriend
Hi,

I am trying to use custom OCL messages, but have no success.
I have checked this thread: https://www.eclipse.org/forums/index.php/t/392067/ (as I understood this issue were resolved in releases after indigo).

My invariant:
invariant nonEmptyType('Type must be any non-empty'): self.type->notEmpty();


But my generated validator does not use my custom messages and I am getting standard message:
Constraint is violated for .... ...


I am using luna release. How I can fix this?
Re: Custom OCL messages [message #1460422 is a reply to message #1460384] Mon, 03 November 2014 14:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Did you try following the tutorial or reading the documentation?

(Studying an old thread from a user who fails to communicate is unlikely
to be helpful.)

Regards

Ed Willink


On 03/11/2014 14:10, Igor Zapletnev wrote:
> Hi,
>
> I am trying to use custom OCL messages, but have no success.
> I have checked this thread:
> https://www.eclipse.org/forums/index.php/t/392067/ (as I understood this
> issue were resolved in releases after indigo).
>
> My invariant:
>
> invariant nonEmptyType('Type must be any non-empty'):
> self.type->notEmpty();
>
>
> But my generated validator does not use my custom messages and I am
> getting standard message:
>
> Constraint is violated for .... ...
>
>
> I am using luna release. How I can fix this?
Re: Custom OCL messages [message #1461274 is a reply to message #1460422] Tue, 04 November 2014 11:45 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I followed next tutorials for OCLinEcore: first, second. But where is no any information about custom messages.

I found interesting paragraph in OCLin syntax doc:
Quote:
A class invariant optionally supports a second OCL expression as a parenthesis on the invariant name. This parenthesized expression is invoked when an invariant fails in order to provide a user-defined failure message. Whether this message is an error or a warning is determined by the evaluation of the invariant:


But it is meaning is not clear for me because my custom message from first message in this thread are not working with generated java code.
Re: Custom OCL messages [message #1461309 is a reply to message #1461274] Tue, 04 November 2014 12:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Try searching the documentation for "custom message" and in particular
the bit on OCLinEcoreEObjectValidator.

Regards

Ed Willink


On 04/11/2014 11:45, Igor Zapletnev wrote:
> Hi,
>
> I followed next tutorials for OCLinEcore:
> http://help.eclipse.org/juno/topic/org.eclipse.ocl.doc/help/Tutorials.html?cp=49_3_0#OCLinEcoreTutorial,
> https://wiki.eclipse.org/MDT/OCLinEcore. But where is no any information
> about custom messages.
>
> I found interesting paragraph in
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FOCLinEcore.html&cp=49_1_2:
>
> Quote:
>> A class invariant optionally supports a second OCL expression as a
>> parenthesis on the invariant name. This parenthesized expression is
>> invoked when an invariant fails in order to provide a user-defined
>> failure message. Whether this message is an error or a warning is
>> determined by the evaluation of the invariant:
>
>
> But it is meaning is not clear for me because my custom message from
> first message in this thread are not working with generated java code.
>
Re: Custom OCL messages [message #1462090 is a reply to message #1461309] Wed, 05 November 2014 07:34 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for response. But I still could not find way how to use custom error messages. Documentation looks weird for me.

Link
Quote:
invariant SufficientCopies('There are ' + library.loans->select((book = self))->size().toString() + ' loans for the ' + copies.toString() + ' copies of \'' + name + '\''):
library.loans->select((book = self))->size() <= copies;

Unfortunately, in the Indigo release, EMF does not support this customization. This must be activated explicitly using an EValidator that is aware of the ValidationDelegateExtension extended API. This is available by using the OCLinEcoreEObjectValidator.


I have tried this syntax, but have no success. I am using Luna and I don't need any manually modifications.

But I also tried to use OCLinEcoreEObjectValidator.java class and my invariants could not be found, because it's using some annotations on eOperation:
String expression = EcoreUtil.getAnnotation(eOperation, validationDelegate, "body");

But I am using java generated code for invariants and there is no any annotations on operation.

Can I find anywhere stable example and/or tutorial?

[Updated on: Wed, 05 November 2014 07:41] by Moderator

Report message to a moderator

Re: Custom OCL messages [message #1462228 is a reply to message #1462090] Wed, 05 November 2014 10:51 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

https://wiki.eclipse.org/OCL/ForumNetiquette

Regards

Ed Willink

On 05/11/2014 07:34, Igor Zapletnev wrote:
> Thanks for response. But I still could not find way how to use custom
> error messages. Documentation looks weird for me.
>
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FIntegration.html&cp=49_1_7
>
> Quote:
>> invariant SufficientCopies('There are ' + library.loans->select((book
>> = self))->size().toString() + ' loans for the ' + copies.toString() +
>> ' copies of \'' + name + '\''):
>> library.loans->select((book = self))->size() <= copies;
>>
>> Unfortunately, in the Indigo release, EMF does not support this
>> customization. This must be activated explicitly using an EValidator
>> that is aware of the ValidationDelegateExtension extended API. This is
>> available by using the OCLinEcoreEObjectValidator.
>
>
> I have tried this syntax, but have no success. I am using Luna and I
> don't need any manually modifications.
>
> But I also tried to use OCLinEcoreEObjectValidator.java class and my
> invariants could not be found, because it's using some annotations on
> eOperation:
>
> String expression = EcoreUtil.getAnnotation(eOperation,
> validationDelegate, "body");
>
> But my OCLinEditor doesn't generate it.
>
> class MyModel
> {
> property type : ecore::EClassifier[?];
> invariant nonEmptyType('Type must be any non-empty'):
> self.type->notEmpty();
> }
>
> Produced code:
>
> <eClassifiers xsi:type="ecore:EClass" name="NamedVariable">
> <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
> <details key="constraints" value="nonEmptyType"/>
> </eAnnotations>
> <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
> <details key="nonEmptyType" value="self.type->notEmpty()"/>
> <details key="nonEmptyType$message" value="'Type must be any
> non-empty'"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="type"
> eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EClassifier"/>
> </eClassifiers>
>
>
> Can I find anywhere stable example and/or tutorial?
Previous Topic:org.eclipse.jdt.annotation version in RCP product configurations
Next Topic:Run-time errors in queries and templates
Goto Forum:
  


Current Time: Fri Apr 19 22:24:10 GMT 2024

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

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

Back to the top