OCL for Systems Traceability

The object constraint language (OCL) is used to configure a semantic browser or a pattern breakpoint.

For more information about:

This page discusses:

OCL Top-Level Declarations

A navigation specification is composed of a list of statements. It ends with a semicolon.

Statement Description
Description

Declares a description text displayed at the top of the preview.

Syntax:

description [ html ] STRING ;

Example 1: simple text description

description
'Semantic Browser Exemple';

Example 2: rich text description, using HTML

description html
"Semantic <b>Browser</b>
<i>Exemple</i>";

Namespace

Declares a namespace prefix for a URL. These prefixes can be used to form OCL property names.

Syntax:

namespace PREFIX_NAME = URL ;

Example:

namespace dc =
http://purl.org/dc/terms/;

Navigation

Declares a navigation expression. It can optionally declare:

  • A Boolean condition indicating when this navigation is applicable
  • A predicate to be used for declaring the results as statements when using the 'in context' mode

Syntax:

navigation NAME { condition EXPRESSION | predicate URL} : EXPRESSION ;

Example 1:

navigation children
    self->collect(e|e.syc:treeChild);

Example 2:

navigation children
    condition self.rdf:type='http://www.3ds.com/vocabularies/syc/type/Enovia.Requirement%20Specification'
    predicate syc:semantic/child
    self->collect(e|e.syc:treeChild);

OCL Function Definition

You can define OCL functions to be called within the navigation expressions, to simplify your script by factorizing commonly used expressions in functions.

Syntax

Syntax for a function definition:

helper <function name> ( <parameter list> ) : <expression> ;

For example, the following function returns the list of children of its parameter o:

helper children(o): o.dc:hasPart;

Call

Function calls are done using the C-style call syntax.

For example, this navigation is described using the previously defined children function:

navigation nav: children(this);

Note: You do not have to declare functions before the location of their call.

Supported OCL Subset

Supported Description
Syntactic constructs
  • if then else endif
  • let in
Types
  • Primitives types:
    String Integer Boolean RdfResource
    Note: RdfResource is the general object type
  • Supported collection types:
    Set OrderedSet Bag Sequence
Operators and functions
  • Primitive types operators:
    + - * div mod not(b) or and implies = <> < <= > >=
  • Primitive types functions:
    e.toString()
  • Collection functions:
    c->isEmpty() c->notEmpty() c->size() c->first() c->last() c->at(i) c->union(c2) c->intersection(c2) c->flatten()
    c->includes(e) c->includesAll(c2)
    c->asSet() c->asOrderedSet() c->asSequence() c->asBag()
  • Collection iterative expressions:
    iterate collect collectNested select reject forAll exists any closure sortedBy
Collection literal
  • Collection literals: Set, OrderedSet, Bag, Sequence. Example:
    Set{'strawberry', 'apple', 'orange'}
  • Intervals in collection literals.

    Example:

    Sequence{1..10}

Tuple Example:
Tuple {name: 'Joe', id: 21255 }
String
  • s.size()
  • s.characters()
  • s.toUpperCase()
  • s.toLowerCase()
  • s.toInteger()
  • s.at(i)
  • s.indexOf(s2)
  • s.substring(start, end)
  • self.trim()
Not Supported Description
Implicit context

The following is not permitted in this OCL implementation:

  • Dropping the keyword self when accessing properties.

    Example: self.name cannot be abbreviated name.

  • Similar abbreviations are not permitted in iterations. The loop variable cannot be omitted.

    Example: collection->collect(e|e.name) cannot be abbreviated collection.collect(name).

Added OCL Extensions

These extensions are added to the OCL language implementation for the semantic browser and pattern.

OCL Extension Description
Object Properties

In standard OCL, object properties are simple identifiers. For example, the property name of an object that is referenced by the obj variable can be accessed with the following expression:

obj.name

In this implementation, the navigation language is able to deal with properties coming from RDF statements. For this, the syntax allows the use of prefixed URIs as property identifiers, using a colon character ( : ) as a separator between a prefix (declared with a namespace declaration) and a short URI. For example the statement dc:title of an object referenced by the variable obj can be accessed with the following expression:

obj.dc:title

Another syntactic extension has been introduced to allow navigating statements in the opposite direction. By prefixing the property with a tilde character ( ~ ), it is possible to navigate from an object to the subjects that point to it. For example, the parents of an object that is referenced by the variable obj can be accessed with the following expression, which reverses the navigation of the syc:treeChild property:

obj.~syc:treeChild

first() Function

In standard OCL, first() is defined only for ordered types. In this implementation, it has been extended to support the unordered collection types.

collection->first( is equivalent to collection->any(e|true).

It returns the first element encountered during the iteration of the collection.

Regular Expression

This implementation of OCL supports regular expressions. A pattern literal can be defined by enclosing the pattern between two /, for example:

/[0-9]+/
The syntax of the pattern conforms to Java regex syntax.

The following functions apply to regular expressions:

  • re.split(s) Splits the string s using the pattern re.
  • re.test(s) Tests if the string s matches exactly the pattern re.
  • re.match(s) Returns the list of substrings of s that match the pattern re.
  • re.matchCapture(s) Similar to match(), but also captures the regions specified in the pattern using parenthesis. Example:
    /IR-([0-9]+)/.matchCapture('(IR-56777) + [IR-78822] cf IR-45698')
    returns
    { { 'IR-56777' '56777' } { 'IR-78822' '78822' } { 'IR-45698' '45698' } }

resource() Function

resource(s) returns the resource identified by its identifier string s

Tracing operator !

The postfix operator ! can be used when debugging OCL navigation. It can be placed after a variable name to indicate that the value of the variable must be written in the log report during execution.

Example: in the following expression, the value of variable e is logged each time it is accessed:

navigation titles:
           self.syc:treeChild->collect(e | e!.dc:title);

It is also possible to trace the result of an expression. In some cases, the expression must be enclosed within parentheses.

Example: this computes the sum x+y+z and logs the value of x+y:

(x + y)! + z