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

Association classes effect to OCL operations in MDriven's new debugger

I noticed how the association class was automatically created simultanously when the classes which the association class depends on were added. That is of course how it should be. The problem with that, however, is that I'd normally go about like…
2
votes
0 answers

Eclipse with Papyrus OCL based JAVA code generation

I have created UML Class Diagram using Eclipse and Papyrus plugin. In separate file I have defined OCL constraints import 'model.uml' package Shop context Product inv PriceIsNotNegative: self.price > 0 endpackage I am trying to…
Daumantas Versockas
  • 797
  • 1
  • 10
  • 29
2
votes
1 answer

OCL conditions in usermodels

I am trying to use OCL conditions based on a ecore user model. My first question is whether it is even possible to use OCL conditions in this context or not. So in my special case the user is able to create an own model with its own tasks, sequence…
Braveness
  • 49
  • 7
2
votes
1 answer

Model OCL evaluation vs Object evaluation

I need to check if a model fires one or more OCL constraints. Models are stored in XMI, loaded with EMF. OCL constraints are generated automatically (String or the like). I found a way to check a constraint on an…
2
votes
1 answer

Using OCL for Date attributes

I have some models with date attributes and I want to include ocl for validation and derivation. Searching on the internet I found some articles and papers referring to date.isBefore(date) or date.before(date) methods but these methods are not…
Sergio Correa
  • 171
  • 1
  • 9
2
votes
1 answer

OCL Stereotype Constraint: Any association that is coloured all connected classes have the same colour

Quite new to OCL, thanks for the help. So I have a profile with the stereotypes as shown: Can someone tell me how to write an invariant constraint that says any association that is Coloured means that all connected classes must have the same colour…
bonapart3
  • 469
  • 7
  • 20
2
votes
2 answers

Define data type in OCL

How to define a new data type in OCL? (example - date) OCL already has pre-defined types (Integer, String, Real & Boolean). But how can I define a new data type? Example: I have a class call Person. Person class has following attributes, name :…
2
votes
2 answers

How to force Acceleo to iterate over a collection in the same order on every template execution?

I'm using an EMF model based on Modisco KDM metamodel. At some point of my Acceleo template I need to iterate over a collection, e.g.: [for (e: AbstractCodeElement | action.codeElement) separator(', ')][e.generateCode() /] The action.codeElement is…
andre
  • 349
  • 2
  • 13
2
votes
1 answer

Template classes with native UML types, and OCL constraints for template classes

I have two questions concerning the same UML class diagram. The first one is about how to model template class with UML native types. The second one is about how to handle template classes in OCL constraints. Question 1: template class I would like…
Bastien Pasdeloup
  • 1,089
  • 12
  • 19
2
votes
3 answers

Can an OCL Post condition be inside an if then statement?

I'm new to OCL and I have some doubts about how the pre and postconditions work. Can a post condition be placed inside an if then statement? For example, the following piece of code is valid or I'm just mixing concepts? Context [some context…
droca
  • 45
  • 3
  • 9
2
votes
1 answer

UML class diagram for string array

In UML how should we show a method which return string array in UML method that looks like this public String[] delete(int col, int row){} Is this representation correct? +delete(col: int; row: int): String[]
SuchZen
  • 57
  • 1
  • 1
  • 3
2
votes
2 answers

Can i add ocl to ecore with java code?

I want to add ocl to my .ecore metamodel with java code. But i cant find any example or tutorial. So i want to ask is tihs possible or where can i find sample codes?
gezgin
  • 207
  • 4
  • 10
2
votes
2 answers

Navigating UML associations in OCL

I'm trying to navigate UML associations in OCL, using the eclipse OCL implementation. I know that UML Associations are treated as Attributes, and the getAttributes() function called on a Class will return a set containing the Attributes as well as a…
user513418
2
votes
1 answer

Increment a variable inside a FOR loop

I'm trying to count how many times a condition is true inside a FOR loop. I declared an additional variable for the template (FOUND : Integer), and I'm trying to increment it every time the [IF] condition is "true", but the variable increments only…
AxA
  • 319
  • 5
  • 18
2
votes
1 answer

Test type of input parameter of a method in OCL

I have a class in UML that looks like this (it's in German, but I think it doesn't matter): The first method takes an array of 4 "Rohstoffkarte". That's an abstract class and I have 5 concrete sub-classes for it. Now I want to check (with OCL) that…
Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
1 2
3
11 12