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.

159 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 …
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
  • 23
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
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
  • 4
  • 9
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
  • 3,894
  • 2
  • 28
  • 41
3
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
  • 191
  • 1
  • 8
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
  • 4,880
  • 1
  • 28
  • 63
3
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
  • 58,696
  • 38
  • 168
  • 301
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
  • 253
  • 3
  • 16
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
  • 4,902
  • 8
  • 53
  • 89
3
votes
2 answers

Is there a way to check the validity of a model in a programmatic manner such as Validation > Validate Model does?

Is there a way to check the validity of a model in a programmatic manner such as Validation > Validate Model does?
KMex
  • 71
  • 3
3
votes
3 answers

Translating ecore models (accompanying OCL expressions) to alloy specification

I am looking to see if there is any tool or engine which translates Ecore (meta-)models to Alloy specification? if it does this translation considering accompanying OCL expressions, it would be great :) Thx
qartal
  • 1,703
  • 15
  • 25
3
votes
1 answer

OCL constraints checking on Eclipse Papyrus

Does anyone manage to check OCL constraints on a class diagram modeled in Eclipse Papyrus ? I have definied a simple test profile with only one constraint on a stereotype attribute : {OCL} self.property > 0 The stereotype extends the Property…
Vincent
  • 638
  • 10
  • 21
1
2 3
10 11