Package com.nomagic.magicdraw.validation
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Annotation
createAnnotation
(Element element, Constraint constraint) Default implementation creates an annotation without actions.void
dispose()
Cleans up used resources of the object.protected Collection<? extends Element>
getInvalidElements
(Constraint constraint, Collection<? extends Element> elements) Returns invalid elements from the specified collection of elements.Map<Class<? extends Element>,
Collection<SmartListenerConfig>> Returns configurations for the rule's expression.void
init
(Project project, Constraint constraint) Initializes the instance from specified parameters.protected void
Single run specific rule data can be initialized here.final Set<Annotation>
run
(Project project, Constraint constraint, Collection<? extends Element> elements) Performs validation on the specified model elements by using specified constraint.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.nomagic.magicdraw.validation.ElementValidationRuleImpl
postRun, preRun, preRun
-
Constructor Details
-
DefaultValidationRuleImpl
public DefaultValidationRuleImpl()
-
-
Method Details
-
init
Initializes the instance from specified parameters.- Specified by:
init
in interfaceElementValidationRuleImpl
- 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 interfaceSmartListenerConfigProvider
- 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 interfaceElementValidationRuleImpl
- 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
Default implementation creates an annotation without actions. Derived classes can override the method and return anAnnotation
object with actions.- Parameters:
element
- a model element for whichAnnotation
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 interfaceElementValidationRuleImpl
-