Class SarifValidationHandler

java.lang.Object
dev.metaschema.modules.sarif.SarifValidationHandler
All Implemented Interfaces:
dev.metaschema.core.model.constraint.ValidationEventListener

public final class SarifValidationHandler extends Object implements dev.metaschema.core.model.constraint.ValidationEventListener
Supports building a Static Analysis Results Interchange Format (SARIF) document based on a set of validation findings.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final dev.metaschema.core.model.IAttributable.Key
    The property key for specifying markdown-formatted help content for a constraint.
    static final dev.metaschema.core.model.IAttributable.Key
    The property key for specifying plain text help content for a constraint.
    static final dev.metaschema.core.model.IAttributable.Key
    The property key for specifying a URL that provides help information for a constraint.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SarifValidationHandler(URI source, dev.metaschema.core.util.IVersionInfo toolVersion)
    Construct a new validation handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFinding(dev.metaschema.core.model.validation.IValidationFinding finding)
    Register a validation finding.
    void
    addFindings(Collection<? extends dev.metaschema.core.model.validation.IValidationFinding> findings)
    Register a collection of validation finding.
    void
    afterConstraintEvaluation(dev.metaschema.core.model.constraint.IConstraint constraint, dev.metaschema.core.metapath.item.node.INodeItem target)
     
    void
    afterLetEvaluation(dev.metaschema.core.model.constraint.ILet let)
     
    void
    afterPhase(dev.metaschema.core.model.constraint.ValidationPhase phase)
     
    void
    afterValidation(URI document)
     
    void
    beforeConstraintEvaluation(dev.metaschema.core.model.constraint.IConstraint constraint, dev.metaschema.core.metapath.item.node.INodeItem target)
     
    void
    beforeLetEvaluation(dev.metaschema.core.model.constraint.ILet let)
     
    void
    beforePhase(dev.metaschema.core.model.constraint.ValidationPhase phase)
     
    void
     
    void
    setTimingCollector(dev.metaschema.core.model.constraint.TimingCollector collector)
    Set the timing collector to enrich SARIF output with performance data.
    void
    write(Path outputFile, dev.metaschema.databind.IBindingContext bindingContext)
    Write the collection of findings to the provided output file.
    writeToString(dev.metaschema.databind.IBindingContext bindingContext)
    Write the collection of findings to a string in SARIF format.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SARIF_HELP_URL_KEY

      @NonNull public static final dev.metaschema.core.model.IAttributable.Key SARIF_HELP_URL_KEY
      The property key for specifying a URL that provides help information for a constraint.
    • SARIF_HELP_TEXT_KEY

      @NonNull public static final dev.metaschema.core.model.IAttributable.Key SARIF_HELP_TEXT_KEY
      The property key for specifying plain text help content for a constraint.
    • SARIF_HELP_MARKDOWN_KEY

      @NonNull public static final dev.metaschema.core.model.IAttributable.Key SARIF_HELP_MARKDOWN_KEY
      The property key for specifying markdown-formatted help content for a constraint.
  • Constructor Details

    • SarifValidationHandler

      public SarifValidationHandler(@NonNull URI source, @Nullable dev.metaschema.core.util.IVersionInfo toolVersion)
      Construct a new validation handler.
      Parameters:
      source - the URI of the content that was validated
      toolVersion - the version information for the tool producing the validation results
  • Method Details

    • setTimingCollector

      public void setTimingCollector(@Nullable dev.metaschema.core.model.constraint.TimingCollector collector)
      Set the timing collector to enrich SARIF output with performance data.

      When set, the generated SARIF document will include:

      • An invocation element with start/end timestamps
      • Phase timing as tool execution notifications
      • Per-constraint timing in rule properties
      Parameters:
      collector - the timing collector containing measurement data, or null to disable timing output
    • beforeValidation

      public void beforeValidation(@NonNull URI document)
      Specified by:
      beforeValidation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • afterValidation

      public void afterValidation(@NonNull URI document)
      Specified by:
      afterValidation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • beforePhase

      public void beforePhase(@NonNull dev.metaschema.core.model.constraint.ValidationPhase phase)
      Specified by:
      beforePhase in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • afterPhase

      public void afterPhase(@NonNull dev.metaschema.core.model.constraint.ValidationPhase phase)
      Specified by:
      afterPhase in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • beforeConstraintEvaluation

      public void beforeConstraintEvaluation(@NonNull dev.metaschema.core.model.constraint.IConstraint constraint, @NonNull dev.metaschema.core.metapath.item.node.INodeItem target)
      Specified by:
      beforeConstraintEvaluation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • afterConstraintEvaluation

      public void afterConstraintEvaluation(@NonNull dev.metaschema.core.model.constraint.IConstraint constraint, @NonNull dev.metaschema.core.metapath.item.node.INodeItem target)
      Specified by:
      afterConstraintEvaluation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • beforeLetEvaluation

      public void beforeLetEvaluation(@NonNull dev.metaschema.core.model.constraint.ILet let)
      Specified by:
      beforeLetEvaluation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • afterLetEvaluation

      public void afterLetEvaluation(@NonNull dev.metaschema.core.model.constraint.ILet let)
      Specified by:
      afterLetEvaluation in interface dev.metaschema.core.model.constraint.ValidationEventListener
    • addFindings

      public void addFindings(@NonNull Collection<? extends dev.metaschema.core.model.validation.IValidationFinding> findings)
      Register a collection of validation finding.
      Parameters:
      findings - the findings to register
    • addFinding

      public void addFinding(@NonNull dev.metaschema.core.model.validation.IValidationFinding finding)
      Register a validation finding.
      Parameters:
      finding - the finding to register
    • writeToString

      @NonNull public String writeToString(@NonNull dev.metaschema.databind.IBindingContext bindingContext) throws IOException
      Write the collection of findings to a string in SARIF format.
      Parameters:
      bindingContext - the context used to access Metaschema module information based on Java class bindings
      Returns:
      the SARIF document as a string
      Throws:
      IOException - if an error occurred while generating the SARIF document
    • write

      public void write(@NonNull Path outputFile, @NonNull dev.metaschema.databind.IBindingContext bindingContext) throws IOException
      Write the collection of findings to the provided output file.
      Parameters:
      outputFile - the path to the output file to write to
      bindingContext - the context used to access Metaschema module information based on Java class bindings
      Throws:
      IOException - if an error occurred while writing the SARIF file