Package net.sf.saxon.trans
Class Mode
java.lang.Object
net.sf.saxon.expr.instruct.Actor
net.sf.saxon.trans.Mode
- All Implemented Interfaces:
SourceLocator
,ExpressionOwner
,Location
,Locator
- Direct Known Subclasses:
CompoundMode
,SimpleMode
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface for helper classes used to process all the rules in the Modestatic interface
Interface for helper classes used to filter a chain of rules -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StructuredQName
protected StructuredQName
boolean
boolean
static final StructuredQName
static final int
static final StructuredQName
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyTemplates
(ParameterSet parameters, ParameterSet tunnelParameters, NodeInfo separator, Outputter output, XPathContextMajor context, Location locationId) Process selected nodes using the template rules registered for this mode.abstract void
computeRankings
(int start) Compute a rank for each rule, as a combination of the precedence and priority, to allow rapid comparison.void
explain
(ExpressionPresenter presenter) abstract void
Explain all template rules in this mode in a form that can be re-imported.final void
export
(ExpressionPresenter presenter) Export expression structure.abstract void
Export all template rules in this mode in a form that can be re-imported.protected void
exportUseAccumulators
(ExpressionPresenter presenter) Set
<? extends Accumulator> Get the list of accumulators declared on the xsl:mode/@use-accumulators attributeabstract SimpleMode
Get the active component of this mode.abstract BuiltInRuleSet
Get the built-in template rules to be used with this Mode in the case where there is no explicit template ruleReturn a built-in rule set for a code string.getCodeForBuiltInRuleSet
(BuiltInRuleSet builtInRuleSet) Return a code string for a built-in rule set.abstract Set
<NamespaceUri> Get the "explicit namespaces" matched by this mode.abstract int
Get the maximum precedence of the rules in this modeabstract int
Get the highest rank of the rules in this modeGet the name of the mode (for diagnostics only)getModeTitle
(boolean initialCaps) Get a title for the mode: either "Mode mode-name" or "The unnamed mode" as appropriategetNextMatchRule
(Item item, Rule currentRule, XPathContext context) Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.Get the policy for handling recoverable errors.getRule
(Item item, int min, int max, XPathContext context) Get the rule corresponding to a given Node, by finding the best Pattern match, subject to a minimum and maximum precedence.abstract Rule
getRule
(Item item, XPathContext context) Get the rule corresponding to a given item, by finding the best pattern match.abstract Rule
getRule
(Item item, XPathContext context, Predicate<Rule> filter) Get the rule corresponding to a given item, by finding the best Pattern match.abstract int
Get the symbolic name of the componentboolean
Ask whether this mode is declared to be streamableabstract boolean
isEmpty()
Ask whether there are any template rules in this mode (a mode could exist merely because it is referenced in apply-templates)boolean
Ask whether this is an enclosing mode (4.0 feature)boolean
boolean
boolean
Determine if this is the unnamed modemakeNewContext
(XPathContext context) Make a new XPath context for evaluating patterns if there is any possibility that the pattern uses local variablesabstract void
processRules
(Mode.RuleAction action) Walk over all the rules, applying a specified action to each one.void
setAccumulators
(Set<? extends Accumulator> accumulators) Set the list of accumulators declared on the xsl:mode/@use-accumulators attributevoid
void
setEnclosingMode
(boolean enclosing) Say whether this is an enclosing mode (4.0 feature)void
setHasRules
(boolean hasRules) void
setModeTracing
(boolean tracing) Switch tracing on or offvoid
setRecoveryPolicy
(RecoveryPolicy policy) Set the policy for handling recoverable errors.void
setStreamable
(boolean streamable) Say that this mode is (or is not) streamableMethods inherited from class net.sf.saxon.expr.instruct.Actor
allocateAllBindingSlots, allocateBindingSlotsRecursive, getBody, getChildExpression, getColumnNumber, getComponentName, getDeclaredVisibility, getLineNumber, getLocation, getPackageData, getProperty, getPublicId, getRetainedStaticContext, getStackFrameMap, getSystemId, getTracingTag, isExportable, makeDeclaringComponent, obtainDeclaringComponent, process, saveLocation, setBody, setChildExpression, setColumnNumber, setDeclaredVisibility, setDeclaringComponent, setLineNumber, setPackageData, setRetainedStaticContext, setStackFrameMap, setSystemId
-
Field Details
-
OMNI_MODE_NAME
-
UNNAMED_MODE_NAME
-
DEFAULT_MODE_NAME
-
modeName
-
RECOVER_WITH_WARNINGS
public static final int RECOVER_WITH_WARNINGS- See Also:
-
mustBeTyped
public boolean mustBeTyped -
mustBeUntyped
public boolean mustBeUntyped
-
-
Constructor Details
-
Mode
-
-
Method Details
-
getDeclaringComponent
- Overrides:
getDeclaringComponent
in classActor
-
getBuiltInRuleSet
Get the built-in template rules to be used with this Mode in the case where there is no explicit template rule- Returns:
- the built-in rule set, defaulting to the TextOnlyCopyRuleSet if no other rule set has been supplied
-
isUnnamedMode
public boolean isUnnamedMode()Determine if this is the unnamed mode- Returns:
- true if this is the unnamed mode
-
getModeName
Get the name of the mode (for diagnostics only)- Returns:
- the mode name. Null for the default (unnamed) mode
-
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 -
getMaxPrecedence
public abstract int getMaxPrecedence()Get the maximum precedence of the rules in this mode -
getMaxRank
public abstract int getMaxRank()Get the highest rank of the rules in this mode- Returns:
- the highest rank
-
computeRankings
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- Parameters:
start
- the lowest rank to use- Throws:
XPathException
- if an error occurs processing the rules
-
getModeTitle
Get a title for the mode: either "Mode mode-name" or "The unnamed mode" as appropriate- Parameters:
initialCaps
- true if the first letter should be upper case- Returns:
- a title for the mode
-
setModeTracing
public void setModeTracing(boolean tracing) Switch tracing on or off -
isModeTracing
public boolean isModeTracing() -
getAccumulators
Get the list of accumulators declared on the xsl:mode/@use-accumulators attribute- Returns:
- the list of accumulators applicable when this is the initial mode
-
setAccumulators
Set the list of accumulators declared on the xsl:mode/@use-accumulators attribute- Parameters:
accumulators
- the list of accumulators applicable when this is the initial mode
-
getSymbolicName
Description copied from class:Actor
Get the symbolic name of the component- Specified by:
getSymbolicName
in classActor
- Returns:
- the symbolic name
-
getObjectName
-
isEmpty
public abstract boolean isEmpty()Ask whether there are any template rules in this mode (a mode could exist merely because it is referenced in apply-templates)- Returns:
- true if no template rules exist in this mode
-
setEnclosingMode
public void setEnclosingMode(boolean enclosing) Say whether this is an enclosing mode (4.0 feature)- Parameters:
enclosing
- true if this is an enclosing mode
-
isEnclosingMode
public boolean isEnclosingMode()Ask whether this is an enclosing mode (4.0 feature)- Returns:
- true if this is an enclosing mode
-
setRecoveryPolicy
Set the policy for handling recoverable errors. Note that for some errors the decision can be made at run-time, but for the "ambiguous template match" error, the decision is (since 9.2) fixed at compile time.- Parameters:
policy
- the recovery policy to be used.
-
setHasRules
public void setHasRules(boolean hasRules) -
getRecoveryPolicy
Get the policy for handling recoverable errors. Note that for some errors the decision can be made at run-time, but for the "ambiguous template match" error, the decision is (since 9.2) fixed at compile time.- Returns:
- the current policy.
-
setStreamable
public void setStreamable(boolean streamable) Say that this mode is (or is not) streamable- Parameters:
streamable
- true if this mode is a streamable mode
-
isDeclaredStreamable
public boolean isDeclaredStreamable()Ask whether this mode is declared to be streamable- Returns:
- true if this mode is declared with the option streamable="yes"
-
getExplicitNamespaces
Get the "explicit namespaces" matched by this mode. Returns a set containing all the namespaces matched by specific template rules in this mode- Parameters:
pool
- the NamePool for the configuration- Returns:
- the set of all namespace URIs of names explicitly matched by rules in this mode
-
setDefaultResultType
-
getDefaultResultType
-
processRules
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
-
makeNewContext
Make a new XPath context for evaluating patterns if there is any possibility that the pattern uses local variables- Parameters:
context
- The existing XPath context- Returns:
- a new XPath context
-
getRule
Get the rule corresponding to a given item, by finding the best pattern match.- Parameters:
item
- the item to be matchedcontext
- the XPath dynamic evaluation context- Returns:
- the best matching rule, if any (otherwise null).
- Throws:
XPathException
- if an error occurs matching a pattern
-
getRule
public abstract Rule getRule(Item item, XPathContext context, Predicate<Rule> filter) throws XPathException Get the rule corresponding to a given item, by finding the best Pattern match.- Parameters:
item
- the item to be matchedcontext
- the XPath dynamic evaluation contextfilter
- a filter to select which rules should be considered- Returns:
- the best matching rule, if any (otherwise null).
- Throws:
XPathException
- if an error occurs
-
getRule
Get the rule corresponding to a given Node, by finding the best Pattern match, subject to a minimum and maximum precedence. (This supports xsl:apply-imports)- Parameters:
item
- the item to be matchedmin
- the minimum import precedencemax
- the maximum import precedencecontext
- the XPath dynamic evaluation context- Returns:
- the Rule registered for that node, if any (otherwise null).
- Throws:
XPathException
- if an error occurs evaluating match patterns
-
getNextMatchRule
public Rule getNextMatchRule(Item item, Rule currentRule, XPathContext context) throws XPathException Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.- Parameters:
item
- the NodeInfo referring to the node to be matchedcurrentRule
- the current rule; we are looking for the next match after the current rulecontext
- the XPath dynamic evaluation context- Returns:
- the object (e.g. a NodeHandler) registered for that element, if any (otherwise null).
- Throws:
XPathException
- if an error occurs matching a pattern
-
exportTemplateRules
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.- Parameters:
out
- used to display the expression tree- Throws:
XPathException
-
explainTemplateRules
Explain 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.- Parameters:
out
- used to display the expression tree- Throws:
XPathException
-
applyTemplates
public TailCall applyTemplates(ParameterSet parameters, ParameterSet tunnelParameters, NodeInfo separator, Outputter output, XPathContextMajor context, Location locationId) throws XPathException Process selected nodes using the template rules registered for this mode.- Parameters:
parameters
- A ParameterSet containing the parameters to the handler/template being invoked. Specify null if there are no parameters.tunnelParameters
- A ParameterSet containing the parameters to the handler/template being invoked. Specify null if there are no parameters.separator
- Text node to be inserted between the output of successive input items; may be nulloutput
- The destination for the result of the selected templatescontext
- A newly-created context object (this must be freshly created by the caller, as it will be modified by this method). The nodes to be processed are those selected by the currentIterator in this context object. There is also a precondition that this mode must be the current mode in this context object.locationId
- location of this apply-templates instruction in the stylesheet- Returns:
- a TailCall returned by the last template to be invoked, or null, indicating that there are no outstanding tail calls.
- Throws:
XPathException
- if any dynamic error occurs
-
getStackFrameSlotsNeeded
public abstract int getStackFrameSlotsNeeded() -
getCodeForBuiltInRuleSet
Return a code string for a built-in rule set. This can be specialised in subclasses for PE/EE- Parameters:
builtInRuleSet
- the rule set to get a code- Returns:
- a simple string code or "???" if the ruleset is unknown
-
getBuiltInRuleSetForCode
Return a built-in rule set for a code string.- Parameters:
code
- the code used in export- Returns:
- a suitable ruleset
-
export
Description copied from class:Actor
Export expression structure. The abstract expression tree is written to the supplied outputstream.- Specified by:
export
in classActor
- Parameters:
presenter
- the expression presenter used to generate the XML representation of the structure- Throws:
XPathException
- if things go wrong, for example an I/O failure
-
exportUseAccumulators
-
isMustBeTyped
public boolean isMustBeTyped() -
explain
- Throws:
XPathException
-