Class SchemaPath


  • public class SchemaPath
    extends java.lang.Object
    Path specification within a schema definition. This implements simple XPath-like expressions, consisting of any number of path components given as element names or '*' for any element or '**' for any nesting of elements, along with optional position number or name attribute predicates in square brackets.
    Author:
    Dennis M. Sosnoski
    • Field Detail

      • WILDCARD_ELEMENT_STEP

        private static final SchemaPath.StepBase WILDCARD_ELEMENT_STEP
        Single element wildcard step.
      • WILDCARD_NESTING_STEP

        private static final SchemaPath.StepBase WILDCARD_NESTING_STEP
        Nesteing element wildcard step.
      • m_sourceObject

        private final java.lang.Object m_sourceObject
        Source object for path expression.
      • m_validationContext

        private final ValidationContext m_validationContext
        Validation context used for reporting errors.
    • Constructor Detail

      • SchemaPath

        private SchemaPath​(java.lang.Object obj,
                           ValidationContext vctx)
        Constructor.
        Parameters:
        obj - source object for expression
        vctx - validation context
    • Method Detail

      • validateName

        private boolean validateName​(java.lang.String nameattr)
        Validate a name attribute value.
        Parameters:
        nameattr - name value
        Returns:
        true if valid, false if not
      • convertPosition

        private int convertPosition​(java.lang.String postext)
        Validate and convert a position value.
        Parameters:
        postext - position text
        Returns:
        position value (strictly positive), or -1 if error
      • buildPathStep

        private SchemaPath.StepBase buildPathStep​(java.lang.String step)
        Build a path step.
        Parameters:
        step - expression
        Returns:
        constructed step, or null if error
      • match

        private void match​(int offset,
                           int end,
                           OpenAttrBase base,
                           java.util.ArrayList matches)
        Find matches for expression starting from a supplied schema element.
        Parameters:
        offset - current path step offset
        end - ending match list offset
        base - starting element for match
        matches - elements matching expression
      • getPathLength

        public int getPathLength()
        Get length of this path (minimum number of nested elements).
        Returns:
        path length
      • isWildStart

        public boolean isWildStart()
        Check if the first path step is a wildcard.
        Returns:
        true if wildcard, false if not
      • partialMatchMultiple

        public java.util.List partialMatchMultiple​(int first,
                                                   int last,
                                                   OpenAttrBase base)
        Find any number of matches for subexpression starting from a supplied schema element annotation.
        Parameters:
        first - starting path step index
        last - ending path step index
        base - starting element for match
        Returns:
        matching element, or null if error
      • partialMatchUnique

        public OpenAttrBase partialMatchUnique​(int first,
                                               int last,
                                               OpenAttrBase base)
        Find unique match for subexpression starting from a supplied schema element annotation. An error is reported if no match is found, or if multiple matches are found.
        Parameters:
        first - starting path step index
        last - ending path step index
        base - starting element for match
        Returns:
        matching element, or null if error
      • matchUnique

        public OpenAttrBase matchUnique​(OpenAttrBase base)
        Find unique match for expression starting from a supplied schema element annotation. An error is reported if no match is found, or if multiple matches are found.
        Parameters:
        base - starting element for match
        Returns:
        matching element, or null if error
      • buildPath

        public static SchemaPath buildPath​(java.lang.String path,
                                           java.lang.String elemname,
                                           java.lang.String nameattr,
                                           java.lang.String postext,
                                           java.lang.Object obj,
                                           ValidationContext vctx)
        Build a path. If a path expression is supplied, the final path step in the expression must either not use an element name, or the element name must match the actual element supplied.
        Parameters:
        path - expression (null if none)
        elemname - element name for final step in path
        nameattr - name attribute (applied to final step in path, null if none)
        postext - position (applied to final step in path, null if none)
        obj - object defining the path
        vctx - validation context
        Returns:
        constructed path, or null if error