Class ModeEE

  • All Implemented Interfaces:
    javax.xml.transform.SourceLocator, ExpressionOwner, Location, org.xml.sax.Locator

    public class ModeEE
    extends ModePE
    A version of class Mode that optimizes various aspects of the template patterns, most notably supporting rule preconditions and indexation of unnamed elements.
    • Method Detail

      • makeRule

        public Rule makeRule​(Pattern pattern,
                             RuleTarget action,
                             int precedence,
                             int minImportPrecedence,
                             double priority,
                             int sequence,
                             int part)
        Description copied from class: SimpleMode
        Generate a new rule - so it can be overridden to make more specialist rules
        Overrides:
        makeRule in class SimpleMode
        Parameters:
        pattern - the pattern that this rule matches
        action - the object invoked by this rule (usually a Template)
        precedence - the precedence of the rule
        minImportPrecedence - the minimum import precedence for xsl:apply-imports
        priority - the priority of the rule
        sequence - a sequence number for ordering of rules
        part - distinguishes rules formed by splitting a rule on a union pattern
        Returns:
        the newly created rule
      • getNamedNodeChain

        public RuleChain getNamedNodeChain​(NodeInfo node,
                                           XPathContext context)
        Find the named node rule chain for a given node
        Parameters:
        node - the node to be matched
        context - local context
        Returns:
        the rule chain for nodes with this name, or null if none
      • getUnnamedNodeChain

        public RuleChain getUnnamedNodeChain​(NodeInfo node)
        Find the unnamed node rule chain for a given node
        Parameters:
        node - the node to be matched
        Returns:
        the rule chain for nodes of this type,or XPath error if illegal type
      • ruleMatches

        protected boolean ruleMatches​(Rule r,
                                      Item item,
                                      XPathContextMajor context,
                                      RuleSearchState ruleSearchState)
                               throws XPathException
        Does this rule match the given item? Can be overridden
        Overrides:
        ruleMatches in class SimpleMode
        Parameters:
        r - the rule to check
        item - the context item
        context - the static context for evaluation
        ruleSearchState - An appropriate matcher for preconditions in this mode
        Returns:
        true if this rule does match
        Throws:
        XPathException - if a dynamic error occurs while matching the pattern
      • optimizeRules

        public void optimizeRules()
        Perform optimization on the complete set of rules comprising this Mode. This is done by optimizing each rule chain in turn.
        Overrides:
        optimizeRules in class SimpleMode
      • optimizeRuleChain

        public void optimizeRuleChain​(RuleChain chain)
        Perform optimization on a chain of rules. This is done by examining the rules in the chain to see if there are common subexpressions (preconditions) that apply to more than one rule; once a precondition has been evaluated for one rule, it can be used to eliminate other rules quickly without full evaluation of the pattern
        Parameters:
        chain - the chain of rules
      • listRules

        public static java.util.List<Rule> listRules​(RuleChain chain)
        Work with a rule chain as a list of rules
        Parameters:
        chain - the chained set of rules
        Returns:
        the rules as an ordered list, in the same order as the chain
      • orderRules

        public static java.util.List<Rule> orderRules​(java.util.List<Rule> r1,
                                                      java.util.List<Rule> r2)
        Combine two rule lists in rank order

        This does not detect duplicates within the list

        Parameters:
        r1 - one list of rules, assumed in rank order
        r2 - the other list of rules, assumed in rank order
        Returns:
        the combined list of rules
      • useFirst

        protected static boolean useFirst​(Rule chain1,
                                          Rule chain2)
      • orderRules

        public static java.util.List<Rule> orderRules​(RuleChain chain1,
                                                      RuleChain chain2)
        Combine two rule chains into a rank-ordered combined list

        This could be simplified as orderRules(listRules(chain1),listRules(chain2))

        Parameters:
        chain1 - the first rule chain
        chain2 - the second rule chain
        Returns:
        a list containing all the rules in the two chains, ordered by rank
      • explainTemplateRules

        public void explainTemplateRules​(ExpressionPresenter out)
                                  throws XPathException
        Description copied from class: SimpleMode
        Explain all template rules in this mode by showing their expression tree represented in XML. Note that this produces more information than the simpler exportTemplateRules() method: this method is intended for the human reader wanting diagnostic explanations, whereas exportTemplateRules() is designed to produce a package that can be re-imported.
        Overrides:
        explainTemplateRules in class SimpleMode
        Parameters:
        out - used to display the expression tree
        Throws:
        XPathException
      • reportAmbiguity

        protected void reportAmbiguity​(Item item,
                                       Rule r1,
                                       Rule r2,
                                       XPathContext c)
                                throws XPathException
        Description copied from class: SimpleMode
        Report an ambiguity, that is, the situation where two rules of the same precedence and priority match the same node
        Overrides:
        reportAmbiguity in class SimpleMode
        Parameters:
        item - The item that matches two or more rules
        r1 - The first rule that the node matches
        r2 - The second rule that the node matches
        c - The context for the transformation
        Throws:
        XPathException - if the system is configured to treat ambiguous template matching as a non-recoverable error
      • typeName

        public static java.lang.String typeName​(int type)
        Find the name for a node type
        Parameters:
        type - the code for the type
        Returns:
        a suitable string or the empty string if unknown