Module dev.metaschema.core
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 syntaxesIPathSegment- Represents a single segment in a path, providing navigation to parent segments and access to associated node itemsMetapathFormatter- 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:
IPathFormatter.METAPATH_PATH_FORMATER- Metapath syntaxIPathFormatter.XPATH_PATH_FORMATTER- XPath 3.1 with EQNamesIPathFormatter.JSON_POINTER_PATH_FORMATTER- RFC 6901 JSON Pointer
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.
-
ClassDescriptionThis interface provides an implementation contract for all path formatters.A named segment of a path that can be formatted.An
IPathFormatterthat produces RFC 6901 compliant JSON Pointer paths.AnIPathFormatterthat produces a Metapath expression for the path to a givenINodeItem.Enumeration of path format selection options for validation output.AnIPathFormatterthat produces XPath 3.1 expressions with namespace-qualified names using the EQName format (e.g.,Q{namespace}localname).