APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xpath.internal

public Class XPath

extends Object
implements Serializable, ExpressionOwner
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xpath.internal.ExpressionOwner, java.io.Serializable
Imports
com.sun.org.apache.xalan.internal.res.XSLMessages, com.sun.org.apache.xml.internal.dtm.DTM, com.sun.org.apache.xml.internal.utils.DefaultErrorHandler, .PrefixResolver, .QName, .SAXSourceLocator, com.sun.org.apache.xpath.internal.compiler.Compiler, .FunctionTable, .XPathParser, com.sun.org.apache.xpath.internal.objects.XObject, com.sun.org.apache.xpath.internal.res.XPATHErrorResources, java.io.Serializable, java.util.List, javax.xml.transform.ErrorListener, .SourceLocator, .TransformerException, jdk.xml.internal.XMLSecurityManager

The XPath class wraps an expression object and provides general services for execution of that expression.

Field Summary

Modifier and TypeField and Description
private static final boolean
DEBUG_MATCHES

Set to true to get diagnostic messages about the result of match pattern testing.

private transient FunctionTable
m_funcTable

The function table for xpath build-in functions

private Expression
m_mainExp

The top of the expression tree.

pack-priv String
m_patternString

The pattern string, mainly kept around for diagnostic purposes.

public static final int
MATCH

Represents a match type expression.

public static final double
MATCH_SCORE_NODETEST

The match score if the pattern consists of just a NodeTest.

public static final double
MATCH_SCORE_NONE

The match score if no match is made.

public static final double
MATCH_SCORE_NSWILD

The match score if the pattern pattern has the form NCName:*.

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.

public static final double
MATCH_SCORE_QNAME

The match score if the pattern has the form of a QName optionally preceded by an @ character.

public static final int
SELECT

Represents a select type expression.

pack-priv static final long

Constructor Summary

AccessConstructor and Description
public
XPath(String
The XPath expression.
exprString
,
SourceLocator
The location of the expression, may be null.
locator
,
PrefixResolver
A prefix resolver to use to resolve prefixes to namespace URIs.
prefixResolver
,
int
one of SELECT or MATCH.
type
,
ErrorListener
The error listener, or null if default should be used.
errorListener
)

Construct an XPath object.

public
XPath(String
The XPath expression.
exprString
,
SourceLocator
The location of the expression, may be null.
locator
,
PrefixResolver
A prefix resolver to use to resolve prefixes to namespace URIs.
prefixResolver
,
int
one of SELECT or MATCH.
type
,
ErrorListener
The error listener, or null if default should be used.
errorListener
,
FunctionTable
the function table
funcTable
,
XMLSecurityManager
the XML security manager
xmlSecMgr
)

Construct an XPath object.

public
XPath(String
The XPath expression.
exprString
,
SourceLocator
The location of the expression, may be null.
locator
,
PrefixResolver
A prefix resolver to use to resolve prefixes to namespace URIs.
prefixResolver
,
int
one of SELECT or MATCH.
type
)

Construct an XPath object.

public
XPath(String
The XPath expression.
exprString
,
SourceLocator
The location of the expression, may be null.
locator
,
PrefixResolver
A prefix resolver to use to resolve prefixes to namespace URIs.
prefixResolver
,
int
one of SELECT or MATCH.
type
,
ErrorListener
The error listener, or null if default should be used.
errorListener
,
FunctionTable
the function table
funcTable
)

Constructs an XPath object.

public
XPath(Expression
The Expression object.
expr
)

Construct an XPath object.

Method Summary

Modifier and TypeMethod and Description
public void
assertion(boolean
If false, a runtime exception will be thrown.
b
,
String
The assertion message, which should be informative.
msg
)

Tell the user of an assertion error, and probably throw an exception.

public boolean
bool(XPathContext
The execution context.
xctxt
,
int
The node that "." expresses.
contextNode
,
PrefixResolver
The context in which namespaces in the XPath are supposed to be expanded.
namespaceContext
)

Given an expression and a context, evaluate the XPath and return the result.

public void
callVisitors(ExpressionOwner
The owner of the visitor, where that path may be rewritten if needed.
owner
,
XPathVisitor
The visitor whose appropriate method will be called.
visitor
)

This will traverse the heararchy, calling the visitor for each member.

public void
error(XPathContext
The XPath runtime context.
xctxt
,
int
Not used.
sourceNode
,
String
An error msgkey that corresponds to one of the constants found in com.sun.org.apache.xpath.internal.res.XPATHErrorResources, which is a key for a format string.
msg
,
Object[]
An array of arguments represented in the format string, which may be null.
args
)

Tell the user of an error, and probably throw an exception.

public XObject

Returns:

