public class SimpleMode extends Mode
Modifier and Type | Class and Description |
---|---|
static interface |
SimpleMode.RuleGroupAction
Interface used around a group of rules - principally at the
group start and the group end
|
Mode.RuleAction, Mode.RuleFilter
Modifier and Type | Field and Description |
---|---|
protected Rule |
atomicValueRuleChain |
protected Rule |
commentRuleChain |
protected Rule |
documentRuleChain |
protected Rule |
functionItemRuleChain |
protected Rule |
genericRuleChain |
protected IntHashMap<Rule> |
namedAttributeRuleChains |
protected IntHashMap<Rule> |
namedElementRuleChains |
protected Rule |
namespaceRuleChain |
protected Rule |
processingInstructionRuleChain |
protected Map<StructuredQName,Rule> |
qNamedAttributeRuleChains |
protected Map<StructuredQName,Rule> |
qNamedElementRuleChains |
protected Rule |
textRuleChain |
protected Rule |
unnamedAttributeRuleChain |
protected Rule |
unnamedElementRuleChain |
DEFAULT_MODE_NAME, hasRules, modeName, mustBeTyped, mustBeUntyped, OMNI_MODE, UNNAMED_MODE_NAME
body
Constructor and Description |
---|
SimpleMode(StructuredQName modeName)
Default constructor - creates a Mode containing no rules
|
Modifier and Type | Method and Description |
---|---|
void |
addRule(Pattern pattern,
Rule newRule) |
void |
addRule(Pattern pattern,
RuleTarget action,
StylesheetModule module,
int precedence,
double priority,
boolean explicitMode)
Add a rule to the Mode.
|
void |
allocateAllBindingSlots(StylesheetPackage pack)
Allocate slot numbers to all the external component references in this component
|
void |
allocateAllPatternSlots()
Allocate slots for local variables in all patterns used by the rules in this mode.
|
void |
allocatePatternSlots(int slots)
Specify how many slots for local variables are required by a particular pattern
|
void |
checkForConflictingProperties()
Check that the mode does not contain conflicting property values
|
void |
computeRankings(int start)
Compute a rank for each rule, as a combination of the precedence and priority, to allow
rapid comparison.
|
void |
computeStreamability()
Compute the streamability of all template rules.
|
static void |
copyRules(SimpleMode from,
SimpleMode to)
Construct a new Mode, copying the contents of an existing Mode
|
void |
explainTemplateRules(ExpressionPresenter out)
Explain all template rules in this mode by showing their
expression tree represented in XML.
|
void |
exportTemplateRules(ExpressionPresenter out)
Export all template rules in this mode in a form that can be re-imported.
|
static void |
forceAllocateAllBindingSlots(StylesheetPackage pack,
SimpleMode mode,
List<ComponentBinding> bindings) |
SimpleMode |
getActivePart()
Get the active component of this mode.
|
BuiltInRuleSet |
getBuiltInRuleSet()
Get the built-in template rules to be used with this Mode in the case where there is no
explicit template rule
|
Set<String> |
getExplicitNamespaces(NamePool pool)
Get the "explicit namespaces" matched by this mode.
|
int |
getMaxPrecedence()
Get the maximum precedence of the rules in this mode
|
int |
getMaxRank()
Get the highest rank of the rules in this mode
|
protected Rule |
getNamedRuleChain(XPathContext c,
int kind,
String uri,
String local)
Get a rule chain for a particular node name without allocating a fingerprint from the name pool
|
String |
getPropertyValue(String name)
Get the value of a property of this mode, e.g.
|
Rule |
getRule(Item item,
XPathContext context)
Get the rule corresponding to a given item, by finding the best pattern match.
|
Rule |
getRule(Item item,
XPathContext context,
Mode.RuleFilter filter)
Get the rule corresponding to a given item, by finding the best Pattern match.
|
int |
getStackFrameSlotsNeeded() |
void |
invertStreamableTemplates()
For a streamable mode, invert all the templates to generate streamable code.
|
boolean |
isEmpty()
Ask whether there are any template rules in this mode
(a mode could exist merely because it is referenced in apply-templates)
|
Rule |
makeRule(Pattern pattern,
RuleTarget action,
int precedence,
int minImportPrecedence,
double priority,
int sequence)
Generate a new rule - so it can be overridden to make more specialist rules
|
protected RuleSearchState |
makeRuleSearchState()
Generate a search state for processing a given node
|
void |
optimizeRules() |
void |
prepareStreamability()
Prepare for possible streamability - null here, but can be subclassed
|
void |
processRuleChain(Rule r,
Mode.RuleAction action)
Walk over all the rules, applying a specified action to each one.
|
void |
processRuleChain(Rule r,
Mode.RuleAction action,
SimpleMode.RuleGroupAction group) |
void |
processRuleChains(IntHashMap<Rule> chains,
Mode.RuleAction action,
SimpleMode.RuleGroupAction group) |
void |
processRules(Mode.RuleAction action)
Walk over all the rules, applying a specified action to each one.
|
void |
processRules(Mode.RuleAction action,
SimpleMode.RuleGroupAction group)
Walk over all the rules, applying a specified action to each one.
|
protected 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 pre)
Does this rule match the given item? Can be overridden
|
protected Rule |
searchRuleChain(Item item,
XPathContext context,
Rule bestRule,
Rule head,
RuleSearchState ruleSearchState)
Search a chain of rules
|
protected Rule |
searchRuleChain(Item item,
XPathContext context,
Rule bestRule,
Rule head,
RuleSearchState ruleSearchState,
Mode.RuleFilter filter)
Search a chain of rules
|
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
|
void |
setExplicitProperty(String name,
String value,
int precedence)
Set an explicit property at a particular precedence.
|
protected SimpleMode.RuleGroupAction |
setGroup(SimpleMode.RuleGroupAction group,
String type)
Set the string associated with a rule group
|
void |
setStackFrameSlotsNeeded(int slots) |
applyTemplates, explain, export, getBuiltInRuleSetForCode, getCodeForBuiltInRuleSet, getComponentKind, getConstructType, getModeName, getModeTitle, getNextMatchRule, getObjectName, getRecoveryPolicy, getRule, getSymbolicName, isDeclaredStreamable, isUnnamedMode, makeNewContext, makeNewContextIfNeeded, setRecoveryPolicy, setStreamable
allocateBindingSlotsRecursive, getBody, getColumnNumber, getDeclaredVisibility, getDeclaringComponent, getLineNumber, getLocation, getPackageData, getProperties, getProperty, getPublicId, getRetainedStaticContext, getStackFrameMap, getSystemId, makeDeclaringComponent, saveLocation, setBody, setDeclaredVisibility, setDeclaringComponent, setLineNumber, setPackageData, setRetainedStaticContext, setStackFrameMap, setSystemId
protected Rule genericRuleChain
protected Rule atomicValueRuleChain
protected Rule functionItemRuleChain
protected Rule documentRuleChain
protected Rule textRuleChain
protected Rule commentRuleChain
protected Rule processingInstructionRuleChain
protected Rule namespaceRuleChain
protected Rule unnamedElementRuleChain
protected Rule unnamedAttributeRuleChain
protected IntHashMap<Rule> namedElementRuleChains
protected IntHashMap<Rule> namedAttributeRuleChains
protected Map<StructuredQName,Rule> qNamedElementRuleChains
protected Map<StructuredQName,Rule> qNamedAttributeRuleChains
public SimpleMode(StructuredQName modeName)
modeName
- the name of the modepublic void setBuiltInRuleSet(BuiltInRuleSet defaultRules)
defaultRules
- the built-in rule setpublic BuiltInRuleSet getBuiltInRuleSet()
getBuiltInRuleSet
in class Mode
public SimpleMode getActivePart()
getActivePart
in class Mode
public void checkForConflictingProperties() throws XPathException
XPathException
- if there are conflictspublic static void copyRules(SimpleMode from, SimpleMode to)
from
- the existing mode.to
- the name of the new mode to be createdprotected RuleSearchState makeRuleSearchState()
public boolean isEmpty()
public void setExplicitProperty(String name, String value, int precedence)
name
- the name of the propertyvalue
- the value of the propertyprecedence
- the import precedence of this property valuepublic String getPropertyValue(String name)
name
- the property name, e.g. "typed"public Set<String> getExplicitNamespaces(NamePool pool)
getExplicitNamespaces
in class Mode
pool
- the NamePool for the configurationpublic void addRule(Pattern pattern, RuleTarget action, StylesheetModule module, int precedence, double priority, boolean explicitMode)
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 ruleexplicitMode
- true if adding a template rule for a specific (default or named) mode;public Rule makeRule(Pattern pattern, RuleTarget action, int precedence, int minImportPrecedence, double priority, int sequence)
pattern
- the pattern that this rule matchesaction
- the object invoked by this rule (usually a Template)precedence
- the precedence of the ruleminImportPrecedence
- the minumum import precedence for xsl:apply-importspriority
- the priority of the rulesequence
- a sequence number for ordering of rulespublic void allocatePatternSlots(int slots)
slots
- the number of slots neededpublic Rule getRule(Item item, XPathContext context) throws XPathException
getRule
in class Mode
item
- the item to be matchedcontext
- the XPath dynamic evaluation contextXPathException
- if an error occurs matching a patternprotected Rule getNamedRuleChain(XPathContext c, int kind, String uri, String local)
kind
- the kind of node (element or attribute)uri
- the namespace URI of the nodelocal
- the local name of the nodeprotected Rule searchRuleChain(Item item, XPathContext context, Rule bestRule, Rule head, RuleSearchState ruleSearchState) throws XPathException
item
- the item being matchedcontext
- XPath dynamic contextbestRule
- the best rule so far in terms of precedence and priority (may be null)head
- the rule at the head of the chain to be searchedruleSearchState
- An appropriate rule state objectXPathException
- if an error occurs matching a patternprotected boolean ruleMatches(Rule r, Item item, XPathContextMajor context, RuleSearchState pre) throws XPathException
r
- the rule to checkitem
- the context itemcontext
- the static context for evaluationpre
- An appropriate matcher for preconditions in this modeXPathException
public Rule getRule(Item item, XPathContext context, Mode.RuleFilter filter) throws XPathException
getRule
in class Mode
item
- the item to be matchedcontext
- the XPath dynamic evaluation contextfilter
- a filter to select which rules should be consideredXPathException
- if an error occursprotected Rule searchRuleChain(Item item, XPathContext context, Rule bestRule, Rule head, RuleSearchState ruleSearchState, Mode.RuleFilter filter) throws XPathException
item
- the item being matchedcontext
- XPath dynamic contextbestRule
- the best rule so far in terms of precedence and priority (may be null)head
- the rule at the head of the chain to be searchedruleSearchState
- An appropriate ruleState in this modefilter
- filter used to select which rules are candidates to be searchedXPathException
- if an error occurs while matching a patternprotected void reportAmbiguity(Item item, Rule r1, Rule r2, XPathContext c) throws XPathException
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 transformationXPathException
- if the system is configured to treat ambiguous template matching as a
non-recoverable errorpublic void prepareStreamability() throws XPathException
XPathException
public void allocateAllBindingSlots(StylesheetPackage pack)
allocateAllBindingSlots
in class ComponentCode<SimpleMode>
pack
- the containing packagepublic static void forceAllocateAllBindingSlots(StylesheetPackage pack, SimpleMode mode, List<ComponentBinding> bindings)
public void computeStreamability() throws XPathException
XPathException
public void invertStreamableTemplates() throws XPathException
XPathException
- if there is a non-streamable template in the modepublic void explainTemplateRules(ExpressionPresenter out)
explainTemplateRules
in class Mode
out
- used to display the expression treepublic void exportTemplateRules(ExpressionPresenter out)
exportTemplateRules
in class Mode
out
- used to display the expression treepublic void processRules(Mode.RuleAction action) throws XPathException
processRules
in class Mode
action
- an action that is to be applied to all the rules in this ModeXPathException
- if an error occurs processing any of the rulespublic void processRules(Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
action
- an action that is to be applied to all the rules in this Modegroup
- - actions to be performed at group start and group endXPathException
- if an error occurs processing any of the rulesprotected SimpleMode.RuleGroupAction setGroup(SimpleMode.RuleGroupAction group, String type)
group
- the group action objecttype
- the type of the rule grouppublic void processRuleChains(IntHashMap<Rule> chains, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
XPathException
public void processRuleChain(Rule r, Mode.RuleAction action) throws XPathException
action
- an action that is to be applied to all the rules in this ModeXPathException
- if an error occurs processing any of the rulespublic void processRuleChain(Rule r, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
XPathException
public void optimizeRules()
public int getMaxPrecedence()
Mode
getMaxPrecedence
in class Mode
public void computeRankings(int start) throws XPathException
computeRankings
in class Mode
start
- the lowest rank to useXPathException
- if an error occurs processing the rulespublic int getMaxRank()
Mode
getMaxRank
in class Mode
public void allocateAllPatternSlots() throws XPathException
XPathException
- if anything goes wrongpublic int getStackFrameSlotsNeeded()
getStackFrameSlotsNeeded
in class Mode
public void setStackFrameSlotsNeeded(int slots)
Copyright (c) 2004-2014 Saxonica Limited. All rights reserved.