Class Elaborator

  • Direct Known Subclasses:
    BooleanElaborator, FallbackElaborator, ItemElaborator, PullElaborator, PushElaborator, SimpleNodePushElaborator, StringElaborator, UpdateElaborator

    public abstract class Elaborator
    extends java.lang.Object
    This class is at the heart of the mechanism for elaborating expressions.

    This mechanism evaluates expressions in two stages. The first stage (the elaboration stage), converts the expression to a lambda function, specifically a function of the context that can be called to produce the expression result. The second stage invokes this function (supplying the context as an argument) to generate the result.

    The mechanism is complicated by the fact that expressions can be evaluated in different modes. Specifically: pull evaluation delivers an iterator over the result, item evaluation delivers the singleton result as an item; push evaluation sends the results to an Outputter, boolean evaluation returns the effective boolean value, and string evaluation returns the string value. Update evaluation is used for XQuery update expressions.

    The Elaborator class is the abstract root of a hierarchy of classes for elaborating different kinds of expression.

    • Constructor Detail

      • Elaborator

        public Elaborator()
    • Method Detail

      • getExpression

        public Expression getExpression()
        Get the expression being elaborated
        Returns:
        the expression
      • setExpression

        public void setExpression​(Expression expr)
        Set the expression being elaborated
        Parameters:
        expr - the expression
      • getConfiguration

        protected Configuration getConfiguration()
        Get the Saxon Configuration
        Returns:
        the Configuration
      • eagerly

        public SequenceEvaluator eagerly()
        Get a function that evaluates the underlying expression eagerly
        Returns:
        an evaluator for the expression that returns a GroundedValue. The class SequenceEvaluator is declared to return a Sequence not a GroundedValue; we can't specialize it because it's a limitation of C# delegates, but the result can safely be cast to GroundedValue.
      • lazily

        public SequenceEvaluator lazily​(boolean repeatable,
                                        boolean lazyEvaluationRequired)
        Get a function that evaluates the underlying expression lazily
        Parameters:
        repeatable - true if the resulting Sequence must be usable repeatedly; false if it only needs to be used once
        lazyEvaluationRequired - true if the expression MUST be evaluated lazily, for example to prevent spurious errors or side-effects if it has been lifted out of a loop
        Returns:
        an evaluator for the expression that returns a Sequence (which may be a lazy sequence)
      • elaborateForPull

        public abstract PullEvaluator elaborateForPull()
        Get a function that evaluates the underlying expression in the form of a SequenceIterator
        Returns:
        an evaluator for the expression that returns a SequenceIterator
      • elaborateForPush

        public abstract PushEvaluator elaborateForPush()
        Get a function that evaluates the underlying expression in push mode, by writing events to an Outputter
        Returns:
        an evaluator for the expression in push mode
      • elaborateForItem

        public abstract ItemEvaluator elaborateForItem()
        Get a function that evaluates the underlying expression in the form of a Item. This must only be called for expressions whose result has cardinality zero or one.
        Returns:
        an evaluator for the expression that returns an Item, or null to represent an empty sequence.
      • elaborateForBoolean

        public abstract BooleanEvaluator elaborateForBoolean()
        Get a function that evaluates the underlying expression in the form of a boolean, this being the effective boolean value of the expression.
        Returns:
        an evaluator for the expression that returns a boolean.
      • elaborateForUnicodeString

        public abstract UnicodeStringEvaluator elaborateForUnicodeString​(boolean zeroLengthWhenAbsent)
        Get a function that evaluates the underlying expression in the form of a unicode string, this being the result of applying fn:string() to the result of the expression.
        Parameters:
        zeroLengthWhenAbsent - if true, then when the result of the expression is an empty sequence, the result of the StringEvaluator should be a zero-length string. If false, the return value should be null. For an expression or function that never returns an empty sequence (for example, a call on string() or normalize-space()), the argument has no effect.
        Returns:
        an evaluator for the expression that returns a string.
      • elaborateForString

        public StringEvaluator elaborateForString​(boolean zeroLengthWhenAbsent)
        Get a function that evaluates the underlying expression in the form of a Java string, this being the result of applying fn:string() to the result of the expression.
        Parameters:
        zeroLengthWhenAbsent - if true, then when the result of the expression is an empty sequence, the result of the StringEvaluator should be a zero-length string. If false, the return value should be null.
        Returns:
        an evaluator for the expression that returns a string.
      • handleNullUnicodeString

        protected final UnicodeString handleNullUnicodeString​(boolean zeroLengthWhenAbsent)
        Helper method that returns either a zero length string or null, depending on the parameter
        Parameters:
        zeroLengthWhenAbsent - if true, return a zero length string; if false, return null
      • handlePossiblyNullUnicodeString

        protected final UnicodeString handlePossiblyNullUnicodeString​(UnicodeString str,
                                                                      boolean zeroLengthWhenAbsent)
      • handleNullString

        protected final java.lang.String handleNullString​(boolean zeroLengthWhenAbsent)
        Helper method that returns either a zero length string or null, depending on the parameter
        Parameters:
        zeroLengthWhenAbsent - if true, return a zero length string; if false, return null
      • handlePossiblyNullString

        protected final java.lang.String handlePossiblyNullString​(java.lang.String str,
                                                                  boolean zeroLengthWhenAbsent)