The Epsilon Validation Language (EVL) is a model validation language that provides additional features to OCL, such as guards, constraint dependency management, user interaction, access to Java objects, and the ability to specify a number of fixes for each constraint, that the user can invoke if the constraint fails in order to repair the model. We’ve been recently working on integrating EVL with GMF so that failed constraints can appear as error/warning markers in GMF editors, and fixes can be invoked using the standard Quick Fix mechanism. An example follows:
The following screenshot shows a file system model in a GMF-based editor (constructed here).
We now specify the following EVL constraints and bind them to the editor (using the instructions provided here):
context File {
constraint HasName {
check : self.name.isDefined()
message : 'Unnamed ' + self.eClass().name + ' not allowed'
}
}
context Folder {
critique NameStartsWithCapital {
guard : self.satisfies('HasName')
check : self.name.firstToUpperCase() = self.name
message : 'Folder ' + self.name +
' should start with an upper-case letter'
fix {
title : 'Rename to ' + self.name.firstToUpperCase()
do {
self.name := self.name.firstToUpperCase();
}
}
}
}
context Sync {
constraint MustLinkSame {
check : self.source.eClass() = self.target.eClass()
message : 'Cannot synchronize a ' + self.source.eClass().name
+ ' with a ' + self.target.eClass().name
fix {
title : 'Synchronize with another ' +
self.source.eClass().name
do {
var target := UserInput.choose('Select target',
_Model.getAllOfType(self.source.eClass().name));
if (target.isDefined()) self.target := target;
}
}
}
}
Then, we evaluate the constraints by clicking Diagram->Validate, and our editor and Problems view now look like this:
We can now right click on the warning and invoke quick fix we have defined for the NameStartsWithCapital critique.
By clicking Finish, the fix is executed and the warning disappears.
A complete reference of the syntax and semantics of EVL can be found in Chapter 6 of the Epsilon Book (PDF). Also, instructions for binding EVL constraints with an existing GMF editor can be found here. Finally, a Flash screencast of this example is available here.
November 10, 2008 at 5:34 pm |
Cool!
November 11, 2008 at 5:00 pm |
Thanks Chris