2

Hi there we´re currently working with MagicDraw 17.0. and we got the following problem. We would like to validate whether an object in an object diagram has any connected objects.

For example if an object "man" has a link to another object "address". Atm. we´re trying this

self.address->isEmpty() 

where address is the role of the adressobject in the association that connects the two objects and the constraint is put on man. Doesn´t work.

Sled
  • 18,541
  • 27
  • 119
  • 168

2 Answers2

1

This is not directly an answer to your question, but hopefully would provide more insight regarding the question you are asking:

if an object (say an instance of Man) has no link (say address) to another object (say instance of Address), traversing self.address with self being a Man, would be undefined at all for the self! (Note that address is a reference and Address is a type).

It seems that oclIsUndefined() operation can be used for this purpose (as gefei mentioned), So probably self.address -> oclIsUndefined() would work for you!

Page 16 of the OCL specification says:

... there is an explicit operation for testing if the value of an expression is undefined. oclIsUndefined() is an operation on OclAny that results in True if its argument is null or invalid and False otherwise.

But there is another perspective:

self.address represents a collection. So isEmpty function should return true if it is empty! (This is the way you probably think to come to using self.address->isEmpty)

Page 175 of the OCL specification regarding isEmpty function says:

isEmpty() : Boolean

Is self the empty collection?

  post: result = (self->size() = 0 ) 

Note: null->isEmpty() returns 'true' in virtue of the implicit casting from null to Bag{}

But as you mentioned isEmpty was not working for you!

I am leaving this to OCL experts to comment the difference? But probably the first approach would help!

Hope this helps!

qartal
  • 2,024
  • 19
  • 31
0

try oclIsUndefined() (see OCL Specification 2.3.1 p.16)

gefei
  • 18,922
  • 9
  • 50
  • 67
  • I tried to follow your suggestion but I always ended up with "`NXO non-executable`" errors when invoking it on `self` or `OclAny`. Could you give a full example? The specs do not illustrate the use of `oclIsUndefined()` very clearly. I get that "OclAny is the sole instance of AnyType" and that you would pass the property (`self.address`) as the only parameter of `oclIsUndefined()`. On what entity do you invoke that operation? – observer Jan 29 '13 at 13:28
  • this is not valid for empty string. if you delete the value, the string is not undefined, but empty, so you have to try something with the size greater than zero, or something – Helder Pereira Oct 11 '22 at 19:45