Class ValidationContext

java.lang.Object
dev.metaschema.databind.io.ValidationContext

public final class ValidationContext extends Object
Provides contextual information for validation errors during parsing.

This class bundles together:

  • Source URI - the document being parsed
  • Location - line and column within the document
  • Path - the path to the current element in the document structure
  • Format - whether parsing XML, JSON, or YAML

This context is passed to problem handlers to enable rich, informative error messages that help users locate and understand validation errors.

  • Method Details

    • of

      @NonNull public static ValidationContext of(@Nullable URI source, @NonNull IResourceLocation location, @NonNull String path, @NonNull Format format)
      Create a new validation context.
      Parameters:
      source - the source URI, may be null
      location - the resource location, must not be null
      path - the current path, must not be null
      format - the format being parsed, must not be null
      Returns:
      a new validation context
    • ofUnknownLocation

      @NonNull public static ValidationContext ofUnknownLocation(@Nullable URI source, @NonNull String path, @NonNull Format format)
      Create a validation context with unknown location.
      Parameters:
      source - the source URI, may be null
      path - the current path
      format - the format being parsed
      Returns:
      a new validation context with unknown location
    • getSource

      @Nullable public URI getSource()
      Get the source URI of the document being parsed.
      Returns:
      the source URI, or null if not available
    • getLocation

      @NonNull public IResourceLocation getLocation()
      Get the location within the document.
      Returns:
      the resource location
    • getPath

      @NonNull public String getPath()
      Get the path to the current element.
      Returns:
      the element path
    • getFormat

      @NonNull public Format getFormat()
      Get the format being parsed.
      Returns:
      the format
    • formatLocation

      @NonNull public String formatLocation()
      Format the location information as a human-readable string.

      The format is: "in 'source' at line:column" or "at line:column" if no source is available, or empty string if location is unknown.

      Returns:
      a formatted location string
    • formatPath

      @NonNull public String formatPath()
      Format the path information for display.
      Returns:
      the path, or "at document root" if path is empty or "/"
    • toString

      public String toString()
      Overrides:
      toString in class Object