Saturday, March 24, 2012

Check Your Models

The Eclipse UML2 project has a new feature in the Juno M6 milestone that should help a certain category of applications to keep their UML models in good health.  These are UML-based modelling tools that use the EMF Validation Framework for model validation, often because they provide diagram editors based on GMF.  The Papyrus project is a good example of such application, and it happens to integrate this new feature.

The UML2 project implements the UML metamodel version 2.4.  I have always said that a model is not complete without the constraints that determine what is a well-formed instance.  Well, now we can have our diagrams and our constraints, too!

The org.eclipse.uml2.uml plug-in now provides a DelegatingConstraintProvider class that adapts the constraints implemented by the UML metamodel's generated EValidator to the framework used by GMF editors.  An application like Papyrus registers this provider on the org.eclipse.emf.validation.constraintProviders extension point and binds it to its client context.  This works not only with the UML metamodel, itself, but any model described in UML and generated by the UML2 project's specialized EMF code generator.




The screenshot above shows the invocation of model validation on a Papyrus UML class diagram with some invalid structures:  a class specializing a component (incompatible metaclasses for generalization) and, more difficult to see, a redefinition relationship between associations ends in classes that aren't related by generalization.



And here we see the results of model validation reported in problems view and, where possible, in the diagram editor, thanks to the information provided by the validation framework about the objects that contribute to the problems.

There are a few customization options available to adopters of this constraint provider, including:

  • defining a category to group the constraints in the Model Validation preference page
  • substituting the default registered EValidator with some other implementation
  • providing a custom label provider for the presentation of model elements in problem messages
It's a small feature but a significant piece of a complete modelling story.  For more details, see bug 373643 in the Eclipse Bugzilla database.  

No comments:

My blog has moved!

You will be automatically redirected to the new address.

If that does not occur, please visit http://www.damus.ca/blog/.