Custom OCL error messages [message #932092] |
Wed, 03 October 2012 16:37  |
Eclipse User |
|
|
|
Hi.
I implemented some OCL constraints in an EMF model ECORE directly by Java annotations.
But the error messages that the graphical editor generated by this model shows the user ultimately not correctly indicating that the constraint active.
I wonder how to customize the messages that are shown by graphic GMF Editor?
Any idea what I have to study?
Thanks for your time.
Ps. I'm sorry for the english.
|
|
|
|
|
|
|
|
Re: Custom OCL error messages [message #938639 is a reply to message #934768] |
Tue, 09 October 2012 23:13   |
Eclipse User |
|
|
|
Hi Ed.
Thanks for your time. Look, I migrate my project to Eclipse Juno and
OCL 4.0. So I'm trying to implement custom messages. See a part of my code in OCLinEcore editor:
class Graph
{
annotation _'gmf.diagram'
(
onefile = 'true',
_'diagram.extension' = 'Graph'
);
property nodes : Node[*] { ordered composes };
property edges : Edge[*] { ordered composes };
attribute name : String[?] { ordered };
invariant NoDuplicateEdgeNames('No duplicate edges'):
edges->forAll(e1 : Edge, e2 : Edge | e1 <> e2 implies e1.name <> e2.name);
invariant NoDuplicateNodeNames: nodes->forAll(n1 : Node, n2 : Node | n1 <> n2 implies n1.name <> n2.name);
invariant NoMultiGraphs:
edges->forAll(e1 : Edge, e2 : Edge | e1 <> e2 implies e1.start <> e2.start or e1.end <> e2.end);
invariant NoSameOneNodes: edges->forAll(e1 : Edge, e2 : Edge | e1 = e2 implies e1.start <> e1.end);
}
How you can see, invariant NoDuplicateEdgeNames have a message that should be showed when I validate my gmf editor, and
OCLinEcore editor no complains no error. Through this Ecore model, I generated a gmf diagram editor using Eugenia and
when I valid appears the message: The 'NoDuplicateEdgeNames' constraint is violated on '<Graph>' (standard message).
So my doubt is: Do I have to implement more something for the custom message work?
Do I have implement something in CompletOCl?
If you can help me I thank you very much.
Thanks for all and I'm sorry about the English.
Best regards.
|
|
|
Re: Custom OCL error messages [message #938738 is a reply to message #938639] |
Wed, 10 October 2012 01:34   |
Eclipse User |
|
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi<br>
<br>
From the OCL Documentation:<br>
<br>
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="OCLinEcoreEObjectValidator"></a>OCLinEcoreEObjectValidator</h3>
</div>
</div>
</div>
<p>Unfortunately, in the Indigo release, EMF does not support this
customization and so must be activated by explicitly using an
EValidator that is aware of the ValidationDelegateExtension
extended API. This is available by using the
OCLinEcoreEObjectValidator, which you may install globally by:</p>
<div class="literallayout">
<p><code class="code">EValidator.Registry.INSTANCE.put(null, new
OCLinEcoreEObjectValidator());<br>
</code></p>
</div>
<p>or more selectively by adjusting the inheritance of the Validator
class generated by EMF from (for a model of a Company):</p>
<div class="literallayout">
<p><code class="code">import
org.eclipse.emf.ecore.util.EObjectValidator;<br>
<br>
/**<br>
* <!-- begin-user-doc --><br>
* The <b>Validator</b> for the model.<br>
* <!-- end-user-doc --><br>
* @see company.CompanyPackage<br>
*/<br>
public class CompanyValidator extends EObjectValidator {<br>
</code></p>
</div>
<p>to</p>
<div class="literallayout">
<p><code class="code">import
org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator;<br>
<br>
/**<br>
* <!-- begin-user-doc --><br>
* The <b>Validator</b> for the model.<br>
* @extends
org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator<br>
* <!-- end-user-doc --><br>
* @see company.CompanyPackage<br>
*/<br>
public class CompanyValidator extends
OCLinEcoreEObjectValidator {<br>
</code></p>
</div>
<p>Note the <span class="bold"><strong>@extends</strong></span>
within the user-doc comment to preserve the change when genmodel
is run again.</p>
Regards<br>
<br>
Ed Willink<br>
<br>
<br>
On 10/10/2012 04:13, Pablo Silva wrote:
<blockquote cite="mid:k52p40$khj$1@xxxxxxxxe.org" type="cite">Hi
Ed.
<br>
<br>
Thanks for your time. Look, I migrate my project to Eclipse Juno
and
<br>
OCL 4.0. So I'm trying to implement custom messages. See a part of
my code in OCLinEcore editor:
<br>
<br>
class Graph
<br>
{
<br>
annotation _'gmf.diagram'
<br>
(
<br>
onefile = 'true',
<br>
_'diagram.extension' = 'Graph'
<br>
);
<br>
property nodes : Node[*] { ordered composes };
<br>
property edges : Edge[*] { ordered composes };
<br>
attribute name : String[?] { ordered };
<br>
<br>
invariant NoDuplicateEdgeNames('No duplicate edges'):
<br>
edges->forAll(e1 : Edge, e2 : Edge | e1 <> e2
implies e1.name <> e2.name);
<br>
<br>
invariant NoDuplicateNodeNames: nodes->forAll(n1 :
Node, n2 : Node | n1 <> n2 implies n1.name <>
n2.name);
<br>
invariant NoMultiGraphs:
<br>
edges->forAll(e1 : Edge, e2 : Edge | e1 <> e2
implies e1.start <> e2.start or e1.end <> e2.end);
<br>
invariant NoSameOneNodes: edges->forAll(e1 : Edge, e2 :
Edge | e1 = e2 implies e1.start <> e1.end);
<br>
}
<br>
<br>
How you can see, invariant NoDuplicateEdgeNames have a message
that should be showed when I validate my gmf editor, and
<br>
OCLinEcore editor no complains no error. Through this Ecore model,
I generated a gmf diagram editor using Eugenia and
<br>
when I valid appears the message: The 'NoDuplicateEdgeNames'
constraint is violated on '<Graph>' (standard message). So
my doubt is: Do I have to implement more something for the custom
message work?
<br>
Do I have implement something in CompletOCl?
<br>
<br>
If you can help me I thank you very much.
<br>
<br>
Thanks for all and I'm sorry about the English.
<br>
<br>
Best regards.
<br>
</blockquote>
<br>
</body>
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Custom OCL error messages [message #987016 is a reply to message #986313] |
Thu, 22 November 2012 16:53  |
Eclipse User |
|
|
|
I'm back. The fact is that I have tried in various ways to solve my problem myself, but I really could not.
My problem is this, I will detail as much as possible, I want to make clear that I am beginner with OCL and so I'm asking for help:
I implemented a graphical editor using GMF from an EMF model ECORE.
Now I'm implementing restrictions directly on my model ECORE to be able to restrict certain user actions to build the model of it in my editor. I managed to make 4 restrictions that I wanted and they are working perfectly. There is a need to implement that last and had already implemented on an older version of OCL and that was solving my problem. But as the need to customize error messages, I changed to version 4.0 of the OCL and this restriction is now generating an exception.
For you to understand better, I attached a file with pictures of bugs and my model ECORE and then I'll explain the situation by naming the images ok:
The picture1 is an overview of my Model ECORE especially noDuplicateName restriction, which is the restriction that is giving problem. This same restriction was working before I migrate to 4.0 and OCL appear this address
http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot
which was previously being:
http://www.eclipse.org/emf/2002/Ecore/OCL
Picture2 shows the exception being generated to validate my model.
I would like to understand why I can not use the allinstances Class TGObject and also build'm not getting any restriction that is in that same class TGObject exception is thrown. I tried to create this restriction TGApplication in class, but still gives the same error.
I tested this restriction with a dynamic instance of TGApplication Interactive OCL Console in there and got true when there is no name for repeated false and when there was. This does not mean that the restriction is working?
Picture3 shows a further meta model that is part of the model in figure 1, but only to the diagram that is the outermost TGApplication. I was using that meta-model for building graphical editors using GMF framework Eugenia. So I used a more simplified meta-model. As you can see in Picture4, the restriction is that it created for the other model in this case it works. This led me questions, because this is a sub-model of the model shown in Figure 1 and thus, should not throw the same restriction?
I tried to do in other ways, but for example I can not see how to find the same names in a set, since that would be used a function that caught each set and compare with everyone else. I could not create this function and do not know if it is possible to create recursive functions in OCL, is it possible?
For example, I know that expression:
TGObject.allInstances () -> collect (name)
returns me all the names on my editor. In conjunction with all the names I could see if there are the same names.
Another question I have is what happens when a restriction, my editor GMF brand elements involved in this breach with an error symbol and then, in my case I necessarily need an expression that returns true or false, that my editor knew GMF exactly where the breach occurred and could mark the elements involved. Otherwise it would be a general context editor and mark all elements and it would be impossible for me.
I know I'm being persistent and perhaps I will be encomodando. But persistence is that we learn to be more capable. I think it costs nothing to help if you know how to solve my problem and this will be a great help to me, even seeming something so insignificant.
I thank you now and if you need any more information to help me and are willing to tell me this can here anytime we will answer soon.
I ask again apologize for the inconvenience.
Sorry also for English.
Attachment: Desktop.rar
(Size: 742.16KB, Downloaded 350 times)
|
|
|
Powered by
FUDForum. Page generated in 0.03600 seconds