org.eclipse.emf.validation.model
Interface IModelConstraint

All Known Implementing Classes:
AbstractOCLModelConstraint, ModelConstraint

public interface IModelConstraint

Interface implemented by all constraint objects in the EMF model validation framework, providing the validate request.


Field Summary
static int STATUS_CODE_SUCCESS
          The status code reported in the IStatus when a constraint succeeds.
 
Method Summary
 IConstraintDescriptor getDescriptor()
          Obtains my descriptor, which provides a variety of meta-data about me.
 IStatus validate(IValidationContext ctx)
           Validates an object in the specified context.
 

Field Detail

STATUS_CODE_SUCCESS

static final int STATUS_CODE_SUCCESS
The status code reported in the IStatus when a constraint succeeds.

See Also:
Constant Field Values
Method Detail

validate

IStatus validate(IValidationContext ctx)

Validates an object in the specified context. The target of the validation operation is available from the context object.

Note that it is best to use the IValidationContext.createSuccessStatus() and IValidationContext.createFailureStatus(Object...) methods of the context object to create the status object returned from this method, to ensure that the status object returned is correctly handled by the validation system.

A single constraint implementation may check multiple conditions. In such cases, it can return a multi-status of multiple results created by the overloaded variants of the ConstraintStatus.createStatus(IValidationContext, org.eclipse.emf.ecore.EObject, Collection, String, Object...) method. In these cases, also, each resulting status can store a distinct result locus. For example:

     public IStatus validate(IValidationContext ctx) {
         List problems = new java.util.ArrayList();
         
         // check the first condition.  This method adds results to the
         //    ctx's result locus if it finds a problem
         IStatus problem = checkFirstCondition(ctx);
         if (problem != null) problems.add(problem);
         
         // check another condition, involving different objects
         problem = checkSecondCondition(ctx);
         if (problem != null) problems.add(problem);
         
         return problems.isEmpty()? ctx.createSuccessStatus() :
             ConstraintStatus.createMultiStatus(ctx, problems);
     }
     
     private IStatus checkFirstCondition(IValidationContext ctx) {
         EObject target = ctx.getTarget();
         
         Collection problemElements = ...; // collect problem elements
         boolean ok = ... ;  // check the target and some related objects
         
         return ok? null : ConstraintStatus.createStatus(
                 ctx,
                 problemElements,
                 "Problem with {0}",
                 new Object[] {problemElements});
     }
     
     private IStatus checkSecondCondition(IValidationContext ctx) ...
 

Parameters:
ctx - the validation context that provides access to the current constraint evaluation environment. The framework will never pass a null value
Returns:
the status of validation of the target object. The IStatus.getSeverity() of the record is either IStatus.OK to indicate success, or some other value to indicate that validation failed. Must not return null
See Also:
IValidationContext.createSuccessStatus(), IValidationContext.createFailureStatus(Object...), ConstraintStatus.createStatus(IValidationContext, org.eclipse.emf.ecore.EObject, Collection, String, Object[])

getDescriptor

IConstraintDescriptor getDescriptor()
Obtains my descriptor, which provides a variety of meta-data about me.

Returns:
my constraint descriptor

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.