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

Constraints on extended stereotype in UML profile

Suppose you have an excerpt of a larger profile for cars: Now i want to define some constraints for a Car, say one of those constraints states, that if attrA is true, then attrB must be false like this using OCL: Context UML::Core::Class inv: self …
Tilman Zuckmantel
  • 643
  • 1
  • 6
  • 18
4
votes
1 answer

How to navigate through association class to create constraints with OCL?

I'm struggling to find a way to navigate through association class to create constraints I checked on the specification here: https://www.omg.org/spec/OCL/About-OCL/ It's says: Let say I have this class diagram: And this object diagram: As you…
Aliz
  • 736
  • 1
  • 11
  • 25
4
votes
2 answers

Can derived attributes be persisted and derivation disabled in Ecore and OCL?

I want to port a legacy data format, which consists of concepts similar to Eclipse Modeling Framework (EMF) Ecore: Elements with Parameters which have different datatypes and default values. A custom-made tool lets you edit such model instances by a…
Hauke
  • 134
  • 10
4
votes
0 answers

OCL (Object Constraint Language) select, use sum for attribute

I'm trying to find an OCL excpression (calculator), but I'm not sure how to get the sum of the attributes of a collection. I have a class Customer and a class Orders. I want to have the sum of all orders of a particular year saved in the Customer…
Maaike
  • 321
  • 2
  • 10
4
votes
4 answers

Has anyone used UML with OCL? Do programmers use it or only analysts who don't code?

I am trying to wrap my head around why we first approach the problem of design and decide upon a visual method (UML), instead of starting with formal specifications that happen to also be executable (RAD prototyping), we start with diagrams that…
Warren P
  • 65,725
  • 40
  • 181
  • 316
4
votes
2 answers

Linking opencv nonfree components (SIFT features and OCL specifically)

I am having trouble compiling some code after a OS upgrade (Ubuntu 12.04 to 14.04) and a re-install of opencv. The general issue is with the "nonfree" parts of opencv which I compiled from source using the following procedure: mkdir ~/OpenCV && cd…
ianrust
  • 91
  • 1
  • 5
4
votes
2 answers

Parse OCL in Java?

I am writing a Java program for a course that takes a UML class diagram, which is a metamodel, as input and allows the user to create diagrams of the type specified in the metamodel. The user should then be able to model instances of what this…
JSFernandes
  • 188
  • 3
  • 9
3
votes
3 answers

UML constraint {xor} between two associations

I am currently struggeling with contraints in UML. Considering the following example: The class A have an association to the class B and an association to the class C. Both associations are bidirectional. The Class A can have exactly one instance of…
Balburus
  • 33
  • 4
3
votes
1 answer

Validate OCL attributes of my model using Eclipse papyrus

I'm making a translation model on Magicdraw/Cameo between two metamodels, using several metamodels in its environment. This model contains OCL expressions, and I would like to use Eclipse to check the syntax of the OCL expressions of my model (I…
Kaly
  • 51
  • 3
3
votes
2 answers

OCL at0 operator syntax error

Working on a timereport project in MDriven and I have created an instance where an employee has worked ten hours. The Employee class's "attribute.type" is of "timespan" for "HoursWorked". action: Employee.create Employee.allinstances->at0(0)…
Gustaf
  • 147
  • 5
3
votes
1 answer

Check if string is a number

================ | Person | |--------------| |- id : String | |--------------| ================ I have class Person with property id that is String type. I have to check that id is a number that contains 11 digits. I thinking about something…
ulou
  • 5,542
  • 5
  • 37
  • 47
3
votes
1 answer

Using hashCat with a RAR file?

I'm pretty stumped, is it actually possible to use hashcat for a RAR file? The forum says "yes" and points to a sample... They appear to be calling: ./oclHashcat64.bin -m 12500 hash -w 3 -a 3 ha?l?l?l?l?l So far, so good.. So I go grab jtr and run…
XeroxDucati
  • 5,130
  • 2
  • 37
  • 66
3
votes
0 answers

Java, EMF + OCL Diagnotician can't handle duplicate id

i have an EMF model where some objects contain IDs, and others don't. The id attribute is configured like this: I use the java Diagnostician to check if any of the OCL Constraints are violated: protected Diagnostic validateModel(EObject modelRoot)…
Simon Eismann
  • 273
  • 1
  • 5
  • 17
3
votes
3 answers

Translate SQL to OCL?

I have a piece of SQL that I want to translate to OCL. I'm not good at SQL so I want to increase maintainability by this. We are using Interbase 2009, Delphi 2007 with Bold and modeldriven development. Now my hope is that someone here both speaks…
Roland Bengtsson
  • 5,058
  • 9
  • 58
  • 99
3
votes
1 answer

Can UML with OCL be used for formal specifications?

I am asking because UML is used for informal specifications and has some ambiguities in its semantics. However OCL can be used to specify pre/post conditions and invariants and other constraints quite efficiently I think. I encountered the Z…
Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
1
2 3
11 12