Page 1 of 1

OCL - Default Value limits check

PostPosted: Tue Mar 13, 2018 5:42 pm
by cardwellj
I'm trying to figure out how to best apply an OCL constraint that checks to make sure the default value assigned to a constraint parameter input is within a valid lower and upper bound. I created a custom stereotype that is a generalization of a ConstraintParameter with two additional attributes called "Valid Lower Limit" and "Valid Upper Limit". The OCL expression "Valid_Upper_Limit > Valid_Upper_Limit" produces an expected Boolean response (true/false) based on the assigned values. However the OCL expression "defaultValue > Valid_Lower_Limit" does not evaluate.

I reviewed the comments from another post (see url below) and I believe the issue has to do with the UML primitive value types, but I'm not sure how to correct it. When I compare the custom attributes, which both are typed by a SysML "Real" type, the OCL expression evaluates. I tried to apply the solution in the post below to my own situation but was unsuccessful. I would like to understand the syntax of that solution and if/how I can apply it for my situation. I have provided a sample model.

Re: OCL - Default Value limits check

PostPosted: Thu Mar 15, 2018 8:25 am
by rimvydas.vaidelis
You expression should be:

Code: Select all
defaultValue.oclAsType(LiteralInteger).value > Valid_Lower_Limit

Note: the constraint must have validationRule stereotype in order to work as a validation rule.

Re: OCL - Default Value limits check

PostPosted: Thu Mar 15, 2018 9:08 am
by cardwellj
Thanks. That did it (using LiteralReal instead of LiteralInteger). I'm very new to OCL and was having a hard time navigating the syntax. From reading the OCL specification, I think this was a type conformance error. Is there a way to see what OCL types the expression is receiving? I typed the stereotype attributes as Real (SysML primitiveValueType), but I'm not sure how that translates in OCL. The Value specification for the default value is "Literal Real" so I'm not sure what the OCL expression is doing or why it's doing it. The No Magic Documentation for OCL is sparse at best and there aren't a lot of great tutorials online. Any additional insight you could provide would be beneficial.

Re: OCL - Default Value limits check

PostPosted: Tue Jul 14, 2020 10:26 am
I know this is an old post, but I want to bump this up again. I too would like to know if there is a way to see what "type" I'm getting out of "self.oclIsTypeOf(...)", and more broadly a debugging mechanism of some kind. The error "Can not evaluate OCL" doesn't help me fix it.

Re: OCL - Default Value limits check

PostPosted: Mon Jul 27, 2020 2:17 am
by marlel

There is no real "debug", but you can do the expression evaluation "Tools->Expression Evaluation" and see the result