The OCL Standard Library


This section describes the OCL Standard Library of predefined types, their operations, and predefined expression templates in the OCL. This section contains all standard types defined within OCL, including all the operations defined on those types. For each operation the signature and a description of the semantics is given. Within the description, the reserved word `result' is used to refer to the value that results from evaluating the operation. In several places, post conditions are used to describe properties of the result. When there is more than one postcondition, all postconditions must be true. A similar thing is true for multiple preconditions. If these are used, the operation is only defined if all preconditions evaluate to true.

11.1 Introduction

The structure, syntax and semantics of the OCL is defined in chapters 8 ("Abstract Syntax"), 9 ("Concrete Syntax") and 10 ("Semantics Described using UML"). This section adds another part to the OCL definition: a library of predefined types and operations. Any implementation of OCL must include this library package. This approach has also been taken by e.g. the Java definition, where the language definition and the standard libraries are both mandatory parts of the
complete language definition.

The OCL standard library defines a number of types, which are shown in Figure 28 on page 132. It includes several primitive types: Integer, Real, String and Boolean. These are familiar from many other languages. The second part of the standard library consists of the collection types. They are Bag, Set, Sequence and Collection, where Collection is an abstract type. Note that all types defined in the OCL standard library are instances of an abstract syntax class. The OCL
standard library exists at the modeling level, also referred to as the M1 level, where the abstract syntax is the metalevel or M2 level.

Next to definitions of types the OCL standard library defines a number of template expressions. Many operations defined on collections, map not on the abstract syntax metaclass ModelPropertyCallExp, but on the IteratorExp. For each of these a template expression that defines the name and format of the expression, is defined in Section 11.8 ("Predefined Iterator Expressions").