Class SimpleMode

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

    public class SimpleMode
    extends Mode
    A Mode is a collection of rules; the selection of a rule to apply to a given element is determined by a Pattern. A SimpleMode is a mode contained within a single package, as opposed to a CompoundMode which can combine rules from several packages
    • Field Detail

      • genericRuleChain

        protected final RuleChain genericRuleChain
      • atomicValueRuleChain

        protected RuleChain atomicValueRuleChain
      • functionItemRuleChain

        protected RuleChain functionItemRuleChain
      • documentRuleChain

        protected RuleChain documentRuleChain
      • textRuleChain

        protected RuleChain textRuleChain
      • commentRuleChain

        protected RuleChain commentRuleChain
      • processingInstructionRuleChain

        protected RuleChain processingInstructionRuleChain
      • namespaceRuleChain

        protected RuleChain namespaceRuleChain
      • unnamedElementRuleChain

        protected RuleChain unnamedElementRuleChain
      • unnamedAttributeRuleChain

        protected RuleChain unnamedAttributeRuleChain
    • Constructor Detail

      • SimpleMode

        public SimpleMode​(StructuredQName modeName)
        Default constructor - creates a Mode containing no rules
        Parameters:
        modeName - the name of the mode
    • Method Detail

      • setBuiltInRuleSet

        public void setBuiltInRuleSet​(BuiltInRuleSet defaultRules)
        Set the built-in template rules to be used with this Mode in the case where there is no explicit template rule
        Parameters:
        defaultRules - the built-in rule set
      • getBuiltInRuleSet

        public BuiltInRuleSet getBuiltInRuleSet()
        Get the built-in template rules to be used with this Mode in the case where there is no explicit template rule
        Specified by:
        getBuiltInRuleSet in class Mode
        Returns:
        the built-in rule set, defaulting to the TextOnlyCopyRuleSet if no other rule set has been supplied
      • getActivePart

        public SimpleMode getActivePart()
        Get the active component of this mode. For a simple mode this is the mode itself; for a compound mode it is the "overriding" part
        Specified by:
        getActivePart in class Mode
      • resolveProperties

        public void resolveProperties​(RuleManager manager)
                               throws XPathException
        Check that the mode does not contain conflicting property values, and select property values if there were multiple xsl:mode declarations, possible at different import precedence
        Throws:
        XPathException - if there are conflicts
      • getLabel

        public java.lang.String getLabel()
        Get an identifier for the mode for use in error messages
        Returns:
        either the string "the unnamed mode" or the string "mode NNNN" where "NNNN" is the display form of the mode's name.
      • makeRuleSearchState

        protected RuleSearchState makeRuleSearchState​(RuleChain chain,
                                                      XPathContext context)
        Generate a search state for processing a given node
        Returns:
        a new object capable of holding the state of a search for a rule
      • isEmpty

        public boolean isEmpty()
        Ask whether there are any template rules in this mode (a mode could exist merely because it is referenced in apply-templates)
        Specified by:
        isEmpty in class Mode
        Returns:
        true if no template rules exist in this mode
      • setExplicitProperty

        public void setExplicitProperty​(java.lang.String name,
                                        java.lang.String value,
                                        int precedence)
        Set an explicit property at a particular precedence. Used for detecting conflicts
        Parameters:
        name - the name of the property
        value - the value of the property
        precedence - the import precedence of this property value
      • getPropertyValue

        public java.lang.String getPropertyValue​(java.lang.String name)
        Get the value of a property of this mode, e.g. the "typed" property
        Parameters:
        name - the property name, e.g. "typed"
        Returns:
        the property value
      • getExplicitNamespaces

        public java.util.Set<NamespaceUri> getExplicitNamespaces​(NamePool pool)
        Get the "explicit namespaces" matched by this mode. Returns a set containing all the namespaces matched by specific template rules in this mode
        Specified by:
        getExplicitNamespaces in class Mode
        Parameters:
        pool - the NamePool for the configuration
        Returns:
        the set of all namespace URIs of names explicitly matched by rules in this mode
      • addRule

        public void addRule​(Pattern pattern,
                            RuleTarget action,
                            StylesheetModule module,
                            int precedence,
                            double priority,
                            int position,
                            int part)
        Add a rule to the Mode.
        Parameters:
        pattern - a Pattern
        action - the Object to return from getRule() when the supplied node matches this Pattern
        module - the stylesheet module containing the rule
        precedence - the import precedence of the rule
        priority - the priority of the rule
        position - the relative position of the rule in declaration order. If two rules have the same position in declaration order, this indicates that they were formed by splitting a single rule whose pattern is a union pattern
        part - the relative position of a rule within a family of rules created by splitting a single rule governed by a union pattern. This is used where the splitting of the rule was mandated by the XSLT specification, that is, where there is no explicit priority specified. In cases where Saxon splits a rule for optimization reasons, the subrules will all have the same subsequence number.
      • makeRule

        public 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
        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
      • addRule

        public void addRule​(Pattern pattern,
                            Rule newRule)
      • addRuleToNamedOrUnnamedChain

        protected void addRuleToNamedOrUnnamedChain​(Rule newRule,
                                                    int fp,
                                                    RuleChain unnamedRuleChain,
                                                    IntHashMap<RuleChain> namedRuleChains)
      • allocatePatternSlots

        public void allocatePatternSlots​(int slots)
        Specify how many slots for local variables are required by a particular pattern
        Parameters:
        slots - the number of slots needed
      • getRule

        public Rule getRule​(Item item,
                            XPathContext context)
                     throws XPathException
        Get the rule corresponding to a given item, by finding the best pattern match.
        Specified by:
        getRule in class Mode
        Parameters:
        item - the item to be matched
        context - the XPath dynamic evaluation context
        Returns:
        the best matching rule, if any (otherwise null).
        Throws:
        XPathException - if an error occurs matching a pattern
      • getNamedRuleChain

        protected RuleChain getNamedRuleChain​(XPathContext c,
                                              int kind,
                                              NamespaceUri uri,
                                              java.lang.String local)
        Get a rule chain for a particular node name without allocating a fingerprint from the name pool
        Parameters:
        kind - the kind of node (element or attribute)
        uri - the namespace URI of the node
        local - the local name of the node
        Returns:
        the Rule at the head of the rule chain for nodes of this name, or null if there are no rules to consider
      • searchRuleChain

        protected Rule searchRuleChain​(Item item,
                                       XPathContext context,
                                       Rule bestRule,
                                       RuleChain chain)
                                throws XPathException
        Search a chain of rules
        Parameters:
        item - the item being matched
        context - XPath dynamic context
        bestRule - the best rule so far in terms of precedence and priority (may be null)
        chain - the chain to be searched
        Returns:
        the best match rule found in the chain, or the previous best rule, or null
        Throws:
        XPathException - if an error occurs matching a pattern
      • ruleMatches

        protected boolean ruleMatches​(Rule r,
                                      Item item,
                                      XPathContextMajor context,
                                      RuleSearchState pre)
                               throws XPathException
        Does this rule match the given item? Can be overridden
        Parameters:
        r - the rule to check
        item - the context item
        context - the static context for evaluation
        pre - 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
      • getRule

        public Rule getRule​(Item item,
                            XPathContext context,
                            java.util.function.Predicate<Rule> filter)
                     throws XPathException
        Get the rule corresponding to a given item, by finding the best Pattern match.
        Specified by:
        getRule in class Mode
        Parameters:
        item - the item to be matched
        context - the XPath dynamic evaluation context
        filter - a filter to select which rules should be considered
        Returns:
        the best matching rule, if any (otherwise null).
        Throws:
        XPathException - if an error occurs
      • searchRuleChain

        protected Rule searchRuleChain​(Item item,
                                       XPathContext context,
                                       Rule bestRule,
                                       RuleChain chain,
                                       RuleSearchState ruleSearchState,
                                       java.util.function.Predicate<Rule> filter)
                                throws XPathException
        Search a chain of rules
        Parameters:
        item - the item being matched
        context - XPath dynamic context
        bestRule - the best rule so far in terms of precedence and priority (may be null)
        chain - the chain to be searched
        ruleSearchState - An appropriate ruleState in this mode
        filter - filter used to select which rules are candidates to be searched
        Returns:
        the best match rule found in the chain, or the previous best rule, or null
        Throws:
        XPathException - if an error occurs while matching a pattern
      • reportAmbiguity

        protected void reportAmbiguity​(Item item,
                                       Rule r1,
                                       Rule r2,
                                       XPathContext c)
                                throws XPathException
        Report an ambiguity, that is, the situation where two rules of the same precedence and priority match the same node
        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
      • prepareStreamability

        public void prepareStreamability()
                                  throws XPathException
        Prepare for possible streamability - null here, but can be subclassed
        Throws:
        XPathException - if a failure occurs
      • allocateAllBindingSlots

        public void allocateAllBindingSlots​(StylesheetPackage pack)
        Allocate slot numbers to all the external component references in this component
        Overrides:
        allocateAllBindingSlots in class Actor
        Parameters:
        pack - the containing package
      • computeStreamability

        public void computeStreamability()
                                  throws XPathException
        Compute the streamability of all template rules. No action in Saxon-HE.
        Throws:
        XPathException
      • invertStreamableTemplates

        public void invertStreamableTemplates()
                                       throws XPathException
        For a streamable mode, invert all the templates to generate streamable code. No action in Saxon-HE.
        Throws:
        XPathException - if there is a non-streamable template in the mode
      • explainTemplateRules

        public void explainTemplateRules​(ExpressionPresenter out)
                                  throws XPathException
        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.
        Specified by:
        explainTemplateRules in class Mode
        Parameters:
        out - used to display the expression tree
        Throws:
        XPathException
      • exportTemplateRules

        public void exportTemplateRules​(ExpressionPresenter out)
                                 throws XPathException
        Export all template rules in this mode in a form that can be re-imported. Note that template rules with union patterns may have been split into multiple rules. We need to avoid outputting them more than once.
        Specified by:
        exportTemplateRules in class Mode
        Parameters:
        out - used to display the expression tree
        Throws:
        XPathException
      • processRules

        public void processRules​(Mode.RuleAction action)
                          throws XPathException
        Walk over all the rules, applying a specified action to each one.
        Specified by:
        processRules in class Mode
        Parameters:
        action - an action that is to be applied to all the rules in this Mode
        Throws:
        XPathException - if an error occurs processing any of the rules
      • processRules

        public void processRules​(Mode.RuleAction action,
                                 SimpleMode.RuleGroupAction group)
                          throws XPathException
        Walk over all the rules, applying a specified action to each one.
        Parameters:
        action - an action that is to be applied to all the rules in this Mode
        group - - actions to be performed at group start and group end
        Throws:
        XPathException - if an error occurs processing any of the rules
      • setGroup

        protected SimpleMode.RuleGroupAction setGroup​(SimpleMode.RuleGroupAction group,
                                                      java.lang.String type)
        Set the string associated with a rule group
        Parameters:
        group - the group action object
        type - the type of the rule group
        Returns:
        modified rulegroup action
      • processRuleChain

        public void processRuleChain​(RuleChain chain,
                                     Mode.RuleAction action)
                              throws XPathException
        Walk over all the rules, applying a specified action to each one.
        Parameters:
        action - an action that is to be applied to all the rules in this Mode
        Throws:
        XPathException - if an error occurs processing any of the rules
      • optimizeRules

        public void optimizeRules()
        Perform optimization on the complete set of rules comprising this Mode. This is a null operation in Saxon-HE.
      • getMaxPrecedence

        public int getMaxPrecedence()
        Description copied from class: Mode
        Get the maximum precedence of the rules in this mode
        Specified by:
        getMaxPrecedence in class Mode
      • computeRankings

        public void computeRankings​(int start)
                             throws XPathException
        Compute a rank for each rule, as a combination of the precedence and priority, to allow rapid comparison. This method also checks that there are no conflicts for property values in different xsl:mode declarations
        Specified by:
        computeRankings in class Mode
        Parameters:
        start - the lowest rank to use
        Throws:
        XPathException - if an error occurs processing the rules
      • getMaxRank

        public int getMaxRank()
        Description copied from class: Mode
        Get the highest rank of the rules in this mode
        Specified by:
        getMaxRank in class Mode
        Returns:
        the highest rank
      • allocateAllPatternSlots

        public void allocateAllPatternSlots()
        Allocate slots for local variables in all patterns used by the rules in this mode. Currently used only for accumulator rules
      • setStackFrameSlotsNeeded

        public void setStackFrameSlotsNeeded​(int slots)