The result of the XPath or null if callbacks are used.
execute
(XPathContext
The execution context.
xctxt
,
Node
The node that "." expresses.
contextNode
,
PrefixResolver
The context in which namespaces in the XPath are supposed to be expanded.
namespaceContext
)

Given an expression and a context, evaluate the XPath and return the result.

public XObject
execute(XPathContext
The execution context.
xctxt
,
int
The node that "." expresses.
contextNode
,
PrefixResolver
The context in which namespaces in the XPath are supposed to be expanded.
namespaceContext
)

Given an expression and a context, evaluate the XPath and return the result.

public void
fixupVariables(List<QName>
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).
vars
,
int globalsSize)

This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.

public Expression

Returns:

the raw Expression object, which should not normally be null.
getExpression
()

Implements com.sun.org.apache.xpath.internal.ExpressionOwner.getExpression.

Get the raw Expression object that this class wraps.

public SourceLocator

Returns:

the SourceLocator on the expression object, which may be null.
getLocator
()

Get the SourceLocator on the expression object.

public double
getMatchScore(XPathContext
XPath runtime context.
xctxt
,
int
The current source tree context node.
context
)

Get the match score of the given node.

public String

Returns:

the XPath string associated with this object.
getPatternString
()

Return the XPath string associated with this object.

private void
initFunctionTable()

initial the function table

public void
setExpression(Expression
the raw Expression object, which should not normally be null.
exp
)

Implements com.sun.org.apache.xpath.internal.ExpressionOwner.setExpression.

Set the raw expression object for this object.

public void
warn(XPathContext
The XPath runtime context.
xctxt
,
int
Not used.
sourceNode
,
String
An error msgkey that corresponds to one of the constants found in com.sun.org.apache.xpath.internal.res.XPATHErrorResources, which is a key for a format string.
msg
,
Object[]
An array of arguments represented in the format string, which may be null.
args
)

Warn the user of an problem.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUG_MATCHESback to summary
private static final boolean DEBUG_MATCHES

Set to true to get diagnostic messages about the result of match pattern testing.

m_funcTableback to summary
private transient FunctionTable m_funcTable

The function table for xpath build-in functions

m_mainExpback to summary
private Expression m_mainExp

The top of the expression tree.

m_patternStringback to summary
pack-priv String m_patternString

The pattern string, mainly kept around for diagnostic purposes.

MATCHback to summary
public static final int MATCH

Represents a match type expression.

MATCH_SCORE_NODETESTback to summary
public static final double MATCH_SCORE_NODETEST

The match score if the pattern consists of just a NodeTest.

MATCH_SCORE_NONEback to summary
public static final double MATCH_SCORE_NONE

The match score if no match is made.

MATCH_SCORE_NSWILDback to summary
public static final double MATCH_SCORE_NSWILD

The match score if the pattern pattern has the form NCName:*.

MATCH_SCORE_OTHERback to summary
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.

MATCH_SCORE_QNAMEback to summary
public static final double MATCH_SCORE_QNAME

The match score if the pattern has the form of a QName optionally preceded by an @ character.

SELECTback to summary
public static final int SELECT

Represents a select type expression.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Constructor Detail

XPathback to summary
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.

Parameters
exprString:String

The XPath expression.

locator:SourceLocator

The location of the expression, may be null.

prefixResolver:PrefixResolver

A prefix resolver to use to resolve prefixes to namespace URIs.

type:int

one of SELECT or MATCH.

errorListener:ErrorListener

The error listener, or null if default should be used.

Exceptions
TransformerException:
if syntax or other error.
XPathback to summary
public XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable funcTable, XMLSecurityManager xmlSecMgr) throws TransformerException

Construct an XPath object. (Needs review -sc) This method initializes an XPathParser/ Compiler and compiles the expression.

Parameters
exprString:String

The XPath expression.

locator:SourceLocator

The location of the expression, may be null.

prefixResolver:PrefixResolver

A prefix resolver to use to resolve prefixes to namespace URIs.

type:int

one of SELECT or MATCH.

errorListener:ErrorListener

The error listener, or null if default should be used.

funcTable:FunctionTable

the function table

xmlSecMgr:XMLSecurityManager

the XML security manager

Exceptions
TransformerException:
if syntax or other error.
XPathback to summary
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.

Parameters
exprString:String

The XPath expression.

locator:SourceLocator

The location of the expression, may be null.

prefixResolver:PrefixResolver

A prefix resolver to use to resolve prefixes to namespace URIs.

type:int

one of SELECT or MATCH.

Exceptions
TransformerException:
if syntax or other error.
XPathback to summary
public XPath(String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable funcTable) throws TransformerException

Constructs an XPath object.

Parameters
exprString:String

The XPath expression.

locator:SourceLocator

The location of the expression, may be null.

prefixResolver:PrefixResolver

A prefix resolver to use to resolve prefixes to namespace URIs.

