Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » New to EMF and OCL
New to EMF and OCL [message #468322] Wed, 05 August 2009 03:13 Go to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
All,

I am using the EMF Framework Validation Plug-in: "OCL Example". It
allows me to write OCL expressions in a text file.

Is it possible to set properties in the model based on OCL expressions?
The OCL 2.0 Spec says that expressions are guaranteed to be without
side effects, but then goes on to say that OCL expressio can be used to
specify a state change (eg. in a post-condition).

Pardon me if this is an obvious question. I am new to EMF and OCL.

Thank you,
Richard Catlin
Re: New to EMF and OCL [message #468435 is a reply to message #468322] Wed, 05 August 2009 14:19 Go to previous messageGo to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
Further thoughts on this question:

If I create a simple EClass called Architecture in Ecore with a property
of "hardwareNotes", then when I generate the model, a
setHardwareNotes(String name) method is generated. When I use the
Interactive OCL Console, I get the following error:

self.setHardwareNotes('hw1')

Cannot find operation (setHardwareNotes(String)) for the type (Architecture)

How can I go about setting this?

Thank you,
Richard

On 8/4/2009 8:13 PM, Richard Catlin wrote:
> All,
>
> I am using the EMF Framework Validation Plug-in: "OCL Example". It
> allows me to write OCL expressions in a text file.
>
> Is it possible to set properties in the model based on OCL expressions?
> The OCL 2.0 Spec says that expressions are guaranteed to be without
> side effects, but then goes on to say that OCL expressio can be used to
> specify a state change (eg. in a post-condition).
>
> Pardon me if this is an obvious question. I am new to EMF and OCL.
>
> Thank you,
> Richard Catlin
Re: New to EMF and OCL [message #478772 is a reply to message #468322] Thu, 06 August 2009 19:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Richard

I don't really understand what you're asking.

A pre-condition is a side-effect free expression that can be used to
determine whether the invocation context is suitable to invoke a function.

The function can the do whatever it likes.

A post-condition is a side-effect free expression that can be used to
determine whether the function behaved as expected.

Sometimes the post-condition may be sufficiently simple to be able to
reinterpret its is-it-so query into a make-it-so operation. That is not
what OCL does, although a specific form of OCL code synthesizer might.

Regards

Ed Willink


Richard Catlin wrote:
> All,
>
> I am using the EMF Framework Validation Plug-in: "OCL Example". It
> allows me to write OCL expressions in a text file.
>
> Is it possible to set properties in the model based on OCL expressions?
> The OCL 2.0 Spec says that expressions are guaranteed to be without
> side effects, but then goes on to say that OCL expressio can be used to
> specify a state change (eg. in a post-condition).
>
> Pardon me if this is an obvious question. I am new to EMF and OCL.
>
> Thank you,
> Richard Catlin
Re: New to EMF and OCL [message #478773 is a reply to message #468435] Thu, 06 August 2009 19:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Richard

setHardwareNotes is an implementation artefact created by EMF, it is not
part of the Ecore class, so it is not accessible from OCL, although the
OCL implementation may use it.

You have defined a property so that is what you should use.

self.hardwareNotes = 'hw1'

Regards

Ed Willink


Richard Catlin wrote:
> Further thoughts on this question:
>
> If I create a simple EClass called Architecture in Ecore with a property
> of "hardwareNotes", then when I generate the model, a
> setHardwareNotes(String name) method is generated. When I use the
> Interactive OCL Console, I get the following error:
>
> self.setHardwareNotes('hw1')
>
> Cannot find operation (setHardwareNotes(String)) for the type
> (Architecture)
>
> How can I go about setting this?
>
> Thank you,
> Richard
>
> On 8/4/2009 8:13 PM, Richard Catlin wrote:
>> All,
>>
>> I am using the EMF Framework Validation Plug-in: "OCL Example". It
>> allows me to write OCL expressions in a text file.
>>
>> Is it possible to set properties in the model based on OCL
>> expressions? The OCL 2.0 Spec says that expressions are guaranteed to
>> be without side effects, but then goes on to say that OCL expressio
>> can be used to specify a state change (eg. in a post-condition).
>>
>> Pardon me if this is an obvious question. I am new to EMF and OCL.
>>
>> Thank you,
>> Richard Catlin
Re: New to EMF and OCL [message #478801 is a reply to message #478773] Fri, 07 August 2009 00:23 Go to previous messageGo to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
Ed,

I'm not sure where I should use
self.hardwareNotes = 'hw1'

I am using the OCL text file, so should it be something like this?

package sizing

context: Architecture
if(true)
self.hardwareNotes = 'hw1'
end

endpackage

Thank you for your help.

Regards,
Richard Catlin


On 8/6/2009 12:26 PM, Ed Willink wrote:
> Hi Richard
>
> setHardwareNotes is an implementation artefact created by EMF, it is not
> part of the Ecore class, so it is not accessible from OCL, although the
> OCL implementation may use it.
>
> You have defined a property so that is what you should use.
>
> self.hardwareNotes = 'hw1'
>
> Regards
>
> Ed Willink
>
>
> Richard Catlin wrote:
>> Further thoughts on this question:
>>
>> If I create a simple EClass called Architecture in Ecore with a
>> property of "hardwareNotes", then when I generate the model, a
>> setHardwareNotes(String name) method is generated. When I use the
>> Interactive OCL Console, I get the following error:
>>
>> self.setHardwareNotes('hw1')
>>
>> Cannot find operation (setHardwareNotes(String)) for the type
>> (Architecture)
>>
>> How can I go about setting this?
>>
>> Thank you,
>> Richard
>>
>> On 8/4/2009 8:13 PM, Richard Catlin wrote:
>>> All,
>>>
>>> I am using the EMF Framework Validation Plug-in: "OCL Example". It
>>> allows me to write OCL expressions in a text file.
>>>
>>> Is it possible to set properties in the model based on OCL
>>> expressions? The OCL 2.0 Spec says that expressions are guaranteed
>>> to be without side effects, but then goes on to say that OCL
>>> expressio can be used to specify a state change (eg. in a
>>> post-condition).
>>>
>>> Pardon me if this is an obvious question. I am new to EMF and OCL.
>>>
>>> Thank you,
>>> Richard Catlin
Re: New to EMF and OCL [message #478814 is a reply to message #478801] Fri, 07 August 2009 04:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI Richard

I am sorry, but if you want help learning the OCL lanaguage you should
consult one of the inline guides or buy a book. I found that Warmer and
Kleppe's book is very readable.

Regards

Ed Willink

Richard Catlin wrote:
> Ed,
>
> I'm not sure where I should use
> self.hardwareNotes = 'hw1'
>
> I am using the OCL text file, so should it be something like this?
>
> package sizing
>
> context: Architecture
> if(true)
> self.hardwareNotes = 'hw1'
> end
>
> endpackage
>
> Thank you for your help.
>
> Regards,
> Richard Catlin
>
>
> On 8/6/2009 12:26 PM, Ed Willink wrote:
>> Hi Richard
>>
>> setHardwareNotes is an implementation artefact created by EMF, it is
>> not part of the Ecore class, so it is not accessible from OCL,
>> although the OCL implementation may use it.
>>
>> You have defined a property so that is what you should use.
>>
>> self.hardwareNotes = 'hw1'
>>
>> Regards
>> Ed Willink
>>
>>
>> Richard Catlin wrote:
>>> Further thoughts on this question:
>>>
>>> If I create a simple EClass called Architecture in Ecore with a
>>> property of "hardwareNotes", then when I generate the model, a
>>> setHardwareNotes(String name) method is generated. When I use the
>>> Interactive OCL Console, I get the following error:
>>>
>>> self.setHardwareNotes('hw1')
>>>
>>> Cannot find operation (setHardwareNotes(String)) for the type
>>> (Architecture)
>>>
>>> How can I go about setting this?
>>>
>>> Thank you,
>>> Richard
>>>
>>> On 8/4/2009 8:13 PM, Richard Catlin wrote:
>>>> All,
>>>>
>>>> I am using the EMF Framework Validation Plug-in: "OCL Example". It
>>>> allows me to write OCL expressions in a text file.
>>>>
>>>> Is it possible to set properties in the model based on OCL
>>>> expressions? The OCL 2.0 Spec says that expressions are guaranteed
>>>> to be without side effects, but then goes on to say that OCL
>>>> expressio can be used to specify a state change (eg. in a
>>>> post-condition).
>>>>
>>>> Pardon me if this is an obvious question. I am new to EMF and OCL.
>>>>
>>>> Thank you,
>>>> Richard Catlin
Re: New to EMF and OCL - Question: If my method returns void, how do I use it in the invariant? [message #479164 is a reply to message #478814] Mon, 10 August 2009 03:38 Go to previous messageGo to next message
Richard Catlin is currently offline Richard CatlinFriend
Messages: 50
Registered: July 2009
Member
Ed,

Thanks. I ordered Kleppe's book. I was reading Ch 7 of the OCL Spec,
and did understand the syntax. The problem I was having was
understanding how to call a method on the generated code; mainly because
I was using the OCL text file to create the invariants. I finally got
this method to work:

public boolean setOutput1() {
setHardwareNotes("test33");
return true;
}

with the invariant declared as:

package sizing

context Architecture

inv inv_3: self.questions->size() < 1

inv inv_4: self.hardwareNotes = 'hw5'

inv inv_5: self.setOutput1()

endpackage

Question: If my method returns void, how do I use it in the invariant?

Regards,
Richard Catlin



On 8/6/2009 9:50 PM, Ed Willink wrote:
> HI Richard
>
> I am sorry, but if you want help learning the OCL lanaguage you should
> consult one of the inline guides or buy a book. I found that Warmer and
> Kleppe's book is very readable.
>
> Regards
>
> Ed Willink
>
> Richard Catlin wrote:
>> Ed,
>>
>> I'm not sure where I should use
>> self.hardwareNotes = 'hw1'
>>
>> I am using the OCL text file, so should it be something like this?
>>
>> package sizing
>>
>> context: Architecture
>> if(true)
>> self.hardwareNotes = 'hw1'
>> end
>>
>> endpackage
>>
>> Thank you for your help.
>>
>> Regards,
>> Richard Catlin
>>
>>
>> On 8/6/2009 12:26 PM, Ed Willink wrote:
>>> Hi Richard
>>>
>>> setHardwareNotes is an implementation artefact created by EMF, it is
>>> not part of the Ecore class, so it is not accessible from OCL,
>>> although the OCL implementation may use it.
>>>
>>> You have defined a property so that is what you should use.
>>>
>>> self.hardwareNotes = 'hw1'
>>>
>>> Regards
>>> Ed Willink
>>>
>>>
>>> Richard Catlin wrote:
>>>> Further thoughts on this question:
>>>>
>>>> If I create a simple EClass called Architecture in Ecore with a
>>>> property of "hardwareNotes", then when I generate the model, a
>>>> setHardwareNotes(String name) method is generated. When I use the
>>>> Interactive OCL Console, I get the following error:
>>>>
>>>> self.setHardwareNotes('hw1')
>>>>
>>>> Cannot find operation (setHardwareNotes(String)) for the type
>>>> (Architecture)
>>>>
>>>> How can I go about setting this?
>>>>
>>>> Thank you,
>>>> Richard
>>>>
>>>> On 8/4/2009 8:13 PM, Richard Catlin wrote:
>>>>> All,
>>>>>
>>>>> I am using the EMF Framework Validation Plug-in: "OCL Example". It
>>>>> allows me to write OCL expressions in a text file.
>>>>>
>>>>> Is it possible to set properties in the model based on OCL
>>>>> expressions? The OCL 2.0 Spec says that expressions are guaranteed
>>>>> to be without side effects, but then goes on to say that OCL
>>>>> expressio can be used to specify a state change (eg. in a
>>>>> post-condition).
>>>>>
>>>>> Pardon me if this is an obvious question. I am new to EMF and OCL.
>>>>>
>>>>> Thank you,
>>>>> Richard Catlin
Re: New to EMF and OCL - Question: If my method returns void, how do I use it in the invariant? [message #479169 is a reply to message #479164] Mon, 10 August 2009 05:14 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Richard

Any OCL expression is side effect free, so anything used in an OCL
invariant is side effect free, so why would you want to call a method
that returned void? the method returns nothing and so does nothing.

So the answer is you can't.

NB. Your inv_4 is a comparison not an assignment.

NB. Your inv-5 invokes a side effecting function and so is not a valid
OCL invariant.

Regards

Ed Willink

Richard Catlin wrote:
> Ed,
>
> Thanks. I ordered Kleppe's book. I was reading Ch 7 of the OCL Spec,
> and did understand the syntax. The problem I was having was
> understanding how to call a method on the generated code; mainly because
> I was using the OCL text file to create the invariants. I finally got
> this method to work:
>
> public boolean setOutput1() {
> setHardwareNotes("test33");
> return true;
> }
>
> with the invariant declared as:
>
> package sizing
>
> context Architecture
>
> inv inv_3: self.questions->size() < 1
>
> inv inv_4: self.hardwareNotes = 'hw5'
>
> inv inv_5: self.setOutput1()
>
> endpackage
>
> Question: If my method returns void, how do I use it in the invariant?
>
> Regards,
> Richard Catlin
>
>
>
> On 8/6/2009 9:50 PM, Ed Willink wrote:
>> HI Richard
>>
>> I am sorry, but if you want help learning the OCL lanaguage you should
>> consult one of the inline guides or buy a book. I found that Warmer
>> and Kleppe's book is very readable.
>>
>> Regards
>>
>> Ed Willink
>>
>> Richard Catlin wrote:
>>> Ed,
>>>
>>> I'm not sure where I should use
>>> self.hardwareNotes = 'hw1'
>>>
>>> I am using the OCL text file, so should it be something like this?
>>>
>>> package sizing
>>>
>>> context: Architecture
>>> if(true)
>>> self.hardwareNotes = 'hw1'
>>> end
>>>
>>> endpackage
>>>
>>> Thank you for your help.
>>>
>>> Regards,
>>> Richard Catlin
>>>
>>>
>>> On 8/6/2009 12:26 PM, Ed Willink wrote:
>>>> Hi Richard
>>>>
>>>> setHardwareNotes is an implementation artefact created by EMF, it is
>>>> not part of the Ecore class, so it is not accessible from OCL,
>>>> although the OCL implementation may use it.
>>>>
>>>> You have defined a property so that is what you should use.
>>>>
>>>> self.hardwareNotes = 'hw1'
>>>>
>>>> Regards
>>>> Ed Willink
>>>>
>>>>
>>>> Richard Catlin wrote:
>>>>> Further thoughts on this question:
>>>>>
>>>>> If I create a simple EClass called Architecture in Ecore with a
>>>>> property of "hardwareNotes", then when I generate the model, a
>>>>> setHardwareNotes(String name) method is generated. When I use the
>>>>> Interactive OCL Console, I get the following error:
>>>>>
>>>>> self.setHardwareNotes('hw1')
>>>>>
>>>>> Cannot find operation (setHardwareNotes(String)) for the type
>>>>> (Architecture)
>>>>>
>>>>> How can I go about setting this?
>>>>>
>>>>> Thank you,
>>>>> Richard
>>>>>
>>>>> On 8/4/2009 8:13 PM, Richard Catlin wrote:
>>>>>> All,
>>>>>>
>>>>>> I am using the EMF Framework Validation Plug-in: "OCL Example".
>>>>>> It allows me to write OCL expressions in a text file.
>>>>>>
>>>>>> Is it possible to set properties in the model based on OCL
>>>>>> expressions? The OCL 2.0 Spec says that expressions are
>>>>>> guaranteed to be without side effects, but then goes on to say
>>>>>> that OCL expressio can be used to specify a state change (eg. in a
>>>>>> post-condition).
>>>>>>
>>>>>> Pardon me if this is an obvious question. I am new to EMF and OCL.
>>>>>>
>>>>>> Thank you,
>>>>>> Richard Catlin
Previous Topic:OCL, AnyType and FeatureMaps
Next Topic:Re: OCL closures implementation
Goto Forum:
  


Current Time: Fri Mar 29 11:26:36 GMT 2024

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

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

Back to the top