net.sf.saxon.value
Class SingletonNode

java.lang.Object
  extended by net.sf.saxon.value.Value
      extended by net.sf.saxon.value.SingletonNode
All Implemented Interfaces:
Serializable, Expression

public class SingletonNode
extends Value

A value that is a sequence containing zero or one nodes

See Also:
Serialized Form

Field Summary
protected  NodeInfo node
           
 
Constructor Summary
SingletonNode(NodeInfo node)
          Create a node-set containing zero or one nodes
 
Method Summary
 int conversionPreference(Class required)
          Get conversion preference for this value to a Java class.
 Object convertToJava(Class target)
          Convert to Java object (for passing to external functions)
 void display(int depth, NamePool pool)
          Diagnostic display
 boolean effectiveBooleanValue(XPathContext context)
          Get the effective boolean value
 String evaluateAsString(XPathContext context)
          Evaluate an expression as a String.
 Item evaluateItem(XPathContext context)
          Evaluate as an item
 int getCardinality()
          Determine the static cardinality
 ItemType getItemType()
          Determine the data type of the items in the expression
 NodeInfo getNode()
          Get the node that forms the node-set.
 int getSpecialProperties()
          Get the static properties of this expression (other than its type).
 SequenceIterator iterate(XPathContext context)
          Return an enumeration of this nodeset value.
 
Methods inherited from class net.sf.saxon.value.Value
analyze, asItem, asValue, collapseWhitespace, getDependencies, getSubExpressions, inverse, normalizeWhitespace, promote, simplify, stringToInteger, stringToNumber, trimWhitespace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

protected NodeInfo node
Constructor Detail

SingletonNode

public SingletonNode(NodeInfo node)
Create a node-set containing zero or one nodes

Parameters:
node - The node to be contained in the node-set, or null if the node-set is to be empty
Method Detail

getItemType

public ItemType getItemType()
Determine the data type of the items in the expression

Returns:
Type.NODE

getCardinality

public int getCardinality()
Determine the static cardinality

Returns:
one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).

getNode

public NodeInfo getNode()
Get the node that forms the node-set. Return null if there is none.


getSpecialProperties

public int getSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.

Specified by:
getSpecialProperties in interface Expression
Overrides:
getSpecialProperties in class Value
Returns:
a set of flags indicating static properties of this expression

iterate

public SequenceIterator iterate(XPathContext context)
Return an enumeration of this nodeset value.

Parameters:
context - supplies the context for evaluation
Returns:
a SequenceIterator that can be used to iterate over the result of the expression

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate as an item

Parameters:
context - The context in which the expression is to be evaluated
Returns:
the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
Get the effective boolean value

Parameters:
context - The context in which the expression is to be evaluated
Returns:
the effective boolean value

evaluateAsString

public String evaluateAsString(XPathContext context)
                        throws XPathException
Evaluate an expression as a String. This function must only be called in contexts where it is known that the expression will return a single string (or where an empty sequence is to be treated as a zero-length string). Implementations should not attempt to convert the result to a string, other than converting () to "". This method is used mainly to evaluate expressions produced by compiling an attribute value template.

Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context. The expression must return a string or (); if the value of the expression is (), this method returns "".
Throws:
XPathException - if any dynamic error occurs evaluating the expression

display

public void display(int depth,
                    NamePool pool)
Diagnostic display

Parameters:
depth - indentation level for this expression

conversionPreference

public int conversionPreference(Class required)
Get conversion preference for this value to a Java class. A low result indicates higher preference.

Specified by:
conversionPreference in class Value

convertToJava

public Object convertToJava(Class target)
                     throws XPathException
Convert to Java object (for passing to external functions)

Specified by:
convertToJava in class Value
Parameters:
target - The class required by the external function
Returns:
an object of the target class
Throws:
XPathException