Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » def expressions again
def expressions again [message #7183] Tue, 20 February 2007 15:30 Go to next message
Eclipse UserFriend
Originally posted by: joana.trindade.iese.fraunhofer.de

Hello, everyone,

This is more related to the OCL syntax itself. Since I could not find the
answer elsewhere, I was wondering if one of you guys can help me. Is it
possible to define an expression and use this definition in another
expression? Like this:

-- Returns set of connectors whose target is the selected component
context Component
def: inputConnectors() : Set =
Connector.allInstances()->select(c | c.target = self)->asSet()

-- Set of Objects connected to me, using the inputConnectors() definition
above
context Component
def: fanInObjects() : Set =
self.inputConnectors->source->asSet()

Another question is, is there a way to retrieve a reference for an object
in the EMF model, besides the selected object representing the context
(self). For example, in this expression:

-- Returns true if Component A is connected to Component B
context Component
def: isConnected(a : Component) : Boolean =
self.fanInObjects()->includes(a) or
self.fanOutObjects()->includes(a)

Moreover, is there a way to specify an object reference as the parameter
"a", assuming that I have the information on which object is this in the
EMF model?

Thanks in advance,
Joana M. F. Trindade
Re: def expressions again [message #7230 is a reply to message #7183] Tue, 20 February 2007 19:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Joana,

See some replies in-line, below.

HTH,

Christian


Joana M. F. Trindade wrote:

> Hello, everyone,
>
> This is more related to the OCL syntax itself. Since I could not find the
> answer elsewhere, I was wondering if one of you guys can help me. Is it
> possible to define an expression and use this definition in another
> expression? Like this:
>
> -- Returns set of connectors whose target is the selected component
> context Component
> def: inputConnectors() : Set =
> Connector.allInstances()->select(c | c.target = self)->asSet()
>
> -- Set of Objects connected to me, using the inputConnectors() definition
> above
> context Component
> def: fanInObjects() : Set =
> self.inputConnectors->source->asSet()

Absolutely. This is exactly the purpose of "def" expressions. Their
purpose is to help in the definition of OCL constraints by defining
reusable expressions; this is why they are often called "OCL helpers."

One problem with the pre-M5 API is that def expressions are applied globally
(they are attached directly to your model), rather than confined to the OCL
environment context in which they were parsed. This is rectified by the
OCL and OCLHelper APIs introduced in M5.


> Another question is, is there a way to retrieve a reference for an object
> in the EMF model, besides the selected object representing the context
> (self). For example, in this expression:
>
> -- Returns true if Component A is connected to Component B
> context Component
> def: isConnected(a : Component) : Boolean =
> self.fanInObjects()->includes(a) or
> self.fanOutObjects()->includes(a)
>
> Moreover, is there a way to specify an object reference as the parameter
> "a", assuming that I have the information on which object is this in the
> EMF model?

I'm not sure I understand exactly, but we'll see if my answer matches your
question. :-) If you are evaluating an OCL expression from Java code,
then you can always insert the object in question via a Variable binding in
the EvaluationEnvironment or, as you indicate, if it is the "self" object
of an expression. If you need to look this object up within an OCL
expression, then you will have to use Component.allInstances()->any(<expr>)
with an <expr> that matches the object according to your criteria. The
objects in an instance of your model (the run-time data) are not named
model elements that OCL can address "directly."


>
> Thanks in advance,
> Joana M. F. Trindade
Re: def expressions again [message #7278 is a reply to message #7230] Wed, 21 February 2007 12:54 Go to previous message
Eclipse UserFriend
Originally posted by: joana.trindade.iese.fraunhofer.de

Thank you, Christian.

Your answers indeed matched my questions :-)

Regards,
Joana Trindade
Previous Topic:OCL def: expressions in the interpreter
Next Topic:OCL expressions in UML models: free text or modeled
Goto Forum:
  


Current Time: Tue Apr 23 11:25:18 GMT 2024

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

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

Back to the top