net.sf.saxon.value
Class Value

java.lang.Object
  |
  +--net.sf.saxon.value.Value
All Implemented Interfaces:
Expression, java.io.Serializable
Direct Known Subclasses:
AtomicValue, SequenceValue, SingletonNode

public abstract class Value
extends java.lang.Object
implements Expression, java.io.Serializable

A value is the result of an expression but it is also an expression in its own right. Note that every value can be regarded as a sequence - in many cases, a sequence of length one.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
 
Constructor Summary
Value()
           
 
Method Summary
 Expression analyze(StaticContext env, ItemType contextItemType)
          TypeCheck an expression
static Item asItem(Value value, XPathContext context)
          Static method to make an Item from a Value
static Value asValue(Item item)
          Static method to make a Value from a given Item (which may be either an AtomicValue or a NodeInfo
static java.lang.CharSequence collapseWhitespace(java.lang.CharSequence in)
          Collapse whitespace as defined in XML Schema
static Value convertJavaObjectToXPath(java.lang.Object result, Controller controller)
          Convert a Java object to an XPath value.
abstract  java.lang.Object convertToJava(java.lang.Class target, Configuration config, XPathContext context)
          Convert the value to a Java object (for passing to external functions)
 int getDependencies()
          Determine which aspects of the context the expression depends on.
 Container getParentExpression()
          Get the expression that immediately contains this expression.
 int getSpecialProperties()
          Get the static properties of this expression (other than its type).
abstract  java.lang.String getStringValue()
          Convert the value to a string, using the serialization rules.
static int inverse(int operator)
          Return the inverse of a relational operator, so that "a op b" can be rewritten as "b inverse(op) a"
 java.util.Iterator iterateSubExpressions()
          Get the sub-expressions of this expression.
static java.lang.CharSequence normalizeWhitespace(java.lang.CharSequence in)
          Normalize whitespace as defined in XML Schema
 Expression promote(PromotionOffer offer)
          Offer promotion for this subexpression.
 Expression simplify(StaticContext env)
          Simplify an expression
static double stringToNumber(java.lang.CharSequence s)
          Static method to convert strings to numbers.
 java.lang.String toString()
          Convert to a string for diagnostic output
static java.lang.CharSequence trimWhitespace(java.lang.CharSequence in)
          Remove leading and trailing whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.expr.Expression
display, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getImplementationMethod, getItemType, iterate, process
 

Constructor Detail

Value

public Value()
Method Detail

asValue

public static Value asValue(Item item)
Static method to make a Value from a given Item (which may be either an AtomicValue or a NodeInfo

Parameters:
item - The supplied item, or null, indicating the empty sequence.
Returns:
The supplied item, if it is a value, or a SingletonNode that wraps the item, if it is a node. If the supplied value was null, return an EmptySequence

asItem

public static Item asItem(Value value,
                          XPathContext context)
                   throws XPathException
Static method to make an Item from a Value

Parameters:
value - the value to be converted
context - the context. It is probably safe to set this to null.
Returns:
null if the value is an empty sequence; or the only item in the value if it is a singleton sequence
Throws:
XPathException - if the Value contains multiple items

stringToNumber

public static double stringToNumber(java.lang.CharSequence s)
                             throws java.lang.NumberFormatException
Static method to convert strings to numbers. Might as well go here as anywhere else.

Parameters:
s - the String to be converted
Returns:
a double representing the value of the String
Throws:
java.lang.NumberFormatException - if the value cannot be converted

normalizeWhitespace

public static java.lang.CharSequence normalizeWhitespace(java.lang.CharSequence in)
Normalize whitespace as defined in XML Schema


collapseWhitespace

public static java.lang.CharSequence collapseWhitespace(java.lang.CharSequence in)
Collapse whitespace as defined in XML Schema


trimWhitespace

public static java.lang.CharSequence trimWhitespace(java.lang.CharSequence in)
Remove leading and trailing whitespace. This has the same effect as collapseWhitespace, but is cheaper, for use by data types that do not allow internal whitespace.

Parameters:
in - the input string whose whitespace is to be removed
Returns:
the result of removing excess whitespace

simplify

public final Expression simplify(StaticContext env)
Simplify an expression

Specified by:
simplify in interface Expression
Returns:
for a Value, this always returns the value unchanged

analyze

public final Expression analyze(StaticContext env,
                                ItemType contextItemType)
TypeCheck an expression

Specified by:
analyze in interface Expression
Parameters:
env - the static context of the expression
contextItemType - the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set to Type.ITEM_TYPE
Returns:
for a Value, this always returns the value unchanged

iterateSubExpressions

public final java.util.Iterator iterateSubExpressions()
Get the sub-expressions of this expression.

Specified by:
iterateSubExpressions in interface Expression
Returns:
for a Value, this always returns an empty array

getParentExpression

public Container getParentExpression()
Get the expression that immediately contains this expression. This method returns null for an outermost expression; it also return null in the case of literal values. For an XPath expression occurring within an XSLT stylesheet, this method returns the XSLT instruction containing the XPath expression.

Specified by:
getParentExpression in interface Expression
Returns:
the expression that contains this expression, if known; return null if there is no containing expression or if the containing expression is unknown.

getSpecialProperties

public int getSpecialProperties()
Get the static properties of this expression (other than its type). For a Value, there are no special properties, so the return value is always zero.

Specified by:
getSpecialProperties in interface Expression
Returns:
zero

promote

public Expression promote(PromotionOffer offer)
Offer promotion for this subexpression. Values (constant expressions) are never promoted

Specified by:
promote in interface Expression
Parameters:
offer - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
Returns:
For a Value, this always returns the value unchanged

getDependencies

public final int getDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as StaticProperty.VARIABLES and StaticProperty.CURRENT_NODE

Specified by:
getDependencies in interface Expression
Returns:
for a Value, this always returns zero.

inverse

public static final int inverse(int operator)
Return the inverse of a relational operator, so that "a op b" can be rewritten as "b inverse(op) a"


getStringValue

public abstract java.lang.String getStringValue()
                                         throws XPathException
Convert the value to a string, using the serialization rules. For atomic values this is the same as a cast; for sequence values it gives a space-separated list.

XPathException

convertToJava

public abstract java.lang.Object convertToJava(java.lang.Class target,
                                               Configuration config,
                                               XPathContext context)
                                        throws XPathException
Convert the value to a Java object (for passing to external functions)

Parameters:
target - The class required by the external function
config - The configuration (needed for access to schema information)
Returns:
an object of the target class
XPathException

convertJavaObjectToXPath

public static Value convertJavaObjectToXPath(java.lang.Object result,
                                             Controller controller)
                                      throws XPathException
Convert a Java object to an XPath value. This method is called to handle the result of an external function call (but only if the required type is not known), and also to process global parameters passed to the stylesheet.

Parameters:
result - The Java object to be converted
controller - The controller: may be null, in which case a Source object cannot be supplied
Returns:
the result of converting the value. If the value is null, returns null.
XPathException

toString

public java.lang.String toString()
Convert to a string for diagnostic output

Overrides:
toString in class java.lang.Object