The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)

10.2 Operations of the OclMessage Type

The OclMessage type, as explained in Section 10.1.5, has a number of operations. The operations defined for the OclMessage type are shown in Table 10-1.

Table 10-1. Message related operations on any OCL instance

Expression

Result Type

isSignalSent()

Boolean

isOperationCall()

Boolean

hasReturned()

Boolean

result()

Return type of called operation

10.2.1 The hasReturned and result Operations

Some messages have result values. A message representing a signal sent is by definition asynchronous, so there never is a return value. If there is a logical return value, it must be modeled as a separate signal message. However, an operation call has a potential return value, indicated by the return type in its signature.

In a postcondition, the return value of an operation call is accessible from an OclMessage instance. It is available only if the operation has already returned upon postcondition time. This is not always the case, because operation calls may be asynchronous.

Therefore, the OclMessage type has two operations: hasReturned and result . The hasReturned operation results in true if the operation call wrapped in the OclMessage instance has already finished executing and has returned a value. The result operation results in the return value of the called operation. For instance, in the model from Figure 10-1, if getMoney is an operation on class Company that returns a boolean, as in Company::getMoney(amount : Integer) : Boolean , we can write

context Person::giveSalary(amount : Integer) post: let message : OclMessage = company^^getMoney(amount)->any( true ) in message.hasReturned() and message.result() = true

Figure 10-1. Persons working for Companies , extended

If the hasReturned operation results in false, then the result operation will return undefined (see Section 10.6).

10.2.2 The isSignalCall and isOperationCall operations

Two other operations are defined on the OclMessage type. The isSignalCall and isOperationCall operations can be used to determine whether a message corresponds to an operation or to a signal. Both have a boolean result, and no parameters.

Категории