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 java.lang.Object implements ElementValidationRuleImpl, SmartListenerConfigProvider
The class implements validating of a model elements by using OCL or binary implementation.
-
-
Constructor Summary
Constructors Constructor Description DefaultValidationRuleImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AnnotationcreateAnnotation(Element element, Constraint constraint)Default implementation creates an annotation without actions.voiddispose()Cleans up used resources of the object.protected java.util.Collection<? extends Element>getInvalidElements(Constraint constraint, java.util.Collection<? extends Element> elements)Returns invalid elements from the specified collection of elements.java.util.Map<java.lang.Class<? extends Element>,java.util.Collection<SmartListenerConfig>>getListenerConfigurations()Returns configurations for the rule's expression.voidinit(Project project, Constraint constraint)Initializes the instance from specified parameters.protected voidinitializeSingleRun()Single run specific rule data can be initialized here.java.util.Set<Annotation>run(Project project, Constraint constraint, java.util.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
-
-
-
-
Method Detail
-
init
public void init(Project project, Constraint constraint)
Initializes the instance from specified parameters.- Specified by:
initin interfaceElementValidationRuleImpl- Parameters:
project- project on which model elements the validation rule applies.constraint- a constraint object.
-
getListenerConfigurations
@CheckForNull public java.util.Map<java.lang.Class<? extends Element>,java.util.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:
getListenerConfigurationsin interfaceSmartListenerConfigProvider- Returns:
- map of listener configurations by element class type
-
run
@CheckForNull public final java.util.Set<Annotation> run(Project project, Constraint constraint, java.util.Collection<? extends Element> elements)
Performs validation on the specified model elements by using specified constraint.- Specified by:
runin 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
Annotationobjects 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 anAnnotationobject with actions.- Parameters:
element- a model element for whichAnnotationobject should be created.constraint- the constraint that is violated.- Returns:
Annotationobject.
-
getInvalidElements
protected java.util.Collection<? extends Element> getInvalidElements(Constraint constraint, java.util.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:
disposein interfaceElementValidationRuleImpl
-
-