Package com.saxonica.ee.trans

## Class ModeEE

- java.lang.Object
- - net.sf.saxon.expr.instruct.Actor
  - - net.sf.saxon.trans.Mode
    - - net.sf.saxon.trans.SimpleMode
      - - com.saxonica.trans.ModePE
        - - com.saxonica.ee.trans.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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `ModeEE.RuleChainOptimizationData` |
    `static interface` | `ModeEE.RuleTypeAction` |

    - ### Nested classes/interfaces inherited from class net.sf.saxon.trans.SimpleMode

      `SimpleMode.RuleGroupAction`

    - ### Nested classes/interfaces inherited from class net.sf.saxon.trans.Mode

      `Mode.RuleAction, Mode.RuleFilter`

  - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.trans.SimpleMode

      `atomicValueRuleChain, commentRuleChain, documentRuleChain, functionItemRuleChain, genericRuleChain, namedAttributeRuleChains, namedElementRuleChains, namespaceRuleChain, processingInstructionRuleChain, qNamedAttributeRuleChains, qNamedElementRuleChains, textRuleChain, unnamedAttributeRuleChain, unnamedElementRuleChain`

    - ### Fields inherited from class net.sf.saxon.trans.Mode

      `DEFAULT_MODE_NAME, modeName, mustBeTyped, mustBeUntyped, OMNI_MODE, RECOVER_WITH_WARNINGS, UNNAMED_MODE_NAME`

    - ### Fields inherited from class net.sf.saxon.expr.instruct.Actor

      `body`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ModeEE​(StructuredQName modeName, CompilerInfo compilerInfo)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `computeStreamability()` | Compute the streamability of all template rules
    `void` | `explainTemplateRules​(ExpressionPresenter out)` | Explain all template rules in this mode by showing their expression tree represented in XML.
    `protected void` | `exportUseAccumulators​(ExpressionPresenter presenter)` |
    `RuleChain` | `getNamedNodeChain​(NodeInfo node, XPathContext context)` | Find the named node rule chain for a given node
    `RuleChain` | `getUnnamedNodeChain​(NodeInfo node)` | Find the unnamed node rule chain for a given node
    `void` | `invertStreamableTemplates()` | For a streamable mode, invert all the templates to generate streamable code
    `static java.util.List<Rule>` | `listRules​(RuleChain chain)` | Work with a rule chain as a list of rules
    `Rule` | `makeRule​(Pattern pattern, RuleTarget action, int precedence, int minImportPrecedence, double priority, int sequence, int part)` | Generate a new rule - so it can be overridden to make more specialist rules
    `protected PreconditionMatcher` | `makeRuleSearchState​(RuleChain chain, XPathContext context)` | Generate a search state for processing a given node
    `void` | `optimizeRuleChain​(RuleChain chain)` | Perform optimization on a chain of rules.
    `void` | `optimizeRules()` | Perform optimization on the complete set of rules comprising this Mode.
    `static java.util.List<Rule>` | `orderRules​(java.util.List<Rule> r1, java.util.List<Rule> r2)` | Combine two rule lists in rank order
    `static java.util.List<Rule>` | `orderRules​(RuleChain chain1, RuleChain chain2)` | Combine two rule chains into a rank-ordered combined list
    `void` | `reportAmbiguity​(Item item, Rule r1, Rule r2, XPathContext c)` | Report an ambiguity, that is, the situation where two rules of the same precedence and priority match the same node
    `protected boolean` | `ruleMatches​(Rule r, Item item, XPathContextMajor context, RuleSearchState ruleSearchState)` | Does this rule match the given item? Can be overridden
    `protected ModeEE.RuleTypeAction` | `setType​(ModeEE.RuleTypeAction action, ItemType type)` |
    `static java.lang.String` | `typeName​(int type)` | Find the name for a node type
    `protected static boolean` | `useFirst​(Rule chain1, Rule chain2)` |

    - ### Methods inherited from class com.saxonica.trans.ModePE

      `prepareStreamability`

    - ### Methods inherited from class net.sf.saxon.trans.SimpleMode

      `addRule, addRule, addRuleToNamedOrUnnamedChain, allocateAllBindingSlots, allocateAllPatternSlots, allocatePatternSlots, checkForConflictingProperties, computeRankings, copyRules, exportTemplateRules, forceAllocateAllBindingSlots, getActivePart, getBuiltInRuleSet, getExplicitNamespaces, getLabel, getMaxPrecedence, getMaxRank, getNamedRuleChain, getPropertyValue, getRule, getRule, getStackFrameSlotsNeeded, isEmpty, processRuleChain, processRuleChain, processRuleChains, processRules, processRules, searchRuleChain, searchRuleChain, setBuiltInRuleSet, setExplicitProperty, setGroup, setStackFrameSlotsNeeded`

    - ### Methods inherited from class net.sf.saxon.trans.Mode

      `applyTemplates, explain, export, getAccumulators, getBuiltInRuleSetForCode, getCodeForBuiltInRuleSet, getDeclaringComponent, getDefaultResultType, getModeName, getModeTitle, getNextMatchRule, getObjectName, getRecoveryPolicy, getRule, getSymbolicName, isDeclaredStreamable, isModeTracing, isMustBeTyped, isUnnamedMode, makeNewContext, setAccumulators, setDefaultResultType, setHasRules, setModeTracing, setRecoveryPolicy, setStreamable`

    - ### Methods inherited from class net.sf.saxon.expr.instruct.Actor

      `allocateBindingSlotsRecursive, getBody, getChildExpression, getColumnNumber, getComponentName, getDeclaredVisibility, getLineNumber, getLocation, getPackageData, getProperties, getProperty, getPublicId, getRetainedStaticContext, getStackFrameMap, getSystemId, getTracingTag, isExportable, makeDeclaringComponent, obtainDeclaringComponent, saveLocation, setBody, setChildExpression, setColumnNumber, setDeclaredVisibility, setDeclaringComponent, setLineNumber, setPackageData, setRetainedStaticContext, setStackFrameMap, setSystemId`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ModeEE

          public ModeEE​(StructuredQName modeName,
                        CompilerInfo compilerInfo)

  - ### Method Detail

    - #### exportUseAccumulators

          protected void exportUseAccumulators​(ExpressionPresenter presenter)

      Overrides:
        `exportUseAccumulators` in class `Mode`

    - #### 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

    - #### makeRuleSearchState

          protected PreconditionMatcher makeRuleSearchState​(RuleChain chain,
                                                            XPathContext context)

      Description copied from class: `SimpleMode`
      Generate a search state for processing a given node
      Overrides:
        `makeRuleSearchState` in class `SimpleMode`
      Returns:
        a new object capable of holding the state of a search for a 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

    - #### computeStreamability

          public void computeStreamability()
                                    throws XPathException

      Compute the streamability of all template rules
      Overrides:
        `computeStreamability` in class `SimpleMode`
      Throws:
        `XPathException`

    - #### invertStreamableTemplates

          public void invertStreamableTemplates()
                                         throws XPathException

      For a streamable mode, invert all the templates to generate streamable code
      Overrides:
        `invertStreamableTemplates` in class `SimpleMode`
      Throws:
        `XPathException` - if there is a non-streamable template in the mode

    - #### setType

          protected ModeEE.RuleTypeAction setType​(ModeEE.RuleTypeAction action,
                                                  ItemType type)

    - #### 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

          public 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