OCL Validation Rules

General discussions about MagicDraw

Moderator: Moderators

OCL Validation Rules

Postby ida-electra.dahl@samares-engineering.com » Thu Feb 18, 2021 3:03 am

Hello,
I'm having trouble writing certain custom OCL 2.0 validation rules, concerning proxy ports.
The first rule I'm having trouble with is this: I want to ensure that all the proxy ports on each block are typed by a different interface. I want the two (or more) ports that are identical to be highlighted (not the block itself), so I have the "proxy port" stereotype as the constrained element, and I have written the following rule:
Code: Select all
self.owner.ownedElement->select(e| e.oclIsTypeOf(ProxyPort) and e <> self )->forall(p | (p.oclAsType(ProxyPort).type <> self.type))
However, it cannot be evaluated. apparently, "type" is an unknown variable. However, if I write simply "self.type", this evaluates to the interface block with no problem at all. The first part of the rule
Code: Select all
self.owner.ownedElement->select(e| e.oclIsTypeOf(ProxyPort) and e <> self )
evaluates without problem. I do not understand why, in the last part of the rule, the "type" is unknown, even after casting "p" as a proxy port (which should not be necessary, seeing as the first part already filters strictly on proxy ports). If anyone could help me figure out how to write this rule, that would be much appreciated!

Secondly, I want to write a rule where I need to know the direction of the port. However, "self.direction" returns an enumeration literal, and "self.direction.name" does not evaluate, even though "in" or "out" is the name of the enumeration literal. I would want to obtain the name as a string in order to be able to compare it, but it seems that I cannot. Is this a bug? Or is there some other way for me to obtain the direction of the port as a string? Or maybe some other way for me compare the obtained enumeration literal with one of the SysML defined ones, so see if it is the same one? I tried comparing "self.direction" to the qualified name of the SysML defined enumeration literal, but that did not work either, possibly beacause of the "&" in "ports&flows", which is part of the qualified name.

Any help on these rules is very much appreciated! As currently I'm stumped.
ida-electra.dahl@samares-engineering.com
Forum Newbie
Forum Newbie
 
Posts: 9
Posts Rating:0
Joined: Fri Apr 05, 2019 3:14 am

Return to MagicDraw

Who is online

Users browsing this forum: No registered users and 1 guest