0
votes

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?

1

1 Answers

1
votes

Edward Willink gave me an explanation and a workaround on the OCL forum:

Naked OCL does not support the binding of ecore to something useful, so the oclAsType(ecore::EClass) has an unresolved reference since each ecxpression is an independent snippet in the ECore file.

The Juno release therefore adds an extension whereby a package qualifier may be a URI, so that if you saw the above serialized it might be oclAsType(_'http://www.eclipse.org/emf/2002/Ecore'::ecore::EClass).

The Juno release also adds flexibility as to whether you use the new Pivot-binding with this extended functionality. In the Window->Preferences->OCL page make sure that the selected executor for the default delegate is http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot.