Search code examples
umloclpapyrus

OCL - Doubts about UML constraints and Complete OCL file in Papyrus


I want to evaluate constraints in both UML class diagram and Complete OCL file. I searched but I only found examples where the methods are in the same class. Below is an example of an UML diagram class about which I have the following questions:

enter image description here

  1. Using Papyrus, how to set in diagram the Collection types (Bag, Set, etc.), since they are not available in the input and return argument types selection window ? It's available only for Ecore (EEList, EMap)

enter image description here

  1. How to define Context and Operations (parameters/arguments), since both are in other class, according class diagram above ?

  2. How to navigate between both classes in OCL complete file ?

  3. Does the OCL Complete file allow the use of commands: def, let, if-then-else, etc. ?

Thanks in advance.


Solution

  • UML does not support Collections or Maps. Rather it has multiplicities and qualified associations. For the usual common cases it is sufficient to specify an unlimited upper bound, and unique and ordered polarities to configure the UML multiplicity of a Bag/OrderedSet/Sequence/Set for OCL.

    UML supports templates but OMG OCL does not, although OMG OCL is aligned to UML. Rather OMG OCL has magic "T" and "T1" types that looks remarkably like template parameters without being defined as such. The Pivot-based Eclipse OCL that prototypes solutions to many OMG OCL problems implements templates and so allows a UML user to define a DataType property whose type templates the relevant collection/map type from the Eclipse OCL Standard Library.

    For flat collections using the library type is just an alternative approach. For nested collections, that UML does not support, using the DataType to define all or all but one levels of nesting is the only option.

    (Papyrus uses the Pivot-based Eclipse OCL.)

    Complete OCL should work normally; UML multiplicities are converted to/interpreted as OCL collection types. In the Pivot-based Eclipse OCL there is a legacy syntax that uses () to reference e.g. Set(MyClass) but a novel/familiar <> to declare e.g. MyAggregate<E>.