umloclmagic-draw

How to navigate through association class to create constraints with OCL?


I'm struggling to find a way to navigate through association class to create constraints

I checked on the specification here: https://www.omg.org/spec/OCL/About-OCL/

It's says: enter image description here

Let say I have this class diagram: enter image description here

And this object diagram: enter image description here

As you can see I created a constraint in the context of class A (just below the name of the class), I tried with lower "c" and upper "C", neither work...

Context A:
inv: self.C[b].val.mod(2) = 0

(The meaning of the constraint is not important, i just would like to make it work)

When I execute the validation process I get this error:

"Expression has errors: Semantic errors at [0:5]: Unrecognized variable: (C)"

This error message seems to be logic as I don't see an attribute "c" or "C" either in the object of type A, but I don't understand why it's that so.

Am I doing something wrong ? I don't understand why it doesn't work as I respected the syntax described in the specification.

For information: I use:

Thank you by advance !


Solution

  • You looking at a very dark corner. My first attempts at actually testing this functionality foundered on a failure to find a UML tool that could actually draw Fig 7.1. Once I got to grips with the text I realized there are many problems; a potential conflict between two different x[y] syntaxes, further aggravated by a QVTo shortform. There is a problem with extension to more than binary associations. The OCL Abstract Syntax continues to use the UML 1.x concepts of AssociationEnd rather than the UML 2.x Property.

    Consequently the functionality you observe is the result of the best endeavours of some tool vendor to make sense of a very inadequate specification.

    With MagicDraw, you used to be using Dresden OCL, but I understand that MagicDraw has switched to Eclipse OCL, perhaps the Classic Eclipse OCL. NoMagic seem remarkably reticent in crediting the open source software they redistribute.

    For the newer Pivot Eclipse OCL where I prototype solutions to many of the OMG OCL problems, the UML to Pivot loading normalises many of the UML concepts so that Associations are redundant, unless an exoplicit navigation to the Association requires an Association Class to be reified. AssociationClasses are normalized to Association Classes with ordinary Properties for each plausible navigation.

    I think that your expression is incorrect.

    self.C[b] cannot be a qualified association since the implicit A::C property has no key.

    self.C[b] could be a disambiguated navigation A::C where the ambiguity of A::C is resolved by selecting the C::b opposite. But A::C is not ambiguous and its opposite is C::a. So self.C should be adequate, self.C[a] is redundant, self.C[b] is wrong wrt the b. Sadly your tooling dislikes self.C so your tooling is defective.

    I think you should have written self.C.val.mod(2) = 0.

    Uppercase C is correct. Lowercase was misguidedly suggested by OCL <= 2.2 following the UML style guide. See indented paragraph under "Missing Association End names" in 7.5.4 of OCL 2.4.