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
0
votes
1 answer

OCL: Specify pre and postconditions for constructor and destructor

Hi I'm new to OCL and was wondering if the following can be done using OCL: check if certain conditions hold before an object can be created specify operations that must be performed after an object is destructed If yes, can we achieve this by…
snow
  • 47
  • 3
0
votes
1 answer

How to make a Group by in OCL?

I have an association between Person and Department, and I want to check if Person.function is unique Person.allInstances->isUnique(function) but I want to check if function is unique for Persons in the same department and not between all persons.…
0
votes
2 answers

How to implement OCL (Object Constraint Language) in Python

I am working on Google Colaboratory, and I have to implement OCL (Object Constraint Language), I searched a lot, but I didn't find how to implement it. Can someone give me an idea please?
0
votes
1 answer

Enable many to many (cardinality) in ATL model2model transformation

I am trying to achieve an M2M transformation using ATL. So I am transforming a source model (1) to target model (2), I am very new to ATL and I can't find any documentation on how to enable many to many transformations. What I am trying to do…
0
votes
2 answers

How to express tree structure constraints

How can the following constraints be expressed: 1 - There is exactly one folder that is not a sub-directory to another directory. (I couldn't fully understand the folder/subfolder theme and how to describe the only one possible exclusion from the…
HollySeater
  • 25
  • 1
  • 7
0
votes
1 answer

How to validate java.util.Date attribute in ocl?

I'm trying to add validation for date type in emf.ecore 2.23 as following examples invariant validation1: self.startDate.before(self.terminationDate); or invariant validation2: self.startDate < self.terminationDate; Using this…
0
votes
2 answers

How to generate code from ecore model with OCL expressions in the separate file?

I'm using Eclipse addon to work with OCL. I have an Ecore model with some operations and derived attributes also I have a separate OCL file with expressions in it. I made a genmodel file and added:
0
votes
1 answer

How much does Enterprise Architect support OCL language?

http://wp13117963.server-he.de/blog/2007/01/15/ocl-support-in-enterprise-architect/comment-page-1/#comment-2035 I am facing an issue mentioned in the above article. i.e. Enterprise Architect is not giving any error when I create a constraint on an…
0
votes
1 answer

get an element index in ocl collection ? [ocl_Eclipse]

i'm working on the following domain : my domain diagram i want to express the folowing constraint : " a succession of two actions of Type Rotate is not allowed " i tried this declaration but eclipse is not recognizing indexOf(element ) : class…
Marwa
  • 1
0
votes
1 answer

Count the occurrences of a boolean operation

I have to make an OCL rule saying that two parameters cannot be equal. I cannot use the not() so I have to show that something like param1 = param2 is empty. I tried to use isEmpty() and size() but as it's boolean, these operators don't…
0
votes
1 answer

Setting context and inv in interactive OCL console

I am using the Eclipse Interactive OCL console to test the OCL examples from this document. For testing, the example(Tutorial.xmi) provided with the link is used. The tried expressions are given…
FaisalM
  • 724
  • 5
  • 18
0
votes
1 answer

Setting OCL context

I am trying to change the OCL context from the Java application. The present context is root node. ARPackage is a node under the root node and I am trying to set the context to this node. Sample code is given below. public void…
FaisalM
  • 724
  • 5
  • 18
0
votes
1 answer

Question about OCL invariants on a diagram

I'm new to OCL and currently trying to figure out how to do invariants. I attached a picture with the diagramm I'm working on. https://i.stack.imgur.com/daQQN.jpg The invariants that I'm trying to resolve are : a) A player has 0 or 2 cards in…
0
votes
1 answer

OCL restrictions and derivations rules

I'm working with this UML model do you know how I could obtain the Film with adult content that only can be sale to Customer that have over 18?. I tried this expression: context Film inv: self.adultContent->notEmpty () implies self.Customer.age…
0
votes
2 answers

ocl constraint with recursive class

For a little bit of context: a Class can have other Class as Requirement to be taken by a student. The Class is taken by a Student via a ClassGroup which can be ordered in time with its attribute sessionYear. I want to put an OCL invariable…
Takyon
  • 59
  • 6