Class DefaultValidationRuleImpl

java.lang.Object
com.nomagic.magicdraw.validation.DefaultValidationRuleImpl
All Implemented Interfaces:
ElementValidationRuleImpl, SmartListenerConfigProvider

@OpenApiAll public class DefaultValidationRuleImpl extends Object implements ElementValidationRuleImpl, SmartListenerConfigProvider
The class implements validating of a model elements by using OCL or binary implementation.
  • Constructor Details

    • DefaultValidationRuleImpl

      public DefaultValidationRuleImpl()
  • Method Details

    • init

      public void init(Project project, Constraint constraint)
      Initializes the instance from specified parameters.
      Specified by:
      init in interface ElementValidationRuleImpl
      Parameters:
      project - project on which model elements the validation rule applies.
      constraint - a constraint object.
    • getListenerConfigurations

      @CheckForNull public Map<Class<? extends Element>,Collection<SmartListenerConfig>> getListenerConfigurations()
      Returns configurations for the rule's expression. When it returns null - the validation rule is interested in all model element changes.
      Specified by:
      getListenerConfigurations in interface SmartListenerConfigProvider
      Returns:
      map of listener configurations by element class type
    • run

      @CheckForNull public final Set<Annotation> run(Project project, Constraint constraint, Collection<? extends Element> elements)
      Performs validation on the specified model elements by using specified constraint.
      Specified by:
      run in interface ElementValidationRuleImpl
      Parameters:
      project - a project of the constraint.
      constraint - constraint that should be used to validate model elements.
      elements - a collection of model elements that needs to be validated.
      Returns:
      collection of Annotation objects that describes violations of the rule.
    • initializeSingleRun

      protected void initializeSingleRun()
      Single run specific rule data can be initialized here.
    • createAnnotation

      protected Annotation createAnnotation(Element element, Constraint constraint)
      Default implementation creates an annotation without actions. Derived classes can override the method and return an Annotation object with actions.
      Parameters:
      element - a model element for which Annotation object should be created.
      constraint - the constraint that is violated.
      Returns:
      Annotation object.
    • getInvalidElements

      protected Collection<? extends Element> getInvalidElements(Constraint constraint, Collection<? extends Element> elements)
      Returns invalid elements from the specified collection of elements.
      Parameters:
      constraint - constraint that specifies validation rules.
      elements - a collection of elements that need to be validated.
      Returns:
      a collection of invalid elements.
    • dispose

      public void dispose()
      Cleans up used resources of the object.
      Specified by:
      dispose in interface ElementValidationRuleImpl