Package com.nomagic.magicdraw.validation
Class DiagramValidator
- java.lang.Object
-
- com.nomagic.magicdraw.validation.DiagramValidator
-
- All Implemented Interfaces:
ValidationRule
- Direct Known Subclasses:
OpenedDiagramValidator
@OpenApiAll public abstract class DiagramValidator extends java.lang.Object implements ValidationRule
Rule to validate elements of diagrams by a given scope (all diagrams in project, only active diagrams or diagrams from a specific scope). Rule is triggered after various diagram related events like changes in the owned symbols, switching the active diagram.
-
-
Constructor Summary
Constructors Constructor Description DiagramValidator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
acceptDiagram(DiagramPresentationElement diagram)
void
dispose()
Unregisters all listeners that were registered and releases other resources.abstract java.util.Set<Annotation>
getAnnotations(Project project, Constraint constraint)
protected java.util.Collection<DiagramPresentationElement>
getDiagrams()
protected java.util.stream.Stream<DiagramPresentationElement>
getDiagramsStream()
protected java.util.List<PresentationElement>
getPresentationElements(Element element)
protected java.util.List<PresentationElement>
getPresentationElements(Element element, java.util.Collection<DiagramPresentationElement> diagrams)
protected Project
getProject()
Get the project.void
init(Project project, Constraint constraint)
This is the first method that is invoked on the implementation of theValidationRule
interface.boolean
isElementInScope(Element element)
If DiagramValidator is to be used in passive validation, then model part to validate can be selected.boolean
needsRun()
Returns whether the validation rule needs to run.protected boolean
needsRun(java.beans.PropertyChangeEvent event)
Check if validator needs to re-run after given change event occurred.java.util.Set<Annotation>
run(Project project, Constraint constraint)
Run the validation.protected void
setNeedsRun(boolean run)
Sets flag if this validator has to be re-run, meaning ifgetAnnotations(Project, Constraint)
method should be called again.
-
-
-
Method Detail
-
init
public void init(Project project, Constraint constraint)
Description copied from interface:ValidationRule
This is the first method that is invoked on the implementation of theValidationRule
interface. Implementation can initialize internal state if required.- Specified by:
init
in interfaceValidationRule
- Parameters:
project
- a project of the constraintconstraint
- a constraint object
-
needsRun
protected boolean needsRun(java.beans.PropertyChangeEvent event)
Check if validator needs to re-run after given change event occurred.- Parameters:
event
- event occurred.- Returns:
- true need to validate.
-
run
public final java.util.Set<Annotation> run(Project project, Constraint constraint)
Description copied from interface:ValidationRule
Run the validation.- Specified by:
run
in interfaceValidationRule
- Parameters:
project
- a project of the constraintconstraint
- a constraint object- Returns:
- set of
Annotation
objects
-
getAnnotations
public abstract java.util.Set<Annotation> getAnnotations(Project project, Constraint constraint)
ReturnAnnotation
object for eachElement
orPresentationElement
which should be annotated. Only the elements represented in diagrams returned bygetDiagrams()
method should be analyzed.- Parameters:
project
- currently active projectconstraint
- a validation rule or a legend item. Use this element to constructAnnotation
objects.- Returns:
- annotations targeting elements from the diagrams in scope
-
needsRun
public boolean needsRun()
Description copied from interface:ValidationRule
Returns whether the validation rule needs to run.- Specified by:
needsRun
in interfaceValidationRule
- Returns:
- true if validation rule needs to run, otherwise false
-
setNeedsRun
protected void setNeedsRun(boolean run)
Sets flag if this validator has to be re-run, meaning ifgetAnnotations(Project, Constraint)
method should be called again. Actual re-run is done by the validation engine.- Parameters:
run
- true to mark validator for rerun
-
dispose
public void dispose()
Unregisters all listeners that were registered and releases other resources.- Specified by:
dispose
in interfaceValidationRule
-
getProject
protected Project getProject()
Get the project.- Returns:
- project
-
getDiagramsStream
protected final java.util.stream.Stream<DiagramPresentationElement> getDiagramsStream()
- Returns:
- Stream of the same diagrams as returned by
getDiagrams()
method. Convenience method.
-
getDiagrams
protected final java.util.Collection<DiagramPresentationElement> getDiagrams()
- Returns:
- collection of diagrams for which used elements annotations should be calculated in
getAnnotations(Project, Constraint)
method.
-
acceptDiagram
protected boolean acceptDiagram(DiagramPresentationElement diagram)
- Returns:
- true if the diagram in scope should be returned by
getDiagrams()
method
-
getPresentationElements
protected java.util.List<PresentationElement> getPresentationElements(Element element)
- Parameters:
element
- element to get presentation elements for- Returns:
- presentation elements of the given element from all diagrams that are currently in scope
-
getPresentationElements
protected java.util.List<PresentationElement> getPresentationElements(Element element, java.util.Collection<DiagramPresentationElement> diagrams)
- Parameters:
element
- element to get presentation elements fordiagrams
- diagrams of interest- Returns:
- presentation elements of the given element from given diagrams
-
isElementInScope
public boolean isElementInScope(Element element)
If DiagramValidator is to be used in passive validation, then model part to validate can be selected. So certain elements used in the diagram should be validated (they are in selected model scope) and certain should be ignored.Only annotate the element, or it's symbol if the element is in scope. Recommendation is to call this method for failing elements only as the last check, since many calls to this method might affect performance in certain scenarios
- Parameters:
element
- element which is used in any of the diagrams in scope- Returns:
- true if the element is in the model scope for the current validation
-
-