The EMF (Eclipse Modeling Framework) Modeling framework can help us transform models (UML, XSD, etc.) into robust and rich Java code. Using EMF to build an application, not only can greatly improve the development efficiency, but also take advantage of the many features provided by EMF to ensure the robustness and perfection of the model, including model change notification mechanism, model persistence and model validation framework. The EMF Validation framework that this article will introduce is an important part of EMF, and by using the EMF Validation Framework, we can easily add validation constraints to the defined EMF model to ensure that the model data is compliant with user-defined constraints.
The EMF Validation Framework provides a validation framework for EMF Eobjects, compared to the EMF Evalidator API
It provides more complex and comprehensive validation and is easy to expand. The EMF Validation Framework provides flexible validation definitions and supports two validation triggers: Batch and Live. It supports the implementation of constraints in the JAVA and OCL languages, and it also supports custom validation of model scanning algorithms, and provides a Validation Client context to circumvent unnecessary validation.
Implementation principle of EMF Validation Framework
There are several important concepts in the EMF Validation framework, which form the basic part of the validation framework, which we describe here:
Constraint (constraints)
All constraints must implement the Imodelconstraint interface, define the logic for validation execution (validate ()), and have a constraint descriptor (a class that implements the Iconstraintdescriptor interface) that contains the source information for this constraint. For example, the validation mode is live or batch, the target object of the validation, and so on, figure 1 can give you a basic concept.
Figure 1. Constraints