|
Re: OCL Association Constraint [message #1456143 is a reply to message #1455768] |
Thu, 30 October 2014 04:07 |
Mahin Abbasipour Messages: 24 Registered: June 2013 |
Junior Member |
|
|
Hi,
I don't know what is wrong with "Test1::ST1". Others may help you with that. But If you want to specify the end members of an association meta class, you can write this:
self.base_Association->collect(e|e.endType().getAppliedStereotypes()->asSequence()->at(1).name)->includes('ST1')
and
self.base_Association->collect(e|e.endType().getAppliedStereotypes()->asSequence()->at(1).name)->includes('ST2')
Also, you made an assumption that the member ends first and last (i.e. at(1), at(2)) are in order which is not usually the case.
Instead of using "includes" twice, I tried the constraint below, but didn't work for me, which again I don't know the reason:
self.base_Association->collect(e|e.endType().getAppliedStereotypes()->asSequence()->at(1).name)->includesAll(Set{'ST1','ST2'})
A question that I have, Is how you will navigate with association metaclass (i.e. testLink) to write other OCLs? for example, ST1 has Attribute1 and ST2 has Attribute2 both from type of Real. You want to be sure that the value of Attribute1 is less than Attribute2. Can we do that really with meta class Associations? How about the time we need to navigate from multiple associations? This seems complicated to me.
|
|
|
Re: OCL Association Constraint [message #1456865 is a reply to message #1456143] |
Thu, 30 October 2014 20:19 |
Rishi Kanth Messages: 18 Registered: October 2014 |
Junior Member |
|
|
Hi,
Thanks. You example, helped me to figure out the right way. Furthermore, the new LUNA with OCL Console is very useful. I have used the following constraint for my purpose:
self.base_Association.endType.getAppliedStereotypes()->asSequence().name->includesAll(Set{'ST1','ST2'})
But here is the interesting thing I have found. There were two ways, I have defined the OCL constrains.
1. I have used "Constraint" node from the designed Palette in Papyrus and associated "Contextual Link" to the respective stereotype. I defined the OCL constraint in the "Constraint" box and saved the profile.
2. I have defined a .ocl file using "OCL->Complete OCL File" (OCL 5.0.2) and placed it in the profile along with (.di, .notation and .uml). I have moved the OCL constraints into the .ocl file.
When I validate the model, option 1 works fine, but option 2 does'not.
Do I have to do anything specific when dealing with .ocl and papyrus (profile and class diagram).
Thanks,
|
|
|
Re: OCL Association Constraint [message #1456873 is a reply to message #1455768] |
Thu, 30 October 2014 20:25 |
|
Hi,
The oclIsTypeOf operation tests that a model element's metaclass is
exactly the argument. Stereotypes are not metaclasses, so your
expressions don't make sense.
You navigated the context stereotype's metaclass extension to access
the association; you need to do similarly for the member-end
properties. Something like this (not tested by me) may work:
self.base_Association.memberEnd->at(1).extension_ST1->notEmpty()
and
self.base_Association.memberEnd->at(2).extension_ST2->notEmpty()
HTH,
Christian
On 2014-10-29 18:43:01 +0000, Rishi Kanth said:
> Hi,
>
> I am relatively new to OCL and its application to UML Profiles. I have
> created a simpled profile with two stereotypes ST1 and ST2 that extend
> metaclass UML Class and one stereotypes testLink that extends metaclass
> Association. In this profile, I have created the following constraint
>
> self.base_Association.memberEnd->at(1).oclIsTypeOf(profile::Test1::ST1)
> and
> self.base_Association.memberEnd->at(2).oclIsTypeOf(profile::Test1::ST2)
>
> When I save the profile, I also check the options to save the OCL
> constraints with the profile. I am using Kepler and Papyrus (0.10.2).
> In the windows Preferences->OCL, I have selected /ECore/OCL/Pivot.
> When I apply the profile to an UML Class diagram (two classes and one
> association, applied with stereotypes) and validate the application, I
> have the following error
>
>
> Severity Description Element Parent Type
> Error An exception occurred while delegating evaluation of the
> 'Constraint1' invariant on 'Test Link -> <<testLink>> <Association>
> myassocication': Errors in '
> self.base_Association.memberEnd->at(1).oclIsTypeOf(profile::Test1::ST1)
> and
> self.base_Association.memberEnd->at(2).oclIsTypeOf(profile::Test1::ST2)'
> 2: Unresolved Property
> 'profile::Test2::http://www.eclipse.org/uml2/2.0.0/UML::Test2::testLink::base_Association'
>
> 2: Ambiguous resolution:
> Property : uml::Association.memberEnd
> Property : UML::Association.memberEnd
> 2: Unresolved Operation 'Set(OclInvalid)::at(UnlimitedNatural)'
> 4: Unresolved Property
> 'profile::Test2::http://www.eclipse.org/uml2/2.0.0/UML::Test2::testLink::base_Association'
>
> 4: Ambiguous resolution:
> Property : uml::Association.memberEnd
> Property : UML::Association.memberEnd
> 4: Unresolved Operation 'Set(OclInvalid)::at(UnlimitedNatural)'
> <<testLink>> <Association> class1_class2_1 model EMF Problem
>
>
>
> Thanks
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04070 seconds