Visual OCL

TU-Berlin | Faculty IV | Institute ISTI | Research group TFS

User Guide for the Eclipse VOCL-Plugin
goup 1

small logo
section: < previous | next >
| |
chapter: << previous | next >>


4.1 Navigation Expressions

In this chapter, we will evolve some examples of navigation expressions. A navigation forms a path, beginning at a classifier-role, going along on associations and ending up at attributes, methods or at classifiers, if no association from there will lead to other ones. Cycles will also cause the path to end, so that in every navigation, each contained classifier-role appears at most twice, if it is the start- and endpoint. Usually, they appear only once. The starting point of the navigation is given by that classifier-role, which implements the context of the constraint, i.e. has the same type and reference name (or the reference name self, if the constaint has none) as defined in the constraint.
When discussing the examples, the detailed editing steps for creating them will not be discussed again, because nearly all elements used here are introduced so far. However, the examples will be compared to the corresponding OCL-Syntax, which will be generated by the ocl-converter. This should help to demonstrate the semantic of the given diagrams.

a) Attribute Navigation

The fist navigation expression discussed is shown in fig. 4.1.1. It consists of a constraint, in which only one classifier-role is located, which is also the context of the constraint, because reference name (c) and type (Company) are the same like those defined in the constraint. Inside the classifier is an attribute named name, which has a constant value of GMC of type String.
This constraint forms one of the most simple expressions available in VOCL. The OCL-Syntax is quite simple as well. To create it, first add a constraint as invariant (context is a classifier), with the name Example-1, the context Company and the variable of the context c. Now, add the classifier-role to this constraint with same type and reference name. Then add an attribute with name name, value GMC and type String via the Properties-dialog. After creating and saving the diagram, click the OCL-Converter-Button from the Toolbar (see fig. 4.1.2), to create the corresponding ocl-string, which is displayed on a dialog (see fig. 4.1.3).

Fig. 4.1.1 - Example 1: Attribute Navigation


Fig. 4.1.2 - Toolbar-Button of the OCL-Converter


Fig. 4.1.3 - Resulting OCL-Expression

b) Attribute Navigation with Condition

Using attribute navigation with constant values only allows to create comparisons of equality. When an attributes value should be greater or smaller than another given value, a condition would be the adequate element to express it.
The next example extends the previous one with the new attribute profitPerYear for the classifier, which type is Integer, and the value is another variable called x. The variable x then is compared in a condition with a constant value. It should be greater than 1.000.0000 ($). The resulting constraint is displayed in figure 4.1.4.
To create it, extend the previous diagram with a new attribute for the given classifier. Name the attribute profitPerYear, deselect the is value-check-box and name the variable x with type Integer. Next, create a condition (via the context-menu of the constraint). Choose the >-operator, on the left side, refer to the variable of the attribute by entering the name and the type, on the right enter the value (1000000). Then click again the OCL-Converter-Button, to see, what the resulting OCL-String looks like. Note, that the result consists of two expression, the one defined in the previous example, and the new one, both connected with an and.

Fig. 4.1.4 - Example 2: Attribute Navigation with Condition


Fig. 4.1.5 - Resulting OCL-Expression

c) Navigation along associations

Since navigation is not limited to attributes, the next example will provide a diagram, where associations come into play. Therefor, new classifier-roles have to be added. As you can see in fig. 4.1.6, the previous example was again extended, this time with two classifiers of type Person and connecting associations. The direction of an association is important, because it determines the direction of the navigation path. Navigation starts always at the unnamed association end, and goes to the named side. In this example, the navigation begins again at the classifier of the context. Then, two navigations along associations are possible, one to the manager and one to employee (names of the association ends). When following the manager-navigation, no more expansions of the actual path are possible, but from the employee, the next association will lead to the chef of the employee, which is also the manager of the company. These two navigation-paths form a constraint, as you can see in the resulting OCL-String in fig. 4.1.7. Note, that the expansion of all possible navigation paths forms a graph. Traversing it is one of the main tasks of the ocl-converter.

Fig. 4.1.6 - Example 3: Navigation along associations


Fig. 4.1.7 - Resulting OCL-Expression

d) A complex example

The next example provides some other aspects, involving a method and a collection classifier-role (see fig. 4.1.8). The method getProfit() provides as the result a varaible called profit, whose type is Integer. Navigating from the Company to the set of employees, and calculating the sum of all salaries, a new variable named cost is defined (and also the variable y, which is needed for adding up). These two variables then are compared in a condition, expression that the profit should be greater than the costs, what indeed is a very useful constraint. The OCL-Converter is up to now not able to extract the correct corresponding OCL-String, so that it is not shown here.


Fig. 4.1.8 - Example 4: A more complex navigation expression

 


  section: < previous | next >
| |
chapter: << previous | next >>
©2005 TFS