Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » constrain a node to be the only root in a graph
constrain a node to be the only root in a graph [message #836] Thu, 18 January 2007 18:35 Go to next message
Conor Missing name is currently offline Conor Missing nameFriend
Messages: 159
Registered: July 2009
Senior Member
Hi,

I'm very new to OCL and have a few questions, the final one being the one
in the Subject line.

Are there any really good tutorials on OCL? I've had a look at this one
which is alright but are there any someone can recommend?
http://www.sciences.univ-nantes.fr/lina/atl/atldemo/oclturor ial/

What is the purpose of <>, is it not equal to? (java would be !=)


I'm specifically looking at GMF, I presume all OCL situations will
translate to from EMF to GMF?

To write a validation to check that diagram is not empty would it be
something like diagram.self -> isEmpty()

I don't really understand the purpose of 'self', could someone give me a
brief explination?

And finally, how would I write an OCL statement to check in a diagram that
only one node, lets call it A, has no parents (links moving directed away
from it), ie is the root node.


Thanks very much for your help.

Gaff
Re: constrain a node to be the only root in a graph [message #924 is a reply to message #836] Fri, 19 January 2007 21:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Gaff,

See some replies, in-line.

HTH,

Christian


Gaff wrote:

> Hi,
>
> I'm very new to OCL and have a few questions, the final one being the one
> in the Subject line.
>
> Are there any really good tutorials on OCL? I've had a look at this one
> which is alright but are there any someone can recommend?
> http://www.sciences.univ-nantes.fr/lina/atl/atldemo/oclturor ial/

None better that I know of. There is the original Warmer & Kleppe book,
which should do pretty well as OCL 2.0 isn't *so* much different from OCL
1.x.


> What is the purpose of <>, is it not equal to? (java would be !=)

Exactly. Like Basic.


> I'm specifically looking at GMF, I presume all OCL situations will
> translate to from EMF to GMF?

Yes. The usage of OCL in the GMF project is on EMF models.


> To write a validation to check that diagram is not empty would it be
> something like diagram.self -> isEmpty()

More like

self.children->isEmpty()

where "self" represents the diagram (the constraint being defined in the
context of the Diagram class).


> I don't really understand the purpose of 'self', could someone give me a
> brief explination?

Self is very much like 'this' in Java. It represents the element being
constrained by your OCL constraint, on which that constraint is applied at
run-time. It is called the "context variable" and its type is the "context
classifier" in which context the constraint is parsed. Typically the
context is declared in text via, e.g.,:

package notation context Diagram
inv myConstraint: ... your constraint here ...
endpackage

or by the placement of the constraint in the model (e.g., owned by the
Diagram class).


> And finally, how would I write an OCL statement to check in a diagram that
> only one node, lets call it A, has no parents (links moving directed away
> from it), ie is the root node.

Perhaps something like:

self->closure(children)->one( child : View |
child.targetEdges->isEmpty() )

For simplicity, I am here using the "closure" iterator that our OCL
implementation defines as an addition to the language. This follows the
closure of the View::children association, which is (transitively) all of
the descendent views of the diagram (which is the "self" object).

The "one" iterator is defined by the OCL specification to query whether
there is exactly one element in the source collection:

self->closure(children)

for which the body expression:

child.targetEdges->isEmpty()

is true.

>
>
> Thanks very much for your help.
>
> Gaff
Re: constrain a node to be the only root in a graph [message #954 is a reply to message #836] Fri, 19 January 2007 22:25 Go to previous message
Eclipse UserFriend
Originally posted by: bezivin.univ-nantes.fr

Hi Gaff,

The original intention in the facility accessible through the URL you
mention below

http://www.sciences.univ-nantes.fr/lina/atl/atldemo/oclturor ial/

was to demonstrate how a QVT-like
language like ATL could be used to provide a pedagogical
and interactive OCL evaluation service.
It is not really an OCL "tutorial" in the classical meaning.


"Gaff" <conorgaff@hotmail.com> a
Previous Topic:Re: OCL link constraint queries
Next Topic:Re: Problem with Interactive OCL Console used with Sample Ecore Editor
Goto Forum:
  


Current Time: Fri Apr 19 23:02:35 GMT 2024

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

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

Back to the top