Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Custom OCL error messages
Custom OCL error messages [message #932092] Wed, 03 October 2012 16:37 Go to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

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 #932431 is a reply to message #932092] Thu, 04 October 2012 01:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

You will find the OCLinEcore editor very helpful for adding OCL to Ecore
models. See
http://help.eclipse.org/juno/topic/org.eclipse.ocl.doc/help/Tutorials.html?cp=42_3_0#OCLinEcoreTutorial.

There is an experimental syntax for custom validation messages. See
http://help.eclipse.org/juno/topic/org.eclipse.ocl.doc/help/Integration.html?cp=42_1_7_1#Integration-Messages.

Regards

Ed Willink

On 03/10/2012 22:37, Pablo Silva wrote:
> 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 #933966 is a reply to message #932431] Fri, 05 October 2012 10:09 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Hi Ed Wilink,

firstly thanks for help.

So I studied the links that you showed me.
I tried implement in my EMF Ecore but for custom messages I try do that way:

import ecore_0 : 'http://www.eclipse.org/emf/2002/Ecore#/';

package terramegims : _'com.terralab.terramegims' = 'http:///com/terralab/terramegims.ecore'
{
	class TGObject { abstract }
	{
		invariant noDuplicateNames('Names must be uniques.'):
		TGObject.allInstances()->forAll(e1| (e1 <> self and e1 <> Jump and e1 <> StateInitial) implies e1.name <> self.name);
		attribute name : noInvalidCaracter[1] = 'terramegimsObjectID';
		attribute terraMESourceCode : String[1] = '' { readonly };
	}


but I don't know why, the editor OCLinEcore is accusing an error.
Isn't to be right?

Do I need install more some plugin in eclipse for to do work?

Thanks for your attention!
Re: Custom OCL error messages [message #934061 is a reply to message #933966] Fri, 05 October 2012 12:07 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Leveraging the topic, I need to formulate an OCL expression that returns me all objects created less of Jump Type and type StateInicial.
An expression that returns all the items I got:

TGObject.allInstances() (TGObject is my Super Class)

Now I need to filter this set returned. I tried to use collect() with reject(), but the compiler Interactive OCL is accusing error, look my expression:

TGObject.allInstances()->collect( i_Object : TGObject | i_Object )->reject(i_Jump: Jump | i_Jump.name <> null) (Jump is a type that I need exclude)

I tried this too

TGObject.allInstances()->reject(e : TGObject | e = (terramegims::Jump))

I got what I wanted with this expression but I think that can bring future errors:

TGObject.allInstances()->select(o: TGObject | o.name <> 'myJump' and o.name <> 'initialState')->forAll(e|e <> self implies e.name <> self.name)


Actualy I don't know is that is rigth. I though in use excludeAll() but all times I tried, the compiler accused error.
So if you can help me to use excludeAll() solve a part of my troubles.


More one time, Thank you attention.

[Updated on: Fri, 05 October 2012 13:24]

Report message to a moderator

Re: Custom OCL error messages [message #934767 is a reply to message #933966] Sat, 06 October 2012 05:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

I cannot comment on an error that you do not identify.

I cannot reproduce the error from an incomplete example.

Regards

Ed Willink

On 05/10/2012 16:09, Pablo Silva wrote:
> Hi Ed Wilink,
>
> firstly thanks for help.
>
> So I studied the links that you showed me.
> I tried implement in my EMF Ecore but for custom messages I try do
> that way:
>
> import ecore_0 : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package terramegims : _'com.terralab.terramegims' =
> 'http:///com/terralab/terramegims.ecore'
> {
> class TGObject { abstract }
> {
> invariant noDuplicateNames('Names must be uniques.'):
> TGObject.allInstances()->forAll(e1| (e1 <> self and e1 <> Jump
> and e1 <> StateInitial) implies e1.name <> self.name);
> attribute name : noInvalidCaracter[1] = 'terramegimsObjectID';
> attribute terraMESourceCode : String[1] = '' { readonly };
> }
>
> but I don't know why, the editor OCLinEcore is accusing an error.
> Isn't to be right?
>
> Do I need install more some plugin in eclipse for to do work?
>
> Thanks for your attention!
Re: Custom OCL error messages [message #934768 is a reply to message #934061] Sat, 06 October 2012 05:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

Again:

I cannot comment on an error that you do not identify.

I cannot reproduce the error from an incomplete example.

In general, any approach that uses allInstances() is bad. It is very
inefficient. It should only be used for exposition rather than
execution. Try locating the constraint somewhere more sensible like the
instance class.

Regards

Ed Willink
On 05/10/2012 18:07, Pablo Silva wrote:
> Leveraging the topic, I need to formulate an OCL expression that
> returns me all objects created less of Jump Type and type
> StateInicial. An expression that returns all the items I got:
>
> TGObject.allInstances() (TGObject is my Super Class)
>
> Now I need to filter this set returned. I tried to use collect() with
> reject(), but the compiler Interactive OCL is accusing error, look my
> expression:
>
> TGObject.allInstances()->collect( i_Object : TGObject | i_Object
> )->reject(i_Jump: Jump | i_Jump.name <> null) (Jump is a type that I
> need exclude)
>
> Actualy I don't know is that is rigth. I though in use excludeAll()
> but all times I tried, the compiler accused error.
> So if you can help me to use excludeAll() solve a part of my troubles.
>
> More one time, Thank you attention.
Re: Custom OCL error messages [message #938639 is a reply to message #934768] Tue, 09 October 2012 23:13 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

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 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
<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>
* &lt;!-- begin-user-doc --&gt;<br>
* The &lt;b&gt;Validator&lt;/b&gt; for the model.<br>
* &lt;!-- end-user-doc --&gt;<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>
* &lt;!-- begin-user-doc --&gt;<br>
* The &lt;b&gt;Validator&lt;/b&gt; for the model.<br>
* @extends
org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator<br>
* &lt;!-- end-user-doc --&gt;<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-&gt;forAll(e1 : Edge, e2 : Edge | e1 &lt;&gt; e2
implies e1.name &lt;&gt; e2.name);
<br>
<br>
        invariant NoDuplicateNodeNames: nodes-&gt;forAll(n1 :
Node, n2 : Node | n1 &lt;&gt; n2 implies n1.name &lt;&gt;
n2.name);
<br>
        invariant NoMultiGraphs:
<br>
        edges-&gt;forAll(e1 : Edge, e2 : Edge | e1 &lt;&gt; e2
implies e1.start &lt;&gt; e2.start or e1.end &lt;&gt; e2.end);
<br>
        invariant NoSameOneNodes: edges-&gt;forAll(e1 : Edge, e2 :
Edge | e1 = e2 implies e1.start &lt;&gt; 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 '&lt;Graph&gt;' (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 #939017 is a reply to message #938738] Wed, 10 October 2012 06:55 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Thank you so much!
I gotta!
Re: Custom OCL error messages [message #986120 is a reply to message #939017] Sun, 18 November 2012 23:22 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Building on this topic, I am working on customizing messages displayed by ocl, my expression must return null for that then appears an error rather than a warming, look at my expression:

TGObject.allInstances () -> select (o: TGObject | o.name <> 'myJump' and o.name <> 'initialState') -> forall (e: TGObject | e <> self implies if e.name <> self.name then true else null endif)

I tried to return null when the expression is the same two names return null, but I tested with a dynamic instance and the result is an expression of oclInvalid and thus the restriction does not work properly.

Any idea how to make this expression returns null?
Thankful.

Sorry for the english.
Re: Custom OCL error messages [message #986136 is a reply to message #986120] Mon, 19 November 2012 02:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

You must return null from the outer level.

Instead you are generating null as the forall body and consequently
getting invalid since it is invalid for forall's body to be null or invalid.

In practice, it is easier and more readable to use a helper function
that just converts true/false to true/null.

[Using allInstances is very poor practice. Surely you can move the
constraint to TGObject, avoiding underlying overheads and getting a
context for a failure?]

Regards

Ed Willink

On 19/11/2012 04:22, Pablo Silva wrote:
> Building on this topic, I am working on customizing messages displayed
> by ocl, my expression must return null for that then appears an error
> rather than a warming, look at my expression:
>
> TGObject.allInstances () -> select (o: TGObject | o.name <> 'myJump'
> and o.name <> 'initialState') -> forall (e: TGObject | e <> self
> implies if e.name <> self.name then true else null endif)
>
> I tried to return null when the expression is the same two names
> return null, but I tested with a dynamic instance and the result is an
> expression of oclInvalid and thus the restriction does not work properly.
>
> Any idea how to make this expression returns null?
> Thankful.
>
> Sorry for the english.
Re: Custom OCL error messages [message #986196 is a reply to message #932092] Mon, 19 November 2012 07:18 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

I think I understand.
But, can you give me some example?


In my model encore all classes inherit from class TGObject that possesses the attribute name. I need to make the diagram GMF no element has the same name as another.

Watch an excerpt of the model:

import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';

package terramegims : _'com.terralab.terramegims' = 'http:///com/terralab/terramegims.ecore'
{
	abstract class TGObject
	{
		attribute name : noInvalidCaracter = 'terramegimsObjectID' { ordered };
		attribute terraMESourceCode : String = '' { ordered readonly };
		invariant noDuplicateNames: TGObject.allInstances()->forAll(e : TGObject | e <> self implies e.name <> self.name);
	}
	abstract class TGModel extends TGObject;
	abstract class TGAbstractFunction extends TGObject
	{
		property variables : TGVariable[*] { ordered composes !resolve };
		attribute body : String = '' { ordered };
	}
	abstract class TGAbstractAutomaton extends TGModel
	{
		property variables : TGVariable[*] { ordered composes !resolve };
		property functions : TGFunction[*] { ordered composes !resolve };
		property initialState : StateInitial { ordered composes !resolve };
		property states : State[*] { ordered composes !resolve };
		property trajectories : Trajectory[*] { ordered composes !resolve };
	}
	abstract class TGAbstractNeighborhood extends TGObject
	{
		property cellularSpace#neighborhoods : CellularSpace { ordered };
	}
	class TGVariable extends TGObject
	{
		attribute value : String = '' { ordered };
	}
	class TGParameter extends TGVariable;
	class TGFunction extends TGAbstractFunction
	{
		property parameters : TGParameter[*] { ordered composes !resolve };
		attribute parameters_str : String { ordered };
	}
	class TGFunctionMain extends TGAbstractFunction;
	abstract class TGRule extends TGObject
	{
		attribute rule : String = '' { ordered };
	}
	class TGApplication extends TGObject
	{
		property variables : TGVariable[*] { ordered composes !resolve };
		property functions : TGFunction[*] { ordered composes !resolve };
		property environment : Environment[?] { ordered composes !resolve };
		property main : TGFunctionMain { ordered composes !resolve };
	}


If you can explain to me how it would be another way other than with the allinstances I appreciate it.

Thanks again and sorry for the english.
Re: Custom OCL error messages [message #986220 is a reply to message #986196] Mon, 19 November 2012 08:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

From the Complete OCL tutorial in the OCL documentation:

def: asError(verdict : Boolean) : Boolean =
if verdict then true else null endif



inv DerivationIsVolatile(
'"volatile" must be specified for derived feature ' + self.toString()):
asError(hasDerivation implies volatile)

Regards

Ed Willink


On 19/11/2012 12:18, Pablo Silva wrote:
> I think I understand.
> But, can you give me some example?
>
>
> In my model encore all classes inherit from class TGObject that
> possesses the attribute name. I need to make the diagram GMF no
> element has the same name as another.
>
> Watch an excerpt of the model:
>
> import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';
>
> package terramegims : _'com.terralab.terramegims' =
> 'http:///com/terralab/terramegims.ecore'
> {
> abstract class TGObject
> {
> attribute name : noInvalidCaracter = 'terramegimsObjectID' {
> ordered };
> attribute terraMESourceCode : String = '' { ordered readonly };
> invariant noDuplicateNames: TGObject.allInstances()->forAll(e
> : TGObject | e <> self implies e.name <> self.name);
> }
> abstract class TGModel extends TGObject;
> abstract class TGAbstractFunction extends TGObject
> {
> property variables : TGVariable[*] { ordered composes !resolve };
> attribute body : String = '' { ordered };
> }
> abstract class TGAbstractAutomaton extends TGModel
> {
> property variables : TGVariable[*] { ordered composes !resolve };
> property functions : TGFunction[*] { ordered composes !resolve };
> property initialState : StateInitial { ordered composes
> !resolve };
> property states : State[*] { ordered composes !resolve };
> property trajectories : Trajectory[*] { ordered composes
> !resolve };
> }
> abstract class TGAbstractNeighborhood extends TGObject
> {
> property cellularSpace#neighborhoods : CellularSpace { ordered };
> }
> class TGVariable extends TGObject
> {
> attribute value : String = '' { ordered };
> }
> class TGParameter extends TGVariable;
> class TGFunction extends TGAbstractFunction
> {
> property parameters : TGParameter[*] { ordered composes
> !resolve };
> attribute parameters_str : String { ordered };
> }
> class TGFunctionMain extends TGAbstractFunction;
> abstract class TGRule extends TGObject
> {
> attribute rule : String = '' { ordered };
> }
> class TGApplication extends TGObject
> {
> property variables : TGVariable[*] { ordered composes !resolve };
> property functions : TGFunction[*] { ordered composes !resolve };
> property environment : Environment[?] { ordered composes
> !resolve };
> property main : TGFunctionMain { ordered composes !resolve };
> }
>
> If you can explain to me how it would be another way other than with
> the allinstances I appreciate it.
>
> Thanks again and sorry for the english.
Re: Custom OCL error messages [message #986234 is a reply to message #986220] Mon, 19 November 2012 09:44 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

So,

Do I have to use Complete OCL in my model?

Regards.
Pablo.
Re: Custom OCL error messages [message #986251 is a reply to message #932092] Mon, 19 November 2012 11:05 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

I'm trying to formulate a new expression to validate the duplication of names in my GMF editor without using the term in allinstances Class TGObject. Noting that I can only create elements within the class TGApplication, I'm trying to formulate an expression within that class to do this validation. But I can not see a way to go all "children" of TGApplication without using the term in allinstances Class TGObject. For example if I do this:

self.main-> select (self.name = main.name)

where self refers to class TGOApplication, I can retrieve all mains which has the same element name TGApplication, but so would be impractical to make such an expression for each element once I create 7 types of different elements within these elements can create new elements and therefore could not make as many combinations as well.

The expression that I had shown him:

TGObject.allInstances () -> select (o: TGObject | o.name <> 'myJump' and o.name <> 'initialState') -> forall (e | e <> self implies e.name <> self.name )

that previously I have changed the Validation class to be able to customize ocl messages present in my ecore model:

//import org.eclipse.emf.ecore.util.EObjectValidator;
import org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator;
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
import org.eclipse.emf.ecore.xml.type.util.XMLTypeValidator;

/**
 * <!-- begin-user-doc -->
 * The <b>Validator</b> for the model.
 * <!-- end-user-doc -->
 * @see com.terralab.terramegims.TerramegimsPackage
 * @generated NOT MODIFIED
 */
public class TerramegimsValidator extends OCLinEcoreEObjectValidator {


no longer works after I made this change. When she will be evolved into my graphics editor, an exception occurs:

An exception occurred while delegating evaluation of the 'noDuplicateNames' constraint on 'tgimsapp :: main': OCL validation result of 'TGObject :: noDuplicateNames' is invalid for 'Class TGObject'

and I googled and could not understand why the restriction that no longer works.
I really need to learn this. If you have some material that I can study and can send me I am very grateful. I'm not wanting a ready answer, if I have the right tools for sure that I will study and be able to do. The problem is that here in Brazil almost nobody works with this type of tool and there is hard to find material.

Thank you very much for your help so far and sorry for the inconvenience.
Sorry for the english.
Best regards.
Pablo Silva
Re: Custom OCL error messages [message #986277 is a reply to message #986251] Mon, 19 November 2012 12:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

I'm sorry, but I am unable to help in discussions for which you provide
no background models that demonstrate what does/doesn't work. I'm not
telepathic and do not have time to guess at your underlying attempts.

Regards

Ed Willink

On 19/11/2012 16:05, Pablo Silva wrote:
> I'm trying to formulate a new expression to validate the duplication
> of names in my GMF editor without using the term in allinstances Class
> TGObject. Noting that I can only create elements within the class
> TGApplication, I'm trying to formulate an expression within that class
> to do this validation. But I can not see a way to go all "children" of
> TGApplication without using the term in allinstances Class TGObject.
> For example if I do this:
>
> self.main-> select (self.name = main.name)
>
> where self refers to class TGOApplication, I can retrieve all mains
> which has the same element name TGApplication, but so would be
> impractical to make such an expression for each element once I create
> 7 types of different elements within these elements can create new
> elements and therefore could not make as many combinations as well.
>
> The expression that I had shown him:
>
> TGObject.allInstances () -> select (o: TGObject | o.name <> 'myJump'
> and o.name <> 'initialState') -> forall (e | e <> self implies e.name
> <> self.name )
>
> that previously I have changed the Validation class to be able to
> customize ocl messages present in my ecore model:
>
> //import org.eclipse.emf.ecore.util.EObjectValidator;
> import
> org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator;
> import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
> import org.eclipse.emf.ecore.xml.type.util.XMLTypeValidator;
>
> /**
> * <!-- begin-user-doc -->
> * The <b>Validator</b> for the model.
> * <!-- end-user-doc -->
> * @see com.terralab.terramegims.TerramegimsPackage
> * @generated NOT MODIFIED
> */
> public class TerramegimsValidator extends OCLinEcoreEObjectValidator {
>
> no longer works after I made this change. When she will be evolved
> into my graphics editor, an exception occurs:
>
> An exception occurred while delegating evaluation of the
> 'noDuplicateNames' constraint on 'tgimsapp :: main': OCL validation
> result of 'TGObject :: noDuplicateNames' is invalid for 'Class TGObject'
>
> and I googled and could not understand why the restriction that no
> longer works.
> I really need to learn this. If you have some material that I can
> study and can send me I am very grateful. I'm not wanting a ready
> answer, if I have the right tools for sure that I will study and be
> able to do. The problem is that here in Brazil almost nobody works
> with this type of tool and there is hard to find material.
>
> Thank you very much for your help so far and sorry for the inconvenience.
> Sorry for the english.
> Best regards.
> Pablo Silva
Re: Custom OCL error messages [message #986278 is a reply to message #986234] Mon, 19 November 2012 12:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

No. It's just an example of a function that maps the invariant return
type. You can define functions in OCLinEcore too.

Regards

Ed Willink

On 19/11/2012 14:44, Pablo Silva wrote:
> So,
>
> Do I have to use Complete OCL in my model?
>
> Regards.
> Pablo.
Re: Custom OCL error messages [message #986299 is a reply to message #986278] Mon, 19 November 2012 13:56 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Unfortunately being a new user forum, I still can not post pictures.
I apologize for the inconvenience and thank you for your attention.

Best regards
Pablo
Re: Custom OCL error messages [message #986313 is a reply to message #986299] Mon, 19 November 2012 16:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

A picture is usually very irritating since it has to be rekeyed. Zipped
projects are much much better.

Regards

Ed Willink

On 19/11/2012 18:56, Pablo Silva wrote:
> Unfortunately being a new user forum, I still can not post pictures.
> I apologize for the inconvenience and thank you for your attention.
>
> Best regards
> Pablo
Re: Custom OCL error messages [message #987016 is a reply to message #986313] Thu, 22 November 2012 16:53 Go to previous message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

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 126 times)
Previous Topic:EmbeddedXtextEditor and context for expression
Next Topic:def initialized with alternatives (or)
Goto Forum:
  


Current Time: Sat Aug 30 08:36:29 EDT 2014

Powered by FUDForum. Page generated in 0.02553 seconds