The XPath class wraps an expression object and provides general services
for execution of that expression.
MATCH
public static final int MATCH
Represents a match type expression.
- 1
MATCH_SCORE_NODETEST
public static final double MATCH_SCORE_NODETEST
The match score if the pattern consists of just a NodeTest.
- 0.0
MATCH_SCORE_NONE
public static final double MATCH_SCORE_NONE
The match score if no match is made.
MATCH_SCORE_NSWILD
public static final double MATCH_SCORE_NSWILD
The match score if the pattern pattern has the form NCName:*.
- 0.0
MATCH_SCORE_OTHER
public static final double MATCH_SCORE_OTHER
The match score if the pattern consists of something
other than just a NodeTest or just a qname.
- 0.0
MATCH_SCORE_QNAME
public static final double MATCH_SCORE_QNAME
The match score if the pattern has the form
of a QName optionally preceded by an @ character.
- 0.0
SELECT
public static final int SELECT
Represents a select type expression.
- 0
XPath
public XPath(String exprString,
SourceLocator locator,
PrefixResolver prefixResolver,
int type)
throws TransformerException
Construct an XPath object.
(Needs review -sc) This method initializes an XPathParser/
Compiler and compiles the expression.
exprString
- The XPath expression.locator
- The location of the expression, may be null.prefixResolver
- A prefix resolver to use to resolve prefixes to
namespace URIs.type
- one of SELECT
or MATCH
.
TransformerException
- if syntax or other error.
XPath
public XPath(String exprString,
SourceLocator locator,
PrefixResolver prefixResolver,
int type,
ErrorListener errorListener)
throws TransformerException
Construct an XPath object.
(Needs review -sc) This method initializes an XPathParser/
Compiler and compiles the expression.
exprString
- The XPath expression.locator
- The location of the expression, may be null.prefixResolver
- A prefix resolver to use to resolve prefixes to
namespace URIs.type
- one of SELECT
or MATCH
.errorListener
- The error listener, or null if default should be used.
TransformerException
- if syntax or other error.
XPath
public XPath(Expression expr)
Construct an XPath object.
expr
- The Expression object.
assertion
public void assertion(boolean b,
String msg)
Tell the user of an assertion error, and probably throw an
exception.
b
- If false, a runtime exception will be thrown.msg
- The assertion message, which should be informative.
bool
public boolean bool(XPathContext xctxt,
int contextNode,
PrefixResolver namespaceContext)
throws TransformerException
Given an expression and a context, evaluate the XPath
and return the result.
xctxt
- The execution context.contextNode
- The node that "." expresses.namespaceContext
- The context in which namespaces in the
XPath are supposed to be expanded.
TransformerException
- thrown if the active ProblemListener decides
the error condition is severe enough to halt processing.TransformerException
-
callVisitors
public void callVisitors(ExpressionOwner owner,
XPathVisitor visitor)
This will traverse the heararchy, calling the visitor for
each member. If the called visitor method returns
false, the subtree should not be called.
owner
- The owner of the visitor, where that path may be
rewritten if needed.visitor
- The visitor whose appropriate method will be called.
error
public void error(XPathContext xctxt,
int sourceNode,
String msg,
Object[] args)
throws TransformerException
Tell the user of an error, and probably throw an
exception.
xctxt
- The XPath runtime context.sourceNode
- Not used.msg
- An error msgkey that corresponds to one of the constants found
in XPATHErrorResources
, which is
a key for a format string.args
- An array of arguments represented in the format string, which
may be null.
TransformerException
- if the current ErrorListoner determines to
throw an exception.
execute
public XObject execute(XPathContext xctxt,
int contextNode,
PrefixResolver namespaceContext)
throws TransformerException
Given an expression and a context, evaluate the XPath
and return the result.
xctxt
- The execution context.contextNode
- The node that "." expresses.namespaceContext
- The context in which namespaces in the
XPath are supposed to be expanded.
TransformerException
- thrown if the active ProblemListener decides
the error condition is severe enough to halt processing.TransformerException
-
execute
public XObject execute(XPathContext xctxt,
Node contextNode,
PrefixResolver namespaceContext)
throws TransformerException
Given an expression and a context, evaluate the XPath
and return the result.
xctxt
- The execution context.contextNode
- The node that "." expresses.namespaceContext
- The context in which namespaces in the
XPath are supposed to be expanded.
- The result of the XPath or null if callbacks are used.
TransformerException
- thrown if
the error condition is severe enough to halt processing.TransformerException
-
fixupVariables
public void fixupVariables(java.util.Vector vars,
int globalsSize)
This function is used to fixup variables from QNames to stack frame
indexes at stylesheet build time.
vars
- List of QNames that correspond to variables. This list
should be searched backwards for the first qualified name that
corresponds to the variable reference qname. The position of the
QName in the vector from the start of the vector will be its position
in the stack frame (but variables above the globalsTop value will need
to be offset to the current stack frame).
getExpression
public Expression getExpression()
Get the raw Expression object that this class wraps.
- getExpression in interface ExpressionOwner
- the raw Expression object, which should not normally be null.
getLocator
public SourceLocator getLocator()
Get the SourceLocator on the expression object.
- the SourceLocator on the expression object, which may be null.
getPatternString
public String getPatternString()
Return the XPath string associated with this object.
- the XPath string associated with this object.
installFunction
public void installFunction(String name,
int funcIndex,
Function func)
Install a built-in function.
name
- The unqualified name of the function; not currently used.funcIndex
- The index of the function in the table.func
- An Implementation of an XPath Function object.
setExpression
public void setExpression(Expression exp)
Set the raw expression object for this object.
- setExpression in interface ExpressionOwner
exp
- the raw Expression object, which should not normally be null.
warn
public void warn(XPathContext xctxt,
int sourceNode,
String msg,
Object[] args)
throws TransformerException
Warn the user of an problem.
xctxt
- The XPath runtime context.sourceNode
- Not used.msg
- An error msgkey that corresponds to one of the constants found
in XPATHErrorResources
, which is
a key for a format string.args
- An array of arguments represented in the format string, which
may be null.
TransformerException
- if the current ErrorListoner determines to
throw an exception.