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 constraint on collection size

draw of my situation In the link above, we can see the class Student and Class. I want to make an invariant constraint to make sure a Student can't register for more than 5 classes each sessionYear. With this constraint, I can determine if Student…
Takyon
  • 59
  • 6
0
votes
1 answer

What is the correct interpretation for a number of OCL expressions that use "Shorthand for Collect"?

Given the following UML model: I am struggling with the correct interpretation of some OCL expressions (all in context of class "City"). The version of OCL I'm working with is OCL 2.3.1 (though if OCL 2.4 is more suited for answering my question,…
jechterhoff
  • 175
  • 2
  • 9
0
votes
1 answer

Calculation in OCL with if else and notEmpty()

I am trying to get this calculation to work in OCL, it has to say that if there is a cancelation present, it should give 'geannuleerd' and if there is a betaaldatum present it should give 'definitief'. My question is: I need for this if-else-then…
0
votes
2 answers

Acceleo - Reference to another model

I am facing a problem and I am kind of desesperate : I am trying to transform a constraint OCL into a C# program. To do so, I define my ocl constraints in a CompleteOCL document, and I save it as Abstract Syntax : POC.ocl.oclas. Then I use Acceleo…
Flora
  • 1
  • 1
0
votes
1 answer

How to write a recursive OCL query with mixed classifiers?

I've got an EMF metamodel as described below: class Application - runsOn: Host [0..*] interface Host class VirtualMachine implements Host - runsOn: Host [0..*] class PhysicalMachine implements Host The question I want to answer using OCL is:…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
0
votes
1 answer

Parameters for parsing OCL Parsing in JAVA

I'm working on a java application that takes as input a set of valid models and a set of invalid models, OCL constraints are generated automatically, my objective is to check if the models are violating the constraints or no. I found on this topic…
0
votes
2 answers

UML constraint across three associations?

Let's say I have class A with associations to classes X, Y, and Z, respectively. I need to indicate that only one of these associations may be instantiated for any given instance of class A (so, an xor constraint). I know how to do this if the…
Huliax
  • 1,489
  • 3
  • 15
  • 27
0
votes
1 answer

Layering derived objects in Papyrus by OCL

Being new to UML/OCL/Papyrus the lack of exchange about this gives me a feeling I might be on the wrong path: Working on a class diagramm I would like to layer a) all objects that are members of a composition and b) all interfaces that inherit from…
lambu0815
  • 311
  • 1
  • 2
  • 9
0
votes
2 answers

OCL constraint on a UML profile in Rational Software Architect 8

I'm new to Rational Software Architect 8 and OCL. I defined a profile that consists of two stereotypes, one applied to a class and another one applied to an association. See the figure for more detail. Now, I'd like to express a constraint using…
user513418
0
votes
1 answer

OCL write constraint on an operation of class A and attribute of class B

Follwing another post: I would like to know if OCL allows the following. Imagine the following UML diagram. How to use ocl to model: "a person can drinkWater() only if he is from country name 'ABCD'" AND if the population of the country is >=…
S12000
  • 3,345
  • 12
  • 35
  • 51
0
votes
1 answer

How to integrate OCL constraints to a model created with Eclipse Sirius?

Its difficult to give more details as I haven't even found a clue in OBEO Designer Community to model OCL constraints. Anyone has a idea how to do this? Thanks
Florian Reisinger
  • 2,638
  • 4
  • 23
  • 34
0
votes
1 answer

OCL : from AST to concrete syntax

Evrything is in the title : I have an OCL AST (with as root an org.eclipse.ocl.ecore.Constraint) which I have modified. I would like to parse it again, but I only find the "one-line OCL grammar" that you get when printing a constraint (or any OCL…
0
votes
0 answers

OCL - get value of variable

How can I get the value of variable instead of its name? The below code return "n" string which is the name of the variable. I need value of n. s.targets.first().name.name The Metamodel
any
  • 325
  • 5
  • 17
0
votes
1 answer

OCL - calling rule

What does the below code do? How can I write this OCL expression when there is one element instead of elements? In other words, I don't understand which elements does the code collect? Since "collect" is used when we have more than one element, if I…
any
  • 325
  • 5
  • 17
0
votes
1 answer

create model instance provider class in eclipse

how can I create model instance provider class in eclipse?
sonya
  • 1
  • 1