Package net.sf.saxon.trans
Class SimpleMode
- java.lang.Object
-
- net.sf.saxon.expr.instruct.Actor
-
- net.sf.saxon.trans.Mode
-
- net.sf.saxon.trans.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSimpleMode.RuleGroupActionInterface used around a group of rules - principally at the group start and the group end-
Nested classes/interfaces inherited from class net.sf.saxon.trans.Mode
Mode.RuleAction, Mode.RuleFilter
-
-
Field Summary
Fields Modifier and Type Field Description protected RuleChainatomicValueRuleChainprotected RuleChaincommentRuleChainprotected RuleChaindocumentRuleChainprotected RuleChainfunctionItemRuleChainprotected RuleChaingenericRuleChainprotected IntHashMap<RuleChain>namedAttributeRuleChainsprotected IntHashMap<RuleChain>namedElementRuleChainsprotected RuleChainnamespaceRuleChainprotected RuleChainprocessingInstructionRuleChainprotected java.util.Map<StructuredQName,RuleChain>qNamedAttributeRuleChainsprotected java.util.Map<StructuredQName,RuleChain>qNamedElementRuleChainsprotected RuleChaintextRuleChainprotected RuleChainunnamedAttributeRuleChainprotected RuleChainunnamedElementRuleChain-
Fields inherited from class net.sf.saxon.trans.Mode
DEFAULT_MODE_NAME, modeName, mustBeTyped, mustBeUntyped, OMNI_MODE, RECOVER_WITH_WARNINGS, UNNAMED_MODE_NAME
-
-
Constructor Summary
Constructors Constructor Description SimpleMode(StructuredQName modeName)Default constructor - creates a Mode containing no rules
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRule(Pattern pattern, Rule newRule)voidaddRule(Pattern pattern, RuleTarget action, StylesheetModule module, int precedence, double priority, int position, int part)Add a rule to the Mode.protected voidaddRuleToNamedOrUnnamedChain(Rule newRule, int fp, RuleChain unnamedRuleChain, IntHashMap<RuleChain> namedRuleChains)voidallocateAllBindingSlots(StylesheetPackage pack)Allocate slot numbers to all the external component references in this componentvoidallocateAllPatternSlots()Allocate slots for local variables in all patterns used by the rules in this mode.voidallocatePatternSlots(int slots)Specify how many slots for local variables are required by a particular patternvoidcheckForConflictingProperties(RuleManager manager)Check that the mode does not contain conflicting property valuesvoidcomputeRankings(int start)Compute a rank for each rule, as a combination of the precedence and priority, to allow rapid comparison.voidcomputeStreamability()Compute the streamability of all template rules.static voidcopyRules(SimpleMode from, SimpleMode to)Construct a new Mode, copying the contents of an existing ModevoidexplainTemplateRules(ExpressionPresenter out)Explain all template rules in this mode by showing their expression tree represented in XML.voidexportTemplateRules(ExpressionPresenter out)Export all template rules in this mode in a form that can be re-imported.static voidforceAllocateAllBindingSlots(StylesheetPackage pack, SimpleMode mode, java.util.List<ComponentBinding> bindings)SimpleModegetActivePart()Get the active component of this mode.BuiltInRuleSetgetBuiltInRuleSet()Get the built-in template rules to be used with this Mode in the case where there is no explicit template rulejava.util.Set<java.lang.String>getExplicitNamespaces(NamePool pool)Get the "explicit namespaces" matched by this mode.java.lang.StringgetLabel()Get an identifier for the mode for use in error messagesintgetMaxPrecedence()Get the maximum precedence of the rules in this modeintgetMaxRank()Get the highest rank of the rules in this modeprotected RuleChaingetNamedRuleChain(XPathContext c, int kind, java.lang.String uri, java.lang.String local)Get a rule chain for a particular node name without allocating a fingerprint from the name pooljava.lang.StringgetPropertyValue(java.lang.String name)Get the value of a property of this mode, e.g.RulegetRule(Item item, XPathContext context)Get the rule corresponding to a given item, by finding the best pattern match.RulegetRule(Item item, XPathContext context, Mode.RuleFilter filter)Get the rule corresponding to a given item, by finding the best Pattern match.intgetStackFrameSlotsNeeded()voidinvertStreamableTemplates()For a streamable mode, invert all the templates to generate streamable code.booleanisEmpty()Ask whether there are any template rules in this mode (a mode could exist merely because it is referenced in apply-templates)RulemakeRule(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 rulesprotected RuleSearchStatemakeRuleSearchState(RuleChain chain, XPathContext context)Generate a search state for processing a given nodevoidoptimizeRules()Perform optimization on the complete set of rules comprising this Mode.voidprepareStreamability()Prepare for possible streamability - null here, but can be subclassedvoidprocessRuleChain(RuleChain chain, Mode.RuleAction action)Walk over all the rules, applying a specified action to each one.voidprocessRuleChain(RuleChain chain, Mode.RuleAction action, SimpleMode.RuleGroupAction group)voidprocessRuleChains(IntHashMap<RuleChain> chains, Mode.RuleAction action, SimpleMode.RuleGroupAction group)voidprocessRules(Mode.RuleAction action)Walk over all the rules, applying a specified action to each one.voidprocessRules(Mode.RuleAction action, SimpleMode.RuleGroupAction group)Walk over all the rules, applying a specified action to each one.protected voidreportAmbiguity(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 nodeprotected booleanruleMatches(Rule r, Item item, XPathContextMajor context, RuleSearchState pre)Does this rule match the given item? Can be overriddenprotected RulesearchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain)Search a chain of rulesprotected RulesearchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain, RuleSearchState ruleSearchState, Mode.RuleFilter filter)Search a chain of rulesvoidsetBuiltInRuleSet(BuiltInRuleSet defaultRules)Set the built-in template rules to be used with this Mode in the case where there is no explicit template rulevoidsetExplicitProperty(java.lang.String name, java.lang.String value, int precedence)Set an explicit property at a particular precedence.protected SimpleMode.RuleGroupActionsetGroup(SimpleMode.RuleGroupAction group, java.lang.String type)Set the string associated with a rule groupvoidsetStackFrameSlotsNeeded(int slots)-
Methods inherited from class net.sf.saxon.trans.Mode
applyTemplates, explain, export, exportUseAccumulators, 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
-
-
-
-
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
-
namedElementRuleChains
protected IntHashMap<RuleChain> namedElementRuleChains
-
namedAttributeRuleChains
protected IntHashMap<RuleChain> namedAttributeRuleChains
-
qNamedElementRuleChains
protected java.util.Map<StructuredQName,RuleChain> qNamedElementRuleChains
-
qNamedAttributeRuleChains
protected java.util.Map<StructuredQName,RuleChain> qNamedAttributeRuleChains
-
-
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:
getBuiltInRuleSetin classMode- 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:
getActivePartin classMode
-
checkForConflictingProperties
public void checkForConflictingProperties(RuleManager manager) throws XPathException
Check that the mode does not contain conflicting property values- Parameters:
manager- the containing RuleManager- 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.
-
copyRules
public static void copyRules(SimpleMode from, SimpleMode to)
Construct a new Mode, copying the contents of an existing Mode- Parameters:
from- the existing mode.to- the name of the new mode to be created
-
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)
-
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 propertyvalue- the value of the propertyprecedence- 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<java.lang.String> 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:
getExplicitNamespacesin classMode- 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 Patternaction- the Object to return from getRule() when the supplied node matches this Patternmodule- the stylesheet module containing the ruleprecedence- the import precedence of the rulepriority- the priority of the ruleposition- 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 patternpart- 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 matchesaction- the object invoked by this rule (usually a Template)precedence- the precedence of the ruleminImportPrecedence- the minimum import precedence for xsl:apply-importspriority- the priority of the rulesequence- a sequence number for ordering of rulespart- distinguishes rules formed by splitting a rule on a union pattern- Returns:
- the newly created rule
-
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:
getRulein classMode- 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
-
getNamedRuleChain
protected RuleChain getNamedRuleChain(XPathContext c, int kind, java.lang.String 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 nodelocal- 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 matchedcontext- XPath dynamic contextbestRule- 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 checkitem- the context itemcontext- the static context for evaluationpre- 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, Mode.RuleFilter filter) throws XPathException
Get the rule corresponding to a given item, by finding the best Pattern match.- Specified by:
getRulein classMode- 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
-
searchRuleChain
protected Rule searchRuleChain(Item item, XPathContext context, Rule bestRule, RuleChain chain, RuleSearchState ruleSearchState, Mode.RuleFilter filter) throws XPathException
Search a chain of rules- Parameters:
item- the item being matchedcontext- XPath dynamic contextbestRule- the best rule so far in terms of precedence and priority (may be null)chain- the chain to be searchedruleSearchState- An appropriate ruleState in this modefilter- 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 rulesr1- The first rule that the node matchesr2- The second rule that the node matchesc- 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 XPathExceptionPrepare 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:
allocateAllBindingSlotsin classActor- Parameters:
pack- the containing package
-
forceAllocateAllBindingSlots
public static void forceAllocateAllBindingSlots(StylesheetPackage pack, SimpleMode mode, java.util.List<ComponentBinding> bindings)
-
computeStreamability
public void computeStreamability() throws XPathExceptionCompute the streamability of all template rules. No action in Saxon-HE.- Throws:
XPathException
-
invertStreamableTemplates
public void invertStreamableTemplates() throws XPathExceptionFor 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:
explainTemplateRulesin classMode- 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:
exportTemplateRulesin classMode- 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:
processRulesin classMode- 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 Modegroup- - 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 objecttype- the type of the rule group- Returns:
- modified rulegroup action
-
processRuleChains
public void processRuleChains(IntHashMap<RuleChain> chains, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
- Throws:
XPathException
-
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
-
processRuleChain
public void processRuleChain(RuleChain chain, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
- Throws:
XPathException
-
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:ModeGet the maximum precedence of the rules in this mode- Specified by:
getMaxPrecedencein classMode
-
computeRankings
public void computeRankings(int start) throws XPathExceptionCompute 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:
computeRankingsin classMode- Parameters:
start- the lowest rank to use- Throws:
XPathException- if an error occurs processing the rules
-
getMaxRank
public int getMaxRank()
Description copied from class:ModeGet the highest rank of the rules in this mode- Specified by:
getMaxRankin classMode- 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
-
getStackFrameSlotsNeeded
public int getStackFrameSlotsNeeded()
- Specified by:
getStackFrameSlotsNeededin classMode
-
setStackFrameSlotsNeeded
public void setStackFrameSlotsNeeded(int slots)
-
-