I'm developing an Ecore model with some invariants defined in OCL, using the OCLinEcore editor. In my model, some elements have references to EClassifier; in some OCL constraints, I need to check if the EClassifier referred to is an EDataType or an EClass. Here is, in OCLinEcore, a model similar to the one I have:
import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';
package Foo : foo = 'some_namespace'
{
class EndPoint
{
attribute name : String[1];
property type : ecore::EClassifier[1];
}
class Coupling
{
invariant Compatibility:
(destination.type.oclIsKindOf(ecore::EDataType) and source.type = destination.type) or
let destinationClass : ecore::EClass = destination.type.oclAsType(ecore::EClass) in
destinationClass.isSuperTypeOf(source.type.oclAsType(ecore::EClass));
property source : EndPoint[1];
property destination : EndPoint[1];
}
}
However, when I try to validate a dynamic instance of my model, an exception occur with the following message:
An exception occured while delegating evaluation of the 'Compatibility' constraint on 'Coupling': Unknow type ([ecore, EDataType])
When I try the expression in the OCL interactive console, I obtain the correct result. Am I doing something wrong when defining my invariant? How can I write an invariant that uses Ecore types?
Edward Willink gave me an explanation and a workaround on the OCL forum: