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
2 answers

Acceleo M2T - Write timestamp into a generated file

I am generating some files by using different Acceleo templates defined into a *.mtl file. At the top op these files I need to write something like: #----------------------------------------------------------------------------- # Project…
pedromateo
  • 2,965
  • 1
  • 18
  • 19
0
votes
1 answer

allInstances of an Associations in OCL

How can I access all instances of an association with an OCL expression. Suppose I have an association name in a variable named refName, which is the name of an association from class A to class B. For a given instance of A (say a) how can I access…
qartal
  • 2,024
  • 19
  • 31
0
votes
1 answer

UML aggregation in OCL

UML Diagram for given problem I have been given a task to create pre and post conditions for an operation: getInformation(givenTitle:String):Integer The operation should return a number of all bug reports for a project of a specified title. As for…
Wunsz
  • 165
  • 3
  • 7
0
votes
2 answers

OCL define invariant

If I have to define an invariant to state that the age of a person requesting a loan should be greater than 18 for the attached class diagram would this be context Person inv: age > 18 or context Person inv: self.age > 18 and what is the…
CompilerSaysNo
  • 415
  • 3
  • 14
0
votes
3 answers

OCL: Check for multiple Associations

I have a student class that has two associations: Graduate and Undergraduate. I am trying to create an invariant that makes sure no student is associated with both. I am very new to OCL and do not know the approach to this or syntax. I am thinking I…
Cassus
  • 199
  • 6
  • 14
0
votes
2 answers

avoid duplicates in a Ecore containment relation

I have an Ecore metamodel. The node Peer has a containment relation 0..* called "in" with the node Message. I want that all the messages contained by the Peer, have different names. So a Peer can not have two messages with the same name. …
DeLac
  • 1,068
  • 13
  • 43
0
votes
1 answer

OCL 2.0 constraint to check if a Key-Value pair is present in the Hashtable

How to write a OCL constraint to check if a particular Key-Value pair is always present in a HashTable using iterate feature in OCL? I am a beginner in OCL. Any hints or example would be helpful.
0
votes
6 answers

Why allInstance not for isUnique?

I have a class Client with attribute noClient, I wan to verify there is no client with the same noClient. I have the solution below, but the teacher said its not appropriate. Because the contraint may be repeated. I don't know why. And I need to…
Kim
  • 41
  • 4
0
votes
1 answer

What is a *package* in OCL?

I know how to write a package in OCL but what exactly is the meaning of this construct? Why and when do we have to use packages? As an example for a package in my script they write package MeetingExample context Meeting::isConfirmed :…
stg
  • 2,757
  • 2
  • 28
  • 55
0
votes
1 answer

Importing eclipse MDT/OCL APIs in qvt-o code

In a model transformation I have native OCL query as string and I need to parse that OCL string and execute it in order to identify and select specific model element in the source model. Is it possible to import eclipse MDT/OCL API in qvt-o code?…
0
votes
1 answer

Follow linked list in OCL

I use Bold for Delphi that has an implementation of OCL. OCL is good at filtering lists, etc. But I have not found a good, generic way of traversing linked lists. Suppose I have a class PlanMission. It contains a single link PlanMission.previous…
Roland Bengtsson
  • 5,058
  • 9
  • 58
  • 99
0
votes
2 answers

Dresden OCL Load Constraints

I am trying to learn Dresden Ocl. When I try to Generate AspectJ Constraint Code. I am getting the following error The selected model does not contain any constraint. Please load constraints first. Please let me know what is the issue here.…
Josh
  • 249
  • 3
  • 11
0
votes
1 answer

How do I use counting related instances instead of attributes in OCL

For example say if I had a library and a precondition of issuing a book to a borrower was that it can only be issued if it is not reference only and is not already on loan to someone else, I could say: context Copy::issue() : Boolean pre:…
James
  • 161
  • 1
  • 8
0
votes
1 answer

OCL verify value in parameter

Class Game Method: addPlayer(param Player) I would like to create an invariant for my method addPlayer so it verifies that parameter Player exists. Example: context Game::addPlayer(pl:Player) inv pl->exists( p : Player | p.playerID =…
gogasca
  • 9,283
  • 6
  • 80
  • 125
0
votes
0 answers

ocl-facedetect sample of opencv 2.4.6.1

![enter image description here][1]On Ubuntu 12.04 LTS with NVidia GeForce 8 series GPU card, I am trying to run the ocl-facedetect sample of OpenCV 2.4.6.1 and seeing following error: $./ocl-example-facedetect -t haarcascade_frontalface_alt.xml -i…
arm
  • 117
  • 1
  • 3
  • 10
1 2 3
11
12