Class Precondition

java.lang.Object
com.saxonica.ee.trans.Precondition
Direct Known Subclasses:
Precondition.BooleanPrecondition, Precondition.NumericComparisonPrecondition, Precondition.StringHashPrecondition

public abstract class Precondition extends Object
A Precondition is a boolean condition that must be true if a pattern is to match (but in general is not a sufficient condition for the pattern to match). Preconditions may be defined in terms of "characteristics": that is, properties of the item being matched. When an item is matched against a RuleChain to find the best matching rule, subexpressions used by more than one rule may be evaluated as characteristics, so they are not evaluated repeatedly. Preconditions are shared by multiple rules. Evaluating a precondition for one rule may ensure that the patterns for other rules do not need to be evaluated.
  • Field Details

  • Constructor Details

    • Precondition

      public Precondition()
  • Method Details

    • setSlotNumber

      public void setSlotNumber(int slotNumber)
      Allocate a slot number indicating where in the data maintained by the PreconditionMatcher the value of this precondition should be held
      Parameters:
      slotNumber - the slot number to be used for the value of this precondition
    • isSatisfied

      public final boolean isSatisfied(PreconditionMatcher matcher) throws XPathException
      Ask whether the precondition is satisfied, making use of caching
      Parameters:
      matcher - The PreconditionMatcher holds the values of conditions that have already been matched, which is therefore used as a cache of values that do not need to be evaluated repeatedly. In addition it holds the dynamic evaluation context; the context item is the item being matched.
      Returns:
      true if the precondition is satisfied
      Throws:
      XPathException - if evaluation of the precondition fails with a dynamic error
    • testPrecondition

      protected abstract boolean testPrecondition(PreconditionMatcher matcher) throws XPathException
      Compute the value of the precondition for a given item. The item in question is the context item in the dynamic context held in the PreconditionMatcher
      Parameters:
      matcher - the PreconditionMatcher: holds the dynamic context for evaluation.
      Returns:
      true if the precondition is satisfied
      Throws:
      XPathException - if evaluation of the precondition fails with a dynamic error