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 RuleChain |
atomicValueRuleChain |
protected RuleChain |
commentRuleChain |
protected RuleChain |
documentRuleChain |
protected RuleChain |
functionItemRuleChain |
protected RuleChain |
genericRuleChain |
protected IntHashMap<RuleChain> |
namedAttributeRuleChains |
protected IntHashMap<RuleChain> |
namedElementRuleChains |
protected RuleChain |
namespaceRuleChain |
protected RuleChain |
processingInstructionRuleChain |
protected java.util.Map<StructuredQName,RuleChain> |
qNamedAttributeRuleChains |
protected java.util.Map<StructuredQName,RuleChain> |
qNamedElementRuleChains |
protected RuleChain |
textRuleChain |
protected RuleChain |
unnamedAttributeRuleChain |
protected RuleChain |
unnamedElementRuleChain |
DEFAULT_MODE_NAME, modeName, mustBeTyped, mustBeUntyped, OMNI_MODE, UNNAMED_MODE_NAME| 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,
java.util.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
|
java.util.Set<java.lang.String> |
getExplicitNamespaces(NamePool pool)
Get the "explicit namespaces" matched by this mode.
|
java.lang.String |
getLabel()
Get an identifier for the mode for use in error messages
|
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 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
|
java.lang.String |
getPropertyValue(java.lang.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(RuleChain chain,
XPathContext context)
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(RuleChain chain,
Mode.RuleAction action)
Walk over all the rules, applying a specified action to each one.
|
void |
processRuleChain(RuleChain chain,
Mode.RuleAction action,
SimpleMode.RuleGroupAction group) |
void |
processRuleChains(IntHashMap<RuleChain> 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,
RuleChain chain)
Search a chain of rules
|
protected Rule |
searchRuleChain(Item item,
XPathContext context,
Rule bestRule,
RuleChain chain,
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(java.lang.String name,
java.lang.String value,
int precedence)
Set an explicit property at a particular precedence.
|
protected SimpleMode.RuleGroupAction |
setGroup(SimpleMode.RuleGroupAction group,
java.lang.String type)
Set the string associated with a rule group
|
void |
setStackFrameSlotsNeeded(int slots) |
applyTemplates, explain, export, exportUseAccumulators, getAccumulators, getBuiltInRuleSetForCode, getCodeForBuiltInRuleSet, getComponentKind, getConstructType, getDeclaringComponent, getModeName, getModeTitle, getNextMatchRule, getObjectName, getRecoveryPolicy, getRule, getSymbolicName, isDeclaredStreamable, isMustBeTyped, isUnnamedMode, makeNewContext, makeNewContextIfNeeded, setAccumulators, setHasRules, setRecoveryPolicy, setStreamableallocateBindingSlotsRecursive, getBody, getColumnNumber, getDeclaredVisibility, getLineNumber, getLocation, getPackageData, getProperties, getProperty, getPublicId, getRetainedStaticContext, getStackFrameMap, getSystemId, isExportable, makeDeclaringComponent, saveLocation, setBody, setChildExpression, setDeclaredVisibility, setDeclaringComponent, setLineNumber, setPackageData, setRetainedStaticContext, setStackFrameMap, setSystemIdprotected RuleChain genericRuleChain
protected RuleChain atomicValueRuleChain
protected RuleChain functionItemRuleChain
protected RuleChain documentRuleChain
protected RuleChain textRuleChain
protected RuleChain commentRuleChain
protected RuleChain processingInstructionRuleChain
protected RuleChain namespaceRuleChain
protected RuleChain unnamedElementRuleChain
protected RuleChain unnamedAttributeRuleChain
protected IntHashMap<RuleChain> namedElementRuleChains
protected IntHashMap<RuleChain> namedAttributeRuleChains
protected java.util.Map<StructuredQName,RuleChain> qNamedElementRuleChains
protected java.util.Map<StructuredQName,RuleChain> 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 Modepublic SimpleMode getActivePart()
getActivePart in class Modepublic void checkForConflictingProperties()
throws XPathException
XPathException - if there are conflictspublic java.lang.String getLabel()
public static void copyRules(SimpleMode from, SimpleMode to)
from - the existing mode.to - the name of the new mode to be createdprotected RuleSearchState makeRuleSearchState(RuleChain chain, XPathContext context)
public boolean isEmpty()
public void setExplicitProperty(java.lang.String name,
java.lang.String value,
int precedence)
name - the name of the propertyvalue - the value of the propertyprecedence - the import precedence of this property valuepublic java.lang.String getPropertyValue(java.lang.String name)
name - the property name, e.g. "typed"public java.util.Set<java.lang.String> getExplicitNamespaces(NamePool pool)
getExplicitNamespaces in class Modepool - 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 Modeitem - the item to be matchedcontext - the XPath dynamic evaluation contextXPathException - if an error occurs matching a patternprotected RuleChain getNamedRuleChain(XPathContext c, int kind, java.lang.String uri, java.lang.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, RuleChain chain) throws XPathException
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 searchedXPathException - 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 modeXPathExceptionpublic Rule getRule(Item item, XPathContext context, Mode.RuleFilter filter) throws XPathException
getRule in class Modeitem - 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, RuleChain chain, 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)chain - 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
XPathExceptionpublic void allocateAllBindingSlots(StylesheetPackage pack)
allocateAllBindingSlots in class Actorpack - the containing packagepublic static void forceAllocateAllBindingSlots(StylesheetPackage pack, SimpleMode mode, java.util.List<ComponentBinding> bindings)
public void computeStreamability()
throws XPathException
XPathExceptionpublic void invertStreamableTemplates()
throws XPathException
XPathException - if there is a non-streamable template in the modepublic void explainTemplateRules(ExpressionPresenter out) throws XPathException
explainTemplateRules in class Modeout - used to display the expression treeXPathExceptionpublic void exportTemplateRules(ExpressionPresenter out) throws XPathException
exportTemplateRules in class Modeout - used to display the expression treeXPathExceptionpublic void processRules(Mode.RuleAction action) throws XPathException
processRules in class Modeaction - 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, java.lang.String type)
group - the group action objecttype - the type of the rule grouppublic void processRuleChains(IntHashMap<RuleChain> chains, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
XPathExceptionpublic void processRuleChain(RuleChain chain, 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(RuleChain chain, Mode.RuleAction action, SimpleMode.RuleGroupAction group) throws XPathException
XPathExceptionpublic void optimizeRules()
public int getMaxPrecedence()
ModegetMaxPrecedence in class Modepublic void computeRankings(int start)
throws XPathException
computeRankings in class Modestart - the lowest rank to useXPathException - if an error occurs processing the rulespublic int getMaxRank()
ModegetMaxRank in class Modepublic void allocateAllPatternSlots()
XPathException - if anything goes wrongpublic int getStackFrameSlotsNeeded()
getStackFrameSlotsNeeded in class Modepublic void setStackFrameSlotsNeeded(int slots)
Copyright (c) 2004-2018 Saxonica Limited. All rights reserved.