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))
- Code: Select all
self.owner.ownedElement->select(e| e.oclIsTypeOf(ProxyPort) and e <> self )
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.