Home » Modeling » OCL » OCL to constrain the use of an association
OCL to constrain the use of an association [message #42875] |
Mon, 05 November 2007 19:37 |
Eclipse User |
|
|
|
Originally posted by: bastian.merches.web.de
Hello,
I've modeled an UML-Profile with a stereotype <<employs>>, which extends
UML Association, and a stereotype <<hierarchy>>, which extends UML Class.
Now I want to make sure, that the <<employs>> Association is only used
to connect <<hierarchy>> Elements.
I used OCL to write the constraints into the <<employs>> stereotype:
self.endType[0].stereotype.name='Hierarchy'
self.endType[1].stereotype.name='Hierarchy'
But when I try to validate a model I get the following error message:
Non-executabe:Semantic error::Violation of wellformedness rule:
Qualified navigation is not allowed if referred association end has no
qualifiers.
I don't know what it means.
How can I do this with OCL?
Thanks for your help!
Regards,
Bastian
|
|
|
Re: OCL to constrain the use of an association [message #42906 is a reply to message #42875] |
Mon, 05 November 2007 20:33 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Bastian,
Which OCL implementation are you using? I don't recognize the text of the
error message that you quoted.
However, the problem that you are confusing Java's array-indexing syntax
with OCL's collection-indexing. In OCL, [...] is used to specify qualifier
values for traversal of qualified associations. e.g.,
class Bank
property account[0..*] : Account
qualifier id : String
class Account
bank : Bank
can then do OCL constraints such as
context Bank
inv: self.account['00-0000-000'].oclIsUndefined()
to stipulate that an account with ID '00-0000-000' must not exist.
For your situation, you want something more like:
self.endType->at(0).stereotype.name='Hierarchy'
self.endType->at(1).stereotype.name='Hierarchy'
or, even better,
self.endType->forAll(stereotype.name='Hierarchy')
Of course, this is forgetting even that 'stereotype' is not a property of
the UML Element metaclass. In UML 2.x, you need to navigate metaclass
extensions:
self.endType->forAll(not extension_Hierarchy.oclIsUndefined())
HTH,
Christian
Bastian Merches wrote:
> Hello,
> I've modeled an UML-Profile with a stereotype <<employs>>, which extends
> UML Association, and a stereotype <<hierarchy>>, which extends UML Class.
>
> Now I want to make sure, that the <<employs>> Association is only used
> to connect <<hierarchy>> Elements.
>
> I used OCL to write the constraints into the <<employs>> stereotype:
> self.endType[0].stereotype.name='Hierarchy'
> self.endType[1].stereotype.name='Hierarchy'
>
> But when I try to validate a model I get the following error message:
> Non-executabe:Semantic error::Violation of wellformedness rule:
> Qualified navigation is not allowed if referred association end has no
> qualifiers.
>
> I don't know what it means.
>
> How can I do this with OCL?
>
> Thanks for your help!
>
>
> Regards,
> Bastian
|
|
|
Re: OCL to constrain the use of an association [message #42937 is a reply to message #42906] |
Mon, 05 November 2007 21:17 |
Eclipse User |
|
|
|
Originally posted by: bastian.merches.web.de
Thanks for the quick response.
I'm going to try this.
I'm using OCL 2.0 within MagicDraw 12.0 Enterprise.
Unfortunatelly I'm very unexperienced in using OCL. I've got the
..stereotype notation from the MagicDraw Manual.
Thank you for the comprehensive description!
Christian W. Damus schrieb:
> Hi, Bastian,
>
> Which OCL implementation are you using? I don't recognize the text of the
> error message that you quoted.
>
> However, the problem that you are confusing Java's array-indexing syntax
> with OCL's collection-indexing. In OCL, [...] is used to specify qualifier
> values for traversal of qualified associations. e.g.,
>
> class Bank
> property account[0..*] : Account
> qualifier id : String
> class Account
> bank : Bank
>
> can then do OCL constraints such as
>
> context Bank
> inv: self.account['00-0000-000'].oclIsUndefined()
>
> to stipulate that an account with ID '00-0000-000' must not exist.
>
> For your situation, you want something more like:
>
> self.endType->at(0).stereotype.name='Hierarchy'
> self.endType->at(1).stereotype.name='Hierarchy'
>
> or, even better,
>
> self.endType->forAll(stereotype.name='Hierarchy')
>
> Of course, this is forgetting even that 'stereotype' is not a property of
> the UML Element metaclass. In UML 2.x, you need to navigate metaclass
> extensions:
>
> self.endType->forAll(not extension_Hierarchy.oclIsUndefined())
>
> HTH,
>
> Christian
>
>
> Bastian Merches wrote:
>
>> Hello,
>> I've modeled an UML-Profile with a stereotype <<employs>>, which extends
>> UML Association, and a stereotype <<hierarchy>>, which extends UML Class.
>>
>> Now I want to make sure, that the <<employs>> Association is only used
>> to connect <<hierarchy>> Elements.
>>
>> I used OCL to write the constraints into the <<employs>> stereotype:
>> self.endType[0].stereotype.name='Hierarchy'
>> self.endType[1].stereotype.name='Hierarchy'
>>
>> But when I try to validate a model I get the following error message:
>> Non-executabe:Semantic error::Violation of wellformedness rule:
>> Qualified navigation is not allowed if referred association end has no
>> qualifiers.
>>
>> I don't know what it means.
>>
>> How can I do this with OCL?
>>
>> Thanks for your help!
>>
>>
>> Regards,
>> Bastian
>
|
|
|
Re: OCL to constrain the use of an association [message #43191 is a reply to message #42937] |
Thu, 08 November 2007 16:02 |
Eclipse User |
|
|
|
Originally posted by: bastian.merches.web.de
Hello,
I tried it and it didn't work because of special notation in MagicDraw.
Correct notation is:
self.endType->forAll(et| et.oclIsKindOf(hierarchy))
Thanks anyway!
Bastian Merches schrieb:
> Thanks for the quick response.
>
> I'm going to try this.
> I'm using OCL 2.0 within MagicDraw 12.0 Enterprise.
> Unfortunatelly I'm very unexperienced in using OCL. I've got the
> .stereotype notation from the MagicDraw Manual.
> Thank you for the comprehensive description!
>
>
>
>
> Christian W. Damus schrieb:
>> Hi, Bastian,
>>
>> Which OCL implementation are you using? I don't recognize the text of
>> the
>> error message that you quoted.
>>
>> However, the problem that you are confusing Java's array-indexing syntax
>> with OCL's collection-indexing. In OCL, [...] is used to specify
>> qualifier
>> values for traversal of qualified associations. e.g.,
>>
>> class Bank
>> property account[0..*] : Account
>> qualifier id : String
>> class Account
>> bank : Bank
>>
>> can then do OCL constraints such as
>>
>> context Bank
>> inv: self.account['00-0000-000'].oclIsUndefined()
>>
>> to stipulate that an account with ID '00-0000-000' must not exist.
>>
>> For your situation, you want something more like:
>>
>> self.endType->at(0).stereotype.name='Hierarchy'
>> self.endType->at(1).stereotype.name='Hierarchy'
>>
>> or, even better,
>>
>> self.endType->forAll(stereotype.name='Hierarchy')
>>
>> Of course, this is forgetting even that 'stereotype' is not a property of
>> the UML Element metaclass. In UML 2.x, you need to navigate metaclass
>> extensions:
>>
>> self.endType->forAll(not extension_Hierarchy.oclIsUndefined())
>>
>> HTH,
>>
>> Christian
>>
>>
>> Bastian Merches wrote:
>>
>>> Hello,
>>> I've modeled an UML-Profile with a stereotype <<employs>>, which extends
>>> UML Association, and a stereotype <<hierarchy>>, which extends UML
>>> Class.
>>>
>>> Now I want to make sure, that the <<employs>> Association is only used
>>> to connect <<hierarchy>> Elements.
>>>
>>> I used OCL to write the constraints into the <<employs>> stereotype:
>>> self.endType[0].stereotype.name='Hierarchy'
>>> self.endType[1].stereotype.name='Hierarchy'
>>>
>>> But when I try to validate a model I get the following error message:
>>> Non-executabe:Semantic error::Violation of wellformedness rule:
>>> Qualified navigation is not allowed if referred association end has no
>>> qualifiers.
>>>
>>> I don't know what it means.
>>>
>>> How can I do this with OCL?
>>>
>>> Thanks for your help!
>>>
>>>
>>> Regards,
>>> Bastian
>>
|
|
|
Re: OCL to constrain the use of an association [message #43224 is a reply to message #43191] |
Thu, 08 November 2007 17:14 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Bastian,
Wow, so the semantics of stereotyping in this implementation of UML is
specialization, not extension? (the stereotyped element is a dynamically
generated metaclass specializing both the base metaclass and the
stereotype). Interesting.
cW
Bastian Merches wrote:
> Hello,
> I tried it and it didn't work because of special notation in MagicDraw.
> Correct notation is:
>
> self.endType->forAll(et| et.oclIsKindOf(hierarchy))
>
> Thanks anyway!
>
-----8<-----
|
|
|
Goto Forum:
Current Time: Fri Apr 19 15:19:08 GMT 2024
Powered by FUDForum. Page generated in 0.02169 seconds
|