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

Using OCL in Maven/Tycho-surefire

I am trying to run a eclipse plugin test that uses OCL, more specifically: Diagnostic diagnostic = Diagnostician.INSTANCE.validate(modelRoot); Which works fine if i run it as rightclick -> run as ... -> Eclipse Plugin Test But if i try to run it…
Simon Eismann
  • 273
  • 1
  • 5
  • 17
1
vote
1 answer

Is it possible to express constraint on the tagged value of an applied stereotype in UML/OCL?

For example, let's consider the following UML diagram: The model has to be valid only if for all of the instances of Block1, the instance of Block1::unit_of_press is the same instance of the tagged value unit of the actual type of Block1::press Is…
Irr
  • 656
  • 1
  • 9
  • 19
1
vote
1 answer

How to possibly do this in ocl?

I have the following schema: For the Boss class, I need the name of all the agents who made the sales with the highest value (something like: foreach agent, select agent name if he has max(foreach command, total = total + price of the product *…
Simply Me
  • 1,579
  • 11
  • 23
1
vote
1 answer

Started to learn UML and OCL and when to use Inv, pre, post

So, I started learning OCL about 3 hours ago. I'm very confused about when you can use inv and when you need to use pre and post. So I was wondering whether you can use inv in a situation like this? context Service :: cost(d : double) inv result…
Neo Streets
  • 525
  • 1
  • 7
  • 15
1
vote
1 answer

Use a Map data structure in OCL

how can i use a Map in OCL. For example i want to get all bills for user c1 and my Map 'purchases' looks like Map . c1.purchases.Bill? Is this possible? regards
1thingtodo
  • 95
  • 2
  • 15
1
vote
2 answers

Nested OCL forAlls

I have the following Formula in First Order Logic. forAll a:A | forAll b :B | if a.r1=b then a.r2=b simply, for all objects of type A, and for all objects of type B, if they are related by r1 then they are related by r2 as well. Here is the Class…
qartal
  • 2,024
  • 19
  • 31
1
vote
1 answer

EMF/UML and OCL API for Scala

A part of an application I am developing in Scala needs to read and parse EMF/UML models along with OCL expressions defined over these models. My OCL expressions are pretty much query expression defined over these EMT/UML models. My Questions: 1)…
qartal
  • 2,024
  • 19
  • 31
1
vote
1 answer

How to attach OCL to UML-Profiles

I want to define some constraints for my profile. For example I need a constraint for a stereotype of the metaclass "connector". I want to define that these element must have one source like the oclkindof(source) and one target like the…
MFY
  • 11
  • 2
1
vote
1 answer

oclHashcat SHA256 Line Length Exception

I am running this command in my Windows cmd: oclHashcat.exe -m 1400 hash.txt My hash is: $5$JLj/jsZd$hOjXUxfucZeTUYE/MB2WMnY75/Cty8V9Z8/sslogefB I keep getting an error "Line-Length exception" and I am not sure why.
1
vote
1 answer

Programmatically execute an OCL query on a UML model

Can anyone provide an example of how to programmatically execute an OCL query on a UML model using Eclipse MDT/OCL implementation. I read the Eclipse documentation, but still could not find a working example and I keep getting different exceptions…
1
vote
1 answer

OCL constraint to force strings not to be empty

I have a class diagram with numerous classes, some of them containing attributes of type string. I want all my strings to be of length at least 1. The easy (yet ugly) solution is as follows: context Class1 inv: self.attributeOfTypeString.size >…
Bastien Pasdeloup
  • 1,089
  • 12
  • 19
1
vote
2 answers

Validate xmi model using OCL in Java

I am trying to create a stand alone Java application that accepts an xmi model and an OCL file containing constraints applied to the model's meta-model. The application then validates the model against the ocl. I have managed to do this inside…
robinjohnobrien
  • 1,092
  • 2
  • 11
  • 19
1
vote
1 answer

Finding nested duplicates in OCL

I am facing a challenge when trying to check for duplicates in OCL. Here is a simplification of the class diagram: +-----------+ |ChapterName| …
whirlwin
  • 16,044
  • 17
  • 67
  • 98
1
vote
4 answers

OCL: How can I write pre and postconditions for the operation max to find the maximum value from a collection?

I am trying to write pre and post conditions to find the maximum value of a collection 'col'. I'm not really sure how to go about it, recursively so I was wondering if someone could help! pre: true post: result = ...
mark
  • 2,841
  • 4
  • 25
  • 23
1
vote
1 answer

Recursion in OCL

Let suppose I have this class diagram in UML: How can I do, in OCL, to specify that an instance of A is not included in list_of_As recursively ? In other words, an instance of A may not be included in A.list_of_As and not be included in all…
Julien Mellerin
  • 412
  • 4
  • 13