Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » null as value in OCL?
null as value in OCL? [message #45753] Mon, 03 December 2007 20:51 Go to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
I have an OCL semantics question.

How do I treat cases, where I want to return "null"?



And as a second question:
What is the result of

a.b

and

a.b.c

if "a" already results in oclUndefined?

Best Regards, Philipp
Re: null as value in OCL? [message #45783 is a reply to message #45753] Tue, 04 December 2007 14:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Philipp,

OCL has a keyword for the literal null value (the "instance" of OclVoid):

null

So, null can be returned as a value for expressions of any type except a
Collection type, in which case an empty collection is more appropriate.
e.g.,

context Person
def: employerName : String =
if
self.employers->notEmpty()
then
self.employers->any(true).name
else
null
endif

Doing simply "self.employers->any(true).name" would result in OclInvalid
(see below) instead of null if there were no employers.

In your second question, if the value of a is null, then

a.b

results in OclInvalid (the singleton valud of the Invalid type, indicating
failed evaluation) and

a.b.c

also results in OclInvalid, as accessing features of OclInvalid is not
allowed, except to ask for .oclIsUndefined() or .oclIsInvalid().

HTH,

Christian


Philipp W. Kutter wrote:

> I have an OCL semantics question.
>
> How do I treat cases, where I want to return "null"?
>
>
>
> And as a second question:
> What is the result of
>
> a.b
>
> and
>
> a.b.c
>
> if "a" already results in oclUndefined?
>
> Best Regards, Philipp
Re: null as value in OCL? [message #46209 is a reply to message #45783] Mon, 10 December 2007 09:35 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Hi, Christian.
This was very useful.

Thus I assume it is better to write

a = null

instead of

a.oclIsUndefined()

since the second would as well be true, if a is invalid.

Best Regards, Philipp



Christian W. Damus wrote:
> Hi, Philipp,
>
> OCL has a keyword for the literal null value (the "instance" of OclVoid):
>
> null
>
> So, null can be returned as a value for expressions of any type except a
> Collection type, in which case an empty collection is more appropriate.
> e.g.,
>
> context Person
> def: employerName : String =
> if
> self.employers->notEmpty()
> then
> self.employers->any(true).name
> else
> null
> endif
>
> Doing simply "self.employers->any(true).name" would result in OclInvalid
> (see below) instead of null if there were no employers.
>
> In your second question, if the value of a is null, then
>
> a.b
>
> results in OclInvalid (the singleton valud of the Invalid type, indicating
> failed evaluation) and
>
> a.b.c
>
> also results in OclInvalid, as accessing features of OclInvalid is not
> allowed, except to ask for .oclIsUndefined() or .oclIsInvalid().
>
> HTH,
>
> Christian
>
>
> Philipp W. Kutter wrote:
>
>> I have an OCL semantics question.
>>
>> How do I treat cases, where I want to return "null"?
>>
>>
>>
>> And as a second question:
>> What is the result of
>>
>> a.b
>>
>> and
>>
>> a.b.c


>>
>> if "a" already results in oclUndefined?
>>
>> Best Regards, Philipp
>
Re: null as value in OCL? [message #46269 is a reply to message #46209] Mon, 10 December 2007 13:13 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Philipp,

Yes, you raise a very good point. I can imagine that there might be cases
where this is an important distinction to make. Although, I'm not sure how
often that would arise. It's a bit like trying to account in your Java API
design for possible programming errors in client code (as signalled by
run-time exceptions); not usually worth the trouble.

Testing specifically for null might result in an attempt to use an
OclInvalid, unless you also test for a.oclIsInvalid().

cW

Philipp W. Kutter wrote:

> Hi, Christian.
> This was very useful.
>
> Thus I assume it is better to write
>
> a = null
>
> instead of
>
> a.oclIsUndefined()
>
> since the second would as well be true, if a is invalid.
>
> Best Regards, Philipp

-----8<-----
Previous Topic:[Announce] MDT OCL 1.2.0 I200712061132 is available
Next Topic:java.lang.ClassCircularityError: myPackage/ValidationDelegateClientSelector
Goto Forum:
  


Current Time: Thu Apr 25 16:34:42 GMT 2024

Powered by FUDForum. Page generated in 0.04221 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top