net.sf.saxon.trans

Class Mode

public class Mode extends Object implements Serializable

A Mode is a collection of rules; the selection of a rule to apply to a given element is determined by a Pattern.

Author: Michael H. Kay

Field Summary
static StructuredQNameALL_MODES
static intDEFAULT_MODE
static StructuredQNameDEFAULT_MODE_NAME
static intNAMED_MODE
static intSTRIPPER_MODE
Constructor Summary
Mode(int usage, StructuredQName modeName)
Default constructor - creates a Mode containing no rules
Mode(Mode omniMode, StructuredQName modeName)
Construct a new Mode, copying the contents of an existing Mode
Method Summary
voidaddRule(Pattern pattern, RuleTarget action, int precedence, double priority, boolean explicitMode)
Add a rule to the Mode.
voidallocatePatternSlots(int slots)
Specify how many slots for local variables are required by a particular pattern
voidcomputeRankings()
Compute a rank for each rule, as a combination of the precedence and priority, to allow rapid comparison.
voidexplainTemplateRules(ExpressionPresenter presenter)
Explain all template rules in this mode by showing their expression tree represented in XML.
StructuredQNamegetModeName()
Get the name of the mode (for diagnostics only)
RulegetNextMatchRule(NodeInfo node, Rule currentRule, XPathContext context)
Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.
intgetRecoveryPolicy()
Get the policy for handling recoverable errors.
RulegetRule(NodeInfo node, XPathContext context)
Get the rule corresponding to a given Node, by finding the best Pattern match.
RulegetRule(NodeInfo node, XPathContext context, Mode.RuleFilter filter)
Get the rule corresponding to a given Node, by finding the best Pattern match.
RulegetRule(NodeInfo node, 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.
voidinvertStreamableTemplates(Optimizer opt)
For a streamable mode, invert all the templates to generate streamable code
booleanisDefaultMode()
Determine if this is the default mode
booleanisEmpty()
Ask whether there are any template rules in this mode (a mode could exist merely because it is referenced in apply-templates)
booleanisStreamable()
Ask whether this mode is streamable
voidprocessRules(Mode.RuleAction action)
Walk over all the rules, applying a specified action to each one.
voidsetRecoveryPolicy(int policy)
Set the policy for handling recoverable errrors.
voidsetStreamable(boolean streamable)
Say that this mode is (or is not) streamable

Field Detail

ALL_MODES

public static final StructuredQName ALL_MODES

DEFAULT_MODE

public static final int DEFAULT_MODE

DEFAULT_MODE_NAME

public static final StructuredQName DEFAULT_MODE_NAME

NAMED_MODE

public static final int NAMED_MODE

STRIPPER_MODE

public static final int STRIPPER_MODE

Constructor Detail

Mode

public Mode(int usage, StructuredQName modeName)
Default constructor - creates a Mode containing no rules

Parameters: usage one of DEFAULT_MODE, NAMED_MODE, STRIPPER_MODE modeName the name of the mode

Mode

public Mode(Mode omniMode, StructuredQName modeName)
Construct a new Mode, copying the contents of an existing Mode

Parameters: omniMode the existing mode. May be null, in which case it is not copied modeName the name of the new mode to be created

Method Detail

addRule

public void addRule(Pattern pattern, RuleTarget action, int precedence, double priority, boolean explicitMode)
Add a rule to the Mode.

Parameters: pattern a Pattern action the Object to return from getRule() when the supplied node matches this Pattern precedence the import precedence of the rule priority the explicit or implicit priority of the rule explicitMode true if adding a template rule for a specific (default or named) mode; false if adding a rule because it applies to all modes

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

computeRankings

public void computeRankings()
Compute a rank for each rule, as a combination of the precedence and priority, to allow rapid comparison.

explainTemplateRules

public void explainTemplateRules(ExpressionPresenter presenter)
Explain all template rules in this mode by showing their expression tree represented in XML.

Parameters: presenter used to display the expression tree

getModeName

public StructuredQName getModeName()
Get the name of the mode (for diagnostics only)

Returns: the mode name. Null for the default (unnamed) mode

getNextMatchRule

public Rule getNextMatchRule(NodeInfo node, Rule currentRule, XPathContext context)
Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.

Parameters: node the NodeInfo referring to the node to be matched currentRule the current rule; we are looking for the next match after the current rule context the XPath dynamic evaluation context

Returns: the object (e.g. a NodeHandler) registered for that element, if any (otherwise null).

getRecoveryPolicy

public int 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.

getRule

public Rule getRule(NodeInfo node, XPathContext context)
Get the rule corresponding to a given Node, by finding the best Pattern match.

Parameters: node the NodeInfo referring to the node to be matched context the XPath dynamic evaluation context

Returns: the best matching rule, if any (otherwise null).

getRule

public Rule getRule(NodeInfo node, XPathContext context, Mode.RuleFilter filter)
Get the rule corresponding to a given Node, by finding the best Pattern match.

Parameters: node the NodeInfo referring to the node to be matched context the XPath dynamic evaluation context

Returns: the best matching rule, if any (otherwise null).

getRule

public Rule getRule(NodeInfo node, 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. (This supports xsl:apply-imports)

Parameters: node the NodeInfo referring to the node to be matched min the minimum import precedence max the maximum import precedence context the XPath dynamic evaluation context

Returns: the Rule registered for that node, if any (otherwise null).

invertStreamableTemplates

public void invertStreamableTemplates(Optimizer opt)
For a streamable mode, invert all the templates to generate streamable code

isDefaultMode

public boolean isDefaultMode()
Determine if this is the default mode

Returns: true if this is the default (unnamed) mode

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)

Returns: true if no template rules exist in this mode

isStreamable

public boolean isStreamable()
Ask whether this mode is streamable

Returns: true if this mode is streamable

processRules

public void processRules(Mode.RuleAction action)
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

setRecoveryPolicy

public void setRecoveryPolicy(int policy)
Set the policy for handling recoverable errrors. 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. The options are RECOVER_SILENTLY, RECOVER_WITH_WARNINGS, or DO_NOT_RECOVER.

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