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

OCL - iterate for each item

I have a class A with a collection of other classes (B). How do I represent in OCL that for each class (B) in the collection there's a constraint on a field ? I thought something like: A.collection->iterate().field = SomeConstraint
Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
1
vote
1 answer

OCL bond on operation between two classes

I have a class diagram and i need to write some OCL about it but i'm not sure about the right sintax. I've searched a lot but i've found a lot of different ways so i'd like to know if the way i'm going to write them is correct. For example, in my CD…
spx305
  • 109
  • 2
  • 11
1
vote
2 answers

OCL group by element attribute

In Acceleo I have an OrderedSet of objects, where each object has a string as attribute. I want to get a container(e.g. OrderedSet) of those strings, where each string is unique.
Borstenhorst
  • 1,716
  • 2
  • 13
  • 11
1
vote
1 answer

Use OCL for validation

I have a RDF dataset and a some OCL files which discribe the expected shape of the data. Is there a way verify the data with the OCL files with Jena?
1
vote
1 answer

How can I say that all elements in an array must have some property in OCL?

I have the following class: and I would like to express in OCL the following constraint: Every String in pre must either contain ('not' and one ' ') or contain no ' ' is it possible? How can I write it? Thank you!! P.s. By writing ' ' I mean a…
elena
  • 889
  • 2
  • 11
  • 19
1
vote
2 answers

Why is this ATL helper wrong?

I'm new to ATL and OCL and I'm trying to transform this metamodel: enter image description here into this one: enter image description here The helper is meant to take all the tests created by the user admin and after that sum the id's of the…
Mikel
  • 209
  • 2
  • 11
1
vote
1 answer

How to specify OCL constraint in activity diagram using Eclipse Papyrus?

Details I have an activity diagram for Login section designed in Eclipse Papyrus. Now I have to write OCL constraints for the following conditions: a username must be string and < 8 characters a password must be numeric+special chars and > 10…
discky
  • 7
  • 3
1
vote
1 answer

OCL allInstances()

At time i learning OCL a little and come across following question, which i coundn't find the right answer. I looked in the documentation on OCL 2.4 Spec, but i found nothing, that seem to answer my question: Mostly allInstances() examples are used…
user2680083
  • 125
  • 1
  • 2
  • 10
1
vote
0 answers

How to get context in opencv ocl?

I am trying to run my first program using OpenCV::ocl without success. I have an exception when calling cv::ocl::Context::getContext(): #include #include #include #include…
BrainabilGH
  • 464
  • 5
  • 15
1
vote
3 answers

Using OCL and UML with Design Patterns

Has anyone tried creating UML profiles for design patterns with stereotypes and OCL constraints? I'm trying to create one for the Singleton pattern but not sure how and where to start...
thesam18888
  • 19
  • 1
  • 2
1
vote
1 answer

OCL is it allow to write constraint on an operation and attribute

Imagine the following class Person ================ | Person | |--------------| |- name | |- age | |--------------| |+ drinkWater()| |+ drinkBeer() | ================ Using OCL, is it possible to set a constraint on the…
S12000
  • 3,345
  • 12
  • 35
  • 51
1
vote
3 answers

How to SortBy two parameters in OCL?

I need to sort the collection of Persons by two parameters, by Surnames and after by Names. How can I do something like this in OCL?
DM14
  • 188
  • 3
  • 13
1
vote
1 answer

How does OCL asSet work?

I have a question according to asSet/ asBag/ asSequence/ asOrderedSet. May I use it on a collection of collection. For example, I have (Sequence(Bag(Set(A)))), may I use these operations and what I will receive as a result, if it is possible. Or I…
DM14
  • 188
  • 3
  • 13
1
vote
2 answers

OCL-based model transformation languages

Which of the model transformation languages are ocl-based? Is Epsilon Transformation Language (ETL) ocl-based?
any
  • 325
  • 5
  • 17
1
vote
2 answers

Is it possible to use the same class in different OCL packages?

I would like to use OCL to link two class diagrams that represent the same model at two levels of abstraction. To illustrate, consider an abstract model A that contains a class Person that has a 'parents' association to itself. And a more concrete…
David Faitelson
  • 211
  • 2
  • 8