Class PreconditionMatcher


  • public class PreconditionMatcher
    extends RuleSearchState
    This class contains the stateful part of the precondition checker. A new PreconditionMatcher is allocated when searching a rule chain to find the best matching rule for a given node (or other item). It holds the values of preconditions and characteristics. A precondition is a boolean property of an item that must be true if the item is to match a particular pattern; once the precondition has been evaluated, its value can be used to eliminate other rules with the same precondition. A characteristic is a property of an item that must match a corresponding property of a rule if the rule is to match; for example, a property might be "name of parent element". Once the value of a characteristic (for example, the name of the parent element) has been evaluated, a rule can be eliminated if it requires a different value for the characteristic.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkPreconditions​(Rule rule)
      Use this search state to check whether the preconditions for a particular rule are satisfied
      int getPreconditionState​(int slot)
      Get the state of a given precondition.
      java.lang.Object obtainCharacteristic​(Characteristic chic)
      Get the value of a particular characteristic of the item being matched, evaluating it if it has not already been evaluated, and retaining its value for future use
      void setPreconditionState​(int slot, boolean value)
      Set the value of a given precondition.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PreconditionMatcher

        public PreconditionMatcher​(RuleChain chain,
                                   XPathContext context)
        Allocate a PreconditionMatcher for a given set of rules
        Parameters:
        chain - the set of rules being matched
        context - the XPath evaluation context; the context item is the item being matched against the set of rules
    • Method Detail

      • setPreconditionState

        public void setPreconditionState​(int slot,
                                         boolean value)
        Set the value of a given precondition.
        Parameters:
        slot - the slot number allocated to the precondition
        value - true if the precondition (for the item being matched) is known to be true, false if it is known to be false.
      • checkPreconditions

        public boolean checkPreconditions​(Rule rule)
                                   throws XPathException
        Use this search state to check whether the preconditions for a particular rule are satisfied
        Overrides:
        checkPreconditions in class RuleSearchState
        Parameters:
        rule - the rule being tested
        Returns:
        true if all preconditions are satisfied; in the HE implementation, there are no preconditions, so this is always true.
        Throws:
        XPathException - if evaluation of preconditions fails.
      • obtainCharacteristic

        public java.lang.Object obtainCharacteristic​(Characteristic chic)
                                              throws XPathException
        Get the value of a particular characteristic of the item being matched, evaluating it if it has not already been evaluated, and retaining its value for future use
        Parameters:
        chic - the characteristic to be evaluated
        Returns:
        the value of the characteristic
        Throws:
        XPathException - if evaluation of the characteristic failed