com.novell.xml.xpath
Class ExpressionContext

java.lang.Object
  extended bycom.novell.xml.xpath.ExpressionContext
All Implemented Interfaces:
ContextNodeList, NamespaceContext, WhitespaceStripper
Direct Known Subclasses:
Context

public class ExpressionContext
extends Object
implements NamespaceContext, ContextNodeList, WhitespaceStripper

Implements the functionality required for the expression evaluation context for XPath expressions

See Also:
Expression

Nested Class Summary
protected  class ExpressionContext.State
          Contains state information for the expression context
 
Field Summary
 
Fields inherited from interface com.novell.xml.xpath.ContextNodeList
DOCUMENT_ORDER, REVERSE_DOCUMENT_ORDER, UNKNOWN_ORDER
 
Constructor Summary
ExpressionContext()
          Create an empty ExpressionContext
ExpressionContext(ExpressionContext iVal)
          Create a copy of an existing expression context, minus any saved state information.
ExpressionContext(Map properties)
          Create an empty ExpressionContext with extended properties
 
Method Summary
 int count()
          Return a count of nodes in the context node list.
 ExpressionValue evaluate(Node currentNode, Expression expression)
          Evaluate a top-level expression - this sets the current node, then resets it after evaluation
 Node first()
          Return the first node in the context node list.
 Node getCurrentNode()
          Return the current node for the outer-most expression This may be different that the current context node.
 ExpandedQName getExpandedName(String qName)
          Return the expanded name given the passed QName, given the current namespace context
 ContextListMark getMark()
          Return a marker to a position in a ContextNodeList.
protected  Node getNamespaceContext()
          Return the node that is the current context node for namespace resolution
 NamespaceName getNamespaceName(String prefix)
          Return the currently in-scope namespace URI for the passed prefix.
 Object getProperty(String name)
          Get an opaque property
 Node next()
          Return a the subsequent node in the context node list after a call to first() or next()
 int order()
          Return order in which nodes are returned from first()-next()
 void popState()
          Restore the last saved expression context state.
 int position()
          Return the position of the last node returned by a call to first() or next()
 void pushState()
          Save the current expression context state.
 void removeProperty(String name, Object value)
          Clear an opaque property
 Node returnToMark(ContextListMark mark)
          Go to a position in a ContextNodeList previously marked with getMark()
 void setContextNodeList(ContextNodeList list)
          Set the context node list for the expression context.
 void setNamespaceContext(Node node)
          Set the namespace context for the expression context.
 void setProperty(String name, Object value)
          Set an opaque property
 boolean stripNode(Node node)
          Return if a text or cdata section node should be stripped (not returned from an axis).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionContext

public ExpressionContext()
Create an empty ExpressionContext


ExpressionContext

public ExpressionContext(Map properties)
Create an empty ExpressionContext with extended properties

Parameters:
properties - Map instance that contains extended properties (may be null)

ExpressionContext

public ExpressionContext(ExpressionContext iVal)
Create a copy of an existing expression context, minus any saved state information.

Parameters:
iVal - The existing context.
Method Detail

evaluate

public ExpressionValue evaluate(Node currentNode,
                                Expression expression)
                         throws XPathEvaluationException
Evaluate a top-level expression - this sets the current node, then resets it after evaluation

Parameters:
currentNode - The context node for the expression
expression - The expression to evaluate
Returns:
The result of the evaluation
Throws:
XPathEvaluationException

pushState

public void pushState()
Save the current expression context state.


popState

public void popState()
Restore the last saved expression context state.


setContextNodeList

public void setContextNodeList(ContextNodeList list)
Set the context node list for the expression context.

Parameters:
list - The context node list to set.

setNamespaceContext

public void setNamespaceContext(Node node)
Set the namespace context for the expression context.

Parameters:
node - The namespace context node.

getCurrentNode

public Node getCurrentNode()
Return the current node for the outer-most expression This may be different that the current context node.

Returns:
The current node.

getNamespaceName

public NamespaceName getNamespaceName(String prefix)
Return the currently in-scope namespace URI for the passed prefix.

Specified by:
getNamespaceName in interface NamespaceContext
Parameters:
prefix - The QName prefix of interest
Returns:
The namespace name associated with the prefix for the passed prefix

getExpandedName

public ExpandedQName getExpandedName(String qName)
Return the expanded name given the passed QName, given the current namespace context

Specified by:
getExpandedName in interface NamespaceContext
Parameters:
qName - The QName to expand
Returns:
The expanded Name

first

public Node first()
           throws XPathEvaluationException
Return the first node in the context node list.

Specified by:
first in interface ContextNodeList
Returns:
First node in list. null is returned if list is empty
Throws:
XPathEvaluationException

next

public Node next()
          throws XPathEvaluationException
Return a the subsequent node in the context node list after a call to first() or next()

Specified by:
next in interface ContextNodeList
Returns:
The next node in the context node list. null is returned if there are no more nodes in the node list
Throws:
XPathEvaluationException

count

public int count()
          throws XPathEvaluationException
Return a count of nodes in the context node list. NOTE: this should be implemented with lazy evaluation if possible, since context node lists can be very large, depending on the document.

Specified by:
count in interface ContextNodeList
Returns:
Count of nodes in the context node list.
Throws:
XPathEvaluationException

position

public int position()
Return the position of the last node returned by a call to first() or next()

Specified by:
position in interface ContextNodeList
Returns:
Node position in node list. 0 is returned if no nodes have been returned. Once first() or next() return null (indicating no more nodes in list) the return will be the position of the last node in the list.

order

public int order()
Return order in which nodes are returned from first()-next()

Specified by:
order in interface ContextNodeList
Returns:
DOCUMENT_ORDER or REVERSE_DOCUMENT_ORDER

getMark

public ContextListMark getMark()
Return a marker to a position in a ContextNodeList. This marker can be used later in a call to returnToMark() to return to a particular position in the list.

Specified by:
getMark in interface ContextNodeList
Returns:
an opaque marker

returnToMark

public Node returnToMark(ContextListMark mark)
Go to a position in a ContextNodeList previously marked with getMark()

Specified by:
returnToMark in interface ContextNodeList
Parameters:
mark - mark returned from getMark()
Returns:
The node at the mark

stripNode

public boolean stripNode(Node node)
Return if a text or cdata section node should be stripped (not returned from an axis).

Specified by:
stripNode in interface WhitespaceStripper
Parameters:
node - The text or cdata section node to test
Returns:
True if the node should be stripped, false otherwise

getNamespaceContext

protected Node getNamespaceContext()
Return the node that is the current context node for namespace resolution

Returns:
The namespace context node

setProperty

public void setProperty(String name,
                        Object value)
Set an opaque property

Parameters:
name - the name of the property
value - the value of the property

removeProperty

public void removeProperty(String name,
                           Object value)
Clear an opaque property

Parameters:
name - the name of the property

getProperty

public Object getProperty(String name)
Get an opaque property

Parameters:
name - the name of the property
Returns:
the value of the property