net.sf.saxon.instruct

Class AnalyzeString

public class AnalyzeString extends Instruction

An xsl:analyze-string element in the stylesheet. New at XSLT 2.0
Constructor Summary
AnalyzeString(Expression select, Expression regex, Expression flags, Expression matching, Expression nonMatching, RegularExpression pattern)
Construct an AnalyzeString instruction
Method Summary
voidcheckPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type.
intcomputeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions.
Expressioncopy()
Copy an expression.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
intgetImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
intgetInstructionNameCode()
ItemTypegetItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction
ExpressiongetMatchingExpression()
Get the expression used to process matching substrings
ExpressiongetNonMatchingExpression()
Get the expression used to process non-matching substrings
booleanhasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
Iterator<Expression>iterateSameFocusSubExpressions()
Get the immediate sub-expressions of this expression that are evaluated with the same focus (context item, position, and size) as the parent expression.
Iterator<Expression>iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction.
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Constructor Detail

AnalyzeString

public AnalyzeString(Expression select, Expression regex, Expression flags, Expression matching, Expression nonMatching, RegularExpression pattern)
Construct an AnalyzeString instruction

Parameters: select the expression containing the input string regex the regular expression flags the flags parameter matching actions to be applied to a matching substring nonMatching actions to be applied to a non-matching substring pattern the compiled regular expression, if it was known statically

Method Detail

checkPermittedContents

public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.

computeDependencies

public int computeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. (This is overridden for path expressions and filter expressions, where the dependencies of a subexpression are not all propogated). This method should be called only once, to compute the dependencies; after that, getDependencies should be used.

Returns: the depencies, as a bit-mask

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

getImplementationMethod

public int getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is prefered.

getInstructionNameCode

public int getInstructionNameCode()

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction

Parameters: th the type hierarchy cache

Returns: the static item type of the instruction

getMatchingExpression

public Expression getMatchingExpression()
Get the expression used to process matching substrings

Returns: the expression used to process matching substrings

getNonMatchingExpression

public Expression getNonMatchingExpression()
Get the expression used to process non-matching substrings

Returns: the expression used to process non-matching substrings

hasLoopingSubexpression

public boolean hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly

Parameters: child the immediate subexpression

Returns: true if the child expression is evaluated repeatedly

iterate

public SequenceIterator iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.

Parameters: context supplies the context for evaluation

Returns: a SequenceIterator that can be used to iterate over the result of the expression

Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression

iterateSameFocusSubExpressions

public Iterator<Expression> iterateSameFocusSubExpressions()
Get the immediate sub-expressions of this expression that are evaluated with the same focus (context item, position, and size) as the parent expression.

Returns: an iterator containing those sub-expressions of this expression that are evaluated with the same focus as the parent expression

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction. This method must be implemented in each subclass. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.

Parameters: context The dynamic context of the transformation, giving access to the current node, the current variables, etc.

Returns: null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

Parameters: offer The type of rewrite being offered

Throws: XPathException

replaceSubExpression

public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression

Parameters: original the original subexpression replacement the replacement subexpression

Returns: true if the original subexpression is found

simplify

public Expression simplify(ExpressionVisitor visitor)
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression).

Parameters: visitor an expression visitor

Returns: the simplified expression

Throws: XPathException if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)