OCL stands for the Object Constraint Language. It is useful in MOF as a platform-independent way of specify operations and constraints. GMF can use OCL somewhat: GMF Troubleshooting 3. Also see: EMF Validation Framework

  1. A good OCL reference
  2. OCL Pygments Lexer

Sample OCL

self.parameter->operation(param)
self.child->isTypeOf(TypeName)
self <> self.child
self.one and self.two
not(self.name = '')

For OCL strings, they must be in single quotes. Double quotes (“) and backticks (`) do not work.

Sample OCL in .gmfmap

self.oclIsTypeOf(TypeName)

Using packages in OCL

I had an object, UserStore, which was in a separate package to the root. I was trying to use the following OCL constraint in my GMF .gmfmap:

self.oclIsTypeOf( DomainStore ) and not self.oclIsTypeOf( UserStore )

However, I was getting the following validation error:

Invalid expression body ‘…’. Cause: Unrecognized variable: (UserStore)

The problem is because the new type is in a separate package. The solution is to use the :: operator as a package separator, i.e.:

self.oclIsTypeOf( DomainStore ) and not self.oclIsTypeOf( users::UserStore )

eContainer in GMF OCL

GMF cannot support OCL with eContainer etc, until bug 256461 has been resolved. See: Having Multiple Containments of the Same Domain Element in GMF