net.sf.saxon.pattern

Class UnionPattern

Implemented Interfaces:
Container, PatternFinder, Serializable, SourceLocator

public class UnionPattern
extends Pattern

A pattern formed as the union (or) of two other patterns

Field Summary

protected Pattern
p1
protected Pattern
p2

Constructor Summary

UnionPattern(Pattern p1, Pattern p2)
Constructor

Method Summary

int
allocateSlots(ExpressionContext env, int nextFree)
Allocate slots to any variables used within the pattern
Pattern
analyze(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the pattern.
int
getDependencies()
Get the dependencies of the pattern.
Pattern
getLHS()
Get the LHS of the union
int
getNodeKind()
Determine the types of nodes to which this pattern applies.
NodeTest
getNodeTest()
Get a NodeTest that all the nodes matching this pattern must satisfy
Pattern
getRHS()
Get the RHS of the union
Iterator
iterateSubExpressions()
Iterate over the subexpressions within this pattern
boolean
matches(NodeInfo e, XPathContext context)
Determine if the supplied node matches the pattern
void
setExecutable(Executable executable)
Set the executable containing this pattern
void
setLineNumber(int lineNumber)
Override method to set the system ID, so it's set on both halves
void
setOriginalText(String pattern)
Set the original text
void
setSystemId(String systemId)
Override method to set the system ID, so it's set on both halves
Pattern
simplify(ExpressionVisitor visitor)
Simplify the pattern: perform any context-independent optimisations

Methods inherited from class net.sf.saxon.pattern.Pattern

allocateSlots, analyze, getColumnNumber, getDefaultPriority, getDependencies, getExecutable, getFingerprint, getHostLanguage, getLineNumber, getLocationProvider, getNodeKind, getNodeTest, getPublicId, getSystemId, internalMatches, iterateSubExpressions, make, makeSearchExpression, matches, promote, replaceSubExpression, selectNodes, setExecutable, setLineNumber, setOriginalText, setSystemId, simplify, toString

Field Details

p1

protected Pattern p1

p2

protected Pattern p2

Constructor Details

UnionPattern

public UnionPattern(Pattern p1,
                    Pattern p2)
Constructor
Parameters:
p1 - the left-hand operand
p2 - the right-hand operand

Method Details

allocateSlots

public int allocateSlots(ExpressionContext env,
                         int nextFree)
Allocate slots to any variables used within the pattern
Overrides:
allocateSlots in interface Pattern
Parameters:
env - the static context in the XSLT stylesheet
nextFree - the next slot that is free to be allocated
Returns:
the next slot that is free to be allocated

analyze

public Pattern analyze(ExpressionVisitor visitor,
                       ItemType contextItemType)
            throws XPathException
Type-check the pattern. This is only needed for patterns that contain variable references or function calls.
Overrides:
analyze in interface Pattern
Returns:
the optimised Pattern

getDependencies

public int getDependencies()
Get the dependencies of the pattern. The only possible dependency for a pattern is on local variables. This is analyzed in those patterns where local variables may appear.
Overrides:
getDependencies in interface Pattern
Returns:
the dependencies, as a bit-significant mask

getLHS

public Pattern getLHS()
Get the LHS of the union

getNodeKind

public int getNodeKind()
Determine the types of nodes to which this pattern applies. Used for optimisation. For patterns that match nodes of several types, return Node.NODE
Overrides:
getNodeKind in interface Pattern
Returns:
the type of node matched by this pattern. e.g. Node.ELEMENT or Node.TEXT

getNodeTest

public NodeTest getNodeTest()
Get a NodeTest that all the nodes matching this pattern must satisfy
Overrides:
getNodeTest in interface Pattern

getRHS

public Pattern getRHS()
Get the RHS of the union

iterateSubExpressions

public Iterator iterateSubExpressions()
Iterate over the subexpressions within this pattern
Overrides:
iterateSubExpressions in interface Pattern
Returns:
an iterator over the subexpressions.

matches

public boolean matches(NodeInfo e,
                       XPathContext context)
            throws XPathException
Determine if the supplied node matches the pattern
Overrides:
matches in interface Pattern
Parameters:
e - the node to be compared
Returns:
true if the node matches either of the operand patterns

setExecutable

public void setExecutable(Executable executable)
Set the executable containing this pattern
Overrides:
setExecutable in interface Pattern
Parameters:
executable - the executable

setLineNumber

public void setLineNumber(int lineNumber)
Override method to set the system ID, so it's set on both halves
Overrides:
setLineNumber in interface Pattern

setOriginalText

public void setOriginalText(String pattern)
Set the original text
Overrides:
setOriginalText in interface Pattern

setSystemId

public void setSystemId(String systemId)
Override method to set the system ID, so it's set on both halves
Overrides:
setSystemId in interface Pattern

simplify

public Pattern simplify(ExpressionVisitor visitor)
            throws XPathException
Simplify the pattern: perform any context-independent optimisations
Overrides:
simplify in interface Pattern
Parameters:
visitor - an expression visitor