Accuracy

Objectives

This project defines architecture to contribute and define easily OCL or JAVA Constraints for any EMF Modeling project. Accuracy uses is based on the EMF Validation Framework and Eclipse architecture profits by exploiting the concept of plug-in.

image

Extensibility

Accuracy is an Eclipse plug-in that uses some kind files and defined an extension point. There are three important kinds of files:

Here is an organization sample: image

Declaring Validation Rules

The Ocl File

An OCL file contains one or more invariants (at your convenience).

constraint0001.ocl:
package extlibrary
context Library
-- we can define additional operations and attributes to assist
-- in the formulation of our constraints
def: unpublishedWriters : Set(Writer) = self.writers->select(books->isEmpty())

-- so, here we use one such definition
inv writers_have_written: unpublishedWriters->isEmpty()
endpackage

The Java File

It is possible to use the Java Language to check rules. You have to write a Java Class that implements the IJavaConstraint contract (see below). The WriterNameStartsWithUpperCase is a sample:

public class WriterNameStartsWithUpperCase implements IJavaConstraint<Writer> {

    public Class<Writer> getTargetType() {
        return Writer.class;
    }

    
    public boolean isValid(Writer object) {
        return object.getName() != null && object.getName().length() > 0
                && Character.isUpperCase(object.getName().charAt(0));
    }

}

Interface

Provided by bundle : org.polarsys.kitalpha.accuracy

File name: org.polarsys.kitalpha.validation.java.provider.generic.IJavaConstraint.java

Configuration File

This file describes which constraints files have to be loaded, and for each invariant that will be found in OCL files and each provided JAVA constraints:

When you write a new constraint, you just have to create the .ocl file in the good directory, and 'add' the constraint information in the properties file.

The properties file contains some more information :

Below a header of a configuration file:

#== Common category used for all constraints => necessary to be taken into account
#== by the Constraint Binding
CommonRootCategory=library/allConstraints

#== Folder where the constraints will be found.
ConstraintsFolder=OwnConstraints/Constraints/

#== The list of file names (separated by a ',') (without extension) that contain the invariants
#== having the message, severity, categories described in this file
ConstraintFiles=\
constraint0001,\
constraint0002

The Constraints

This part of the configuration file contains all constraints. A constraint specifies the following data:

Here is a sample of a constraint part of the configuration file:

#============= Constraint constraint0001/writers_have_written/Rule Type = OCL
# All writer shall have written at least one book
constraint0001.Invariant.writers_have_written.Name=LibraryConstraint#0001
constraint0001.Invariant.writers_have_written.Message=\
Library's writers should have written at least one book.
constraint0001.Invariant.writers_have_written.Severity=ERROR
constraint0001.Invariant.writers_have_written.Categories=library/writer
constraint0001.Invariant.writers_have_written.Code=0001

#============= Constraint constraint0001/writers_have_written/Rule Type = OCL
# Every book shall have an author
constraint0002.Invariant.book_must_have_author.Name=LibraryConstraint#0002
constraint0002.Invariant.book_must_have_author.Message={0} has no writer.
constraint0002.Invariant.book_must_have_author.Severity=ERROR
constraint0002.Invariant.book_must_have_author.Categories=library/book
constraint0002.Invariant.book_must_have_author.Code=0002

The key of information has the following pattern: OCL: [ocl_file_name].Invariant.[invariant_name].[data_to_set] Java: [requirement_id].Invariant.[invariant_id].[data_to_set]

Contributing Constraitnes to Accuracy

Declaring a Constraint Category For The Validation Rules

Provided by bundle: org.eclipse.emf.validation

Extension point name: org.eclipse.emf.validation.constraintBindings.

Declaring a constraint category is done through the following extension (in the bundle plugin.xml file):

<extension
   point="org.eclipse.emf.validation.constraintBindings">
      <binding
        category="library"
        context="org.polarsys.kitalpha.accuracy.clientContext">
      </binding>
</extension>

ConstraintBindings Declaration Attributes:

Declaring Validation Rules Mapping to Business Metamodel

Declaring Validation Rules Mapping to Business Metamodel

Provided by bundle: org.eclipse.emf.validation

Extension point name: org.eclipse.emf.validation.constraintProviders.

Declaring a validation rule mapping to metamodel is done through the following extension (in the bundle plugin.xml file):

<extension
     id="ocl.constraint.provider.SpecificConstraintProvider"
     point="org.eclipse.emf.validation.constraintProviders">
     <constraintProvider
        class="ocl.constraint.provider.SpecificConstraintProvider">
         <package namespaceUri="http://org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0">
         </package>
   </constraintProvider>
</extension>

ConstraintProvider Declaration Attributes:

Package Declaration Attributes:

Note : If you declaring JAVA Validation Rules, you have to contribute another extension point :

Provided by bundle: org.eclipse.emf.validation

Extension point name: org.polarsys.kitalpha.validation.java.

Presentation

Additional documentation can be found on the presentation.