OCL - Comparing Integers

Other topics that do not fit in any of categories.

Moderator: Moderators

Re: OCL - Comparing Integers

Postby nadka123 » Mon Oct 13, 2014 7:04 am

I have to use Integer type from the SysML profile. Why is there a difference between the UML and SysML profiles of Integer? Is there a way that I can convert from SysML to UML integer within the code so I don't have to re-stereotype my items?
nadka123
Forum Expert
Forum Expert
 
Posts: 143
Posts Rating:0
Joined: Sun Jan 26, 2014 10:56 am

Re: OCL - Comparing Integers

Postby rimvydas.vaidelis » Tue Oct 14, 2014 2:20 am

UML Integer and SysML Integer are different types and they are incompatible. You can't convert SysML Integer to UML Integer.
Integer from UML profile has the comparison operations. Other profiles can have a classifier named Integer but this does not mean that it will be treated as an Integer from UML profile. At the moment MD supports primitive types from other profiles only. A PrimitiveType with a name Integer in a custom profile will be treated as an Integer from the UML profile. In this case OCL expression self.rangeBegin <= self.rangeEnd would be valid (types of rangeBegin and rangeEnd should be myProfile::Integer).
However, the Integer from the SysML profile is not a primitive type. It is a DataType with the stereotype ValueType and it has no support from MD OCL engine. So in order to compare Integers from the SysML profile you have to use the following OCL expression:
Code: Select all
self.appliedStereotypeInstance.slot -> select(definingFeature.name='rangeBegin') -> asSequence() -> first().value -> first().oclAsType(LiteralInteger).value <=
self.appliedStereotypeInstance.slot -> select(definingFeature.name='rangeEnd') -> asSequence() -> first().value -> first().oclAsType(LiteralInteger).value
rimvydas.vaidelis
Customer Support
Customer Support
 
Posts: 262
Posts Rating:14
Joined: Fri May 28, 2010 4:45 am

Previous

Return to Other

Who is online

Users browsing this forum: No registered users and 1 guest