Questions tagged [ocl]

A formal specification language used with MOF meta-models (including UML) to express queries or constraints that cannot otherwise be expressed in diagramic notation.

The object constraint language (OCL) can be used to define invariants, queries, pre- and postconditions for MOF meta-models (including UML models). It allows a user to specify constraints on models, which can not be specified by the graphical notation of the UML.

OCL itself is a side-effect free, typed language based on first-order logic.

Invariants are defined for a context, typically a class. The following invariant states, that all person names should be unique:

context Person inv namesUnique:
  Person.allInstances->forAll(p|self.name=p2.name implies self=p2)

Note, that OCL provides the built in operation allInstances() to access all instances of a class.

Pre- and postconditions are specified in the context of an operation. In a post condition the special operator @pre can be used to access the values of variables, ettributes, etc. before an operation was called. Also, the special variable result can be used to access the result of the operation call.

The following conditions could be specified for an operation pop():OclAny of a Stack:

pop():OclAny
  pre  self.size > 0
  post self.size = self.size@pre - 1
  post result = self.elements@pre->last()

Beside constraint definition, OCL is used as a query language in model transformation approaches like QVT.

Further information about OCL can be found on the websites of the OCL workshop or the OCL Portal.

180 questions
2
votes
2 answers

OCL 2.0 Constraints

Hi there we´re currently working with MagicDraw 17.0. and we got the following problem. We would like to validate whether an object in an object diagram has any connected objects. For example if an object "man" has a link to another object…
2
votes
2 answers

OCLinEcore and Regex to create valid IPv4 string

I have an Ecore model, where I'm trying to add some OCL constraints. My problem comes when I try to make a property (a string) that is in valid IPv4 form. I guess I should use a regular expression, but I have no idea at all about how to use regex…
Mario Corchero
  • 5,257
  • 5
  • 33
  • 59
1
vote
1 answer

Reverse an OrderedSet in an Eclipse Modeling Framework Model via OCL

I have a UML model (which is actually irrelevant as it could be any MOF model) with an ordered set I need to access from the last to the first element. I thus need to reverse it through OCL. I have seen there is the sortedBy method that needs an…
Andrea Sindico
  • 7,358
  • 6
  • 47
  • 84
1
vote
1 answer

How can I add OCL restriction to the class variable?

I'm implementing a Composite design pattern to which a need to add OCL restriction. This is a snippet of a code I'm using. public abstract class ComplexTerritory implements ITerritory { private List territories = new…
Aleksa Majkic
  • 632
  • 5
  • 17
1
vote
2 answers

How do I find a UML object if I only know the value of one of its attributes in OCL?

I have a UML class Student that has an attribute id. I want to write a query in OCL to find a particular Student by only knowing its id. Should I use allInstances()? Or derive? I'm not very familiar with OCL.
tofana
  • 83
  • 1
  • 5
1
vote
1 answer

Get ocl string attribute length

I need to check an string attribute length and I don't know what function I have to use, size() maybe? Context Myclass inv:self.string_attribute->size() <7
user18727693
1
vote
1 answer

Understanding the semantics of some OCL operands

I am having a bit of troubles trying to understand the semantics of OCL operands in the OCL specification of version 2.4. In particular, to begin with, given a contextual model as a Student class, in which the available attributes is his age, then…
HoaNg
  • 25
  • 2
1
vote
1 answer

Beginner's question on OCL and derived attributes

I just recently started to look deeper into the intricacies of OCL. During my first applications, the following question came up: Is it possible, and if so, what is the correct way to derive an attribute in case that no value is provided? Approaches…
BMH_H20
  • 13
  • 2
1
vote
1 answer

OCL - Doubts about UML constraints and Complete OCL file in Papyrus

I want to evaluate constraints in both UML class diagram and Complete OCL file. I searched but I only found examples where the methods are in the same class. Below is an example of an UML diagram class about which I have the following…
1
vote
1 answer

Papyrus - OCL constraint to verified property

My class has 2 properties (String) that are two types of people's document numbers. To verify if the documents has valid numbers, a calculation is realized (verifiers digits). Below an example how is realized a consistensy of one of them: Number:…
1
vote
1 answer

BPMN with OCL or other Constraints Language

I am looking for (the) BPMN definition in terms of xmi and complete MOF files, also including OCL (constraints). Does this exist? I found only a couple of OCL-statements in the files. In contrast to that, the Superstructure.xmi of the UML (see…
user10017556
1
vote
3 answers

How to implement the Luhn alorithm in OCL

I am trying to find the Luhn algorithm in OCL to check the validity of ISIN. Can anyone provide a code example would it be great!
1
vote
1 answer

One-to-many association constraint in ocl

I am new in ocl and I am stuck in a problem. I had built an UML class diagram for a school and I want to create an association that connects one teacher from class Teachers to many students from class Students. My problem not with creating the…
NewProg
  • 13
  • 2
1
vote
1 answer

The relation between Class Diagrams and OCL

I know the following: OCL is a constraint language that to specify constraints on my class diagram models I know, that in the OMG world for class diagrams there are 3 levels of models: M1 (model), M2 (meta-mode), M3 (meta-meta model) M3: defines…
JennyDong
  • 9
  • 3
1
vote
1 answer

OCL collection operation on list attribute

I'm modelling a problem in which there are students and courses. Each courses have some other courses as prerequisites and I want to make an OCL constraint on the "joinCourse()" operation of students to allow them to join a courses if and only if…
artas
  • 148
  • 1
  • 3
  • 12