type:int

one of SELECT or MATCH.

errorListener:ErrorListener

The error listener, or null if default should be used.

funcTable:FunctionTable

the function table

XPathback to summary
public XPath(Expression expr)

Construct an XPath object.

Parameters
expr:Expression

The Expression object.

Exceptions
TransformerException:
if syntax or other error.

Method Detail

assertionback to summary
public void assertion(boolean b, String msg)

Tell the user of an assertion error, and probably throw an exception.

Parameters
b:boolean

If false, a runtime exception will be thrown.

msg:String

The assertion message, which should be informative.

Exceptions
RuntimeException:
if the b argument is false.
boolback to summary
public boolean bool(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws TransformerException

Given an expression and a context, evaluate the XPath and return the result.

Parameters
xctxt:XPathContext

The execution context.

contextNode:int

The node that "." expresses.

namespaceContext:PrefixResolver

The context in which namespaces in the XPath are supposed to be expanded.

Exceptions
TransformerException:
thrown if the active ProblemListener decides the error condition is severe enough to halt processing.
callVisitorsback to summary
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.

Parameters
owner:ExpressionOwner

The owner of the visitor, where that path may be rewritten if needed.

visitor:XPathVisitor

The visitor whose appropriate method will be called.

errorback to summary
public void error(XPathContext xctxt, int sourceNode, String msg, Object[] args) throws TransformerException

Tell the user of an error, and probably throw an exception.

Parameters
xctxt:XPathContext

The XPath runtime context.

sourceNode:int

Not used.

msg:String

An error msgkey that corresponds to one of the constants found in com.sun.org.apache.xpath.internal.res.XPATHErrorResources, which is a key for a format string.

args:Object[]

An array of arguments represented in the format string, which may be null.

Exceptions
TransformerException:
if the current ErrorListoner determines to throw an exception.
executeback to summary
public XObject execute(XPathContext xctxt, Node contextNode, PrefixResolver namespaceContext) throws TransformerException

Given an expression and a context, evaluate the XPath and return the result.

Parameters
xctxt:XPathContext

The execution context.

contextNode:Node

The node that "." expresses.

namespaceContext:PrefixResolver

The context in which namespaces in the XPath are supposed to be expanded.

Returns:XObject

The result of the XPath or null if callbacks are used.

Exceptions
TransformerException:
thrown if the error condition is severe enough to halt processing.
executeback to summary
public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws TransformerException

Given an expression and a context, evaluate the XPath and return the result.

Parameters
xctxt:XPathContext

The execution context.

contextNode:int

The node that "." expresses.

namespaceContext:PrefixResolver

The context in which namespaces in the XPath are supposed to be expanded.

Exceptions
TransformerException:
thrown if the active ProblemListener decides the error condition is severe enough to halt processing.
fixupVariablesback to summary
public void fixupVariables(List<QName> vars, int globalsSize)

This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.

Parameters
vars:List<QName>

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).

getExpressionback to summary
public Expression getExpression()

Implements com.sun.org.apache.xpath.internal.ExpressionOwner.getExpression.

Get the raw Expression object that this class wraps.

Returns:Expression

the raw Expression object, which should not normally be null.

getLocatorback to summary
public SourceLocator getLocator()

Get the SourceLocator on the expression object.

Returns:SourceLocator

the SourceLocator on the expression object, which may be null.

getMatchScoreback to summary
public double getMatchScore(XPathContext xctxt, int context) throws TransformerException

Get the match score of the given node.

Parameters
xctxt:XPathContext

XPath runtime context.

context:int

The current source tree context node.

Returns:double

score, one of MATCH_SCORE_NODETEST, MATCH_SCORE_NONE, MATCH_SCORE_OTHER, or MATCH_SCORE_QNAME.

getPatternStringback to summary
public String getPatternString()

Return the XPath string associated with this object.

Returns:String

the XPath string associated with this object.

initFunctionTableback to summary
private void initFunctionTable()

initial the function table

setExpressionback to summary
public void setExpression(Expression exp)

Implements com.sun.org.apache.xpath.internal.ExpressionOwner.setExpression.

Set the raw expression object for this object.

Parameters
exp:Expression

the raw Expression object, which should not normally be null.

warnback to summary
public void warn(XPathContext xctxt, int sourceNode, String msg, Object[] args) throws TransformerException

Warn the user of an problem.

Parameters
xctxt:XPathContext

The XPath runtime context.

sourceNode:int

Not used.

msg:String

An error msgkey that corresponds to one of the constants found in com.sun.org.apache.xpath.internal.res.XPATHErrorResources, which is a key for a format string.

args:Object[]

An array of arguments represented in the format string, which may be null.

Exceptions
TransformerException:
if the current ErrorListoner determines to throw an exception.