Package dev.metaschema.core.metapath.format


package dev.metaschema.core.metapath.format
Provides formatters for generating path expressions from Metaschema node items.

This package contains interfaces and implementations for converting sequences of path segments (representing navigation through a Metaschema document structure) into formatted path strings. Different formatters can produce paths in various syntaxes for different use cases.

Key interfaces and classes:

  • IPathFormatter - Core interface defining the contract for path formatters with implementations for different path syntaxes
  • IPathSegment - Represents a single segment in a path, providing navigation to parent segments and access to associated node items
  • MetapathFormatter - Produces Metapath expression syntax for paths (e.g., /root/assembly[1]/field[1])
  • XPathFormatter - Produces XPath 3.1 paths with EQName-qualified names (e.g., /Q{http://example.com}root/Q{http://example.com}assembly[1])
  • JsonPointerFormatter - Produces RFC 6901 JSON Pointer paths (e.g., /root/assemblies/0/id)

Available formatter constants on IPathFormatter:

Path formatters are primarily used for:

  • Generating human-readable error messages that indicate the location of schema validation failures
  • Creating navigational references for documentation and debugging
  • Providing context when reporting constraint violations
  • Integrating with XML tooling (XPath formatter)
  • Integrating with JSON tooling (JSON Pointer formatter)

Typical usage:


 // Get a path formatter
 IPathFormatter formatter = IPathFormatter.METAPATH_PATH_FORMATER;

 // Format a path from a node item
 INodeItem nodeItem = ...; // some node in a document
 String path = nodeItem.toPath(formatter);
 // Result: "/root-assembly/child-assembly[1]/field[1]"

 // For JSON Pointer paths:
 String jsonPath = nodeItem.toPath(IPathFormatter.JSON_POINTER_PATH_FORMATTER);
 // Result: "/root-assembly/child-assemblies/0/field"
 

Path formatters are designed to be stateless and thread-safe, allowing reuse across multiple formatting operations.