Using 'if' in OCL
CapableObjects Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Using 'if' in OCL Expand / Collapse
Author
Message
Posted 2008-12-09 17:42:38
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 2010-08-12 17:32:24
Posts: 51, Visits: 600
Hi

How do I use an 'if' statment in an ocl expression for a derived attribute

What I'm trying to do is

if (self.ParentType.isNull) then

self.Name

else

self.ParentType.Name + ' - ' + self.Name

Thanks

Nick

Post #1389
Posted 2008-12-09 17:50:03
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2012-01-23 17:45:58
Posts: 49, Visits: 72
if ... then ... else ... endif
Post #1390
Posted 2008-12-09 17:54:58
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 2010-08-12 17:32:24
Posts: 51, Visits: 600
Thanks

I'm at a clients so I don't have your book to hand

Nick

Post #1391
Posted 2008-12-10 13:39:09
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230, Visits: 1 382

if ParentType is an association then
use ->isEmpty to check for null
else
use ->IsNull
endif


:-) /* the above is not syntactically correct OCL */

"->isEmpty" can be used with both single and multi links (0..1 and 0..*), ".isNull" should only be used for attributes (it happens to work for singlelinks too, but more by accident than by design).


/Jonas Hogstrom [CapableObjects]
Post #1395
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: HansKarlsen, Jonas Hogstrom, PeterMorris

Permissions Expand / Collapse

All times are GMT +1:00, Time now is 12:07

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0,313. 9 queries. Compression Disabled.