Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Operation Body Expression
Operation Body Expression [message #972270] Mon, 05 November 2012 13:48 Go to next message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

I am trying to use Operation Body Expression as they are defined in the OCL specification at section 7.4.6

I created an example ocl file like this
import '[url]http://www.eclipse.org/uml2/4.0.0/UML[/url]'
package UML
context Operation
	def: class:Class=self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
	inv testName('this is a test warning'):
		class.name='Test'
	
endpackage



And validated a simple UML model against it. It works properly.

If I modify the ocl in this way

import 'http://www.eclipse.org/uml2/4.0.0/UML'
package UML


context Operation
	def: class:Class=self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
	inv testName('this is a test warning'):
		class.name='Test'

context Operation::getContainerClass() : Class
	body: self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
		
endpackage



I get an error depicted on the getContainerClass() Operation Declaration saying
Unresolved 'unknown-type' 'getContainerClass'

What am I doing wrong?


Follow me on Twitter @andreasindico

[Updated on: Mon, 05 November 2012 13:48]

Report message to a moderator

Re: Operation Body Expression [message #972770 is a reply to message #972270] Mon, 05 November 2012 22:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4057
Registered: July 2009
Senior Member
Hi

Comments below

On 05/11/2012 13:48, Andrea Sindico wrote:
> I am trying to use Operation Body Expression as they are defined in
> the OCL specification at section 7.4.6
>
Not sure which OCL specification.
7.4.6 is nothing to do with Operation Body Expression.
> I created an example ocl file like this
> Quote:
>> import 'http://www.eclipse.org/uml2/4.0.0/UML'
>> package UML
>> context Operation
>> def:
>> class:Class=self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
>> inv testName('this is a test warning'):
>> class.name='Test'
>>
>> endpackage
>
No idea why you're going to so much trouble to create an ambiguous
definition of the pre-existing UML property.
You might find selectByType() helpful.
>
> And validated a simple UML model against it. It works properly.
>
> If I modify the ocl in this way
>
>
> import 'http://www.eclipse.org/uml2/4.0.0/UML'
> package UML
>
>
> context Operation
> def:
> class:Class=self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
> inv testName('this is a test warning'):
> class.name='Test'
>
> context Operation::getContainerClass() : Class
> body:
> self.oclAsType(ocl::OclElement)->closure(oclContainer())->select(oclIsTypeOf(Class))->any(true).oclAsType(Class)
>
> endpackage
>
>
>
> I get an error depicted on the getContainerClass() Operation
> Declaration saying Unresolved 'unknown-type' 'getContainerClass'
>
> What am I doing wrong?
You are defining a body for a pre-existing operation that is not
pre-existing. Use def to define rather than complement.

Regards

Ed Willink
Re: Operation Body Expression [message #972808 is a reply to message #972270] Mon, 05 November 2012 22:45 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

Ed there is something I still don't understand

The example in the specification is
context Person::getCurrentSpouse() : Person
pre: self.isMarried = true
body: self.mariages->select( m | m.ended = false ).spouse


and an OCL expression is said may be used to indicate the result of a query operation.
Although I may use a define I'd like to understand why it does not work with an operation. I guess I am not getting what does it mean the operation is pre-existing. My aim was actually to define an operation which did not exist.


Follow me on Twitter @andreasindico

[Updated on: Mon, 05 November 2012 22:46]

Report message to a moderator

Re: Operation Body Expression [message #973429 is a reply to message #972808] Tue, 06 November 2012 10:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4057
Registered: July 2009
Senior Member
Hi

A Complete OCL document complements a pre-existing meta-model which may
contain classes, operations and properties. (body:, pre:, post:)

(context anOperation) Incomplete operations may be complemented by
defining a body, pre-conditions and post conditions. (init:, derive:)

(context aProperty) Incomplete properties may be complemented by
defining an initial value, or imposing a derived constraint.

(context aType) types may be complemented/extended by defining
additional operations and properties (def:...)

You are confusing the two syntaxes for operation.

Regards

Ed Willink

On 05/11/2012 22:45, Andrea Sindico wrote:
> Ed there is something I still don't understand
>
> The example in the specification is
>
> context Person::getCurrentSpouse() : Person
> pre: self.isMarried = true
> body: self.mariages->select( m | m.ended = false ).spouse
>
>
> and an OCL expression is said may be used to indicate the result of a
> query operation. Although I may use a define I'd like to understand
> why it does not work with an operation. I guess I am not getting the
> what does it mean the operation is pre-existing. My aim was actually
> to define an operation which did not exist.
Re: Operation Body Expression [message #973953 is a reply to message #972270] Tue, 06 November 2012 19:02 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

yes I misunderstood it.
I thought it was a means to define queries (like queries in MOFM2T). Is there any way to do that?
As far as I understand a def is accessible in the context where it is defined.
I would like instead to define a query accessible from different contexts.

Thank you Ed


Follow me on Twitter @andreasindico

Re: Operation Body Expression [message #974072 is a reply to message #973953] Tue, 06 November 2012 20:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4057
Registered: July 2009
Senior Member
Hi

The additional features should be accessible wherever the Complete OCL
document is loaded.

Regards

Ed Willink

On 06/11/2012 19:02, Andrea Sindico wrote:
> yes I misunderstood it. I thought it was a means to define queries
> (like queries in MOFM2T). Is there any way to do that? As far as I
> understand a def is accessible in the context where it is defined. I
> would like instead to define a query accessible from different contexts.
>
> Thank you Ed
Re: Operation Body Expression [message #980059 is a reply to message #972270] Sun, 11 November 2012 10:08 Go to previous message
Andrea Sindico is currently offline Andrea Sindico
Messages: 266
Registered: November 2010
Senior Member

indeed they are. Thanks Ed now I have got it

Follow me on Twitter @andreasindico

Previous Topic:OCL Interpreter in Java (Helios)
Next Topic:OCL Iterator index
Goto Forum:
  


Current Time: Wed Oct 01 08:21:41 GMT 2014

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

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