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

Constructor Summary
Value()
           
 
Method Summary
 Expression analyze(StaticContext env)
          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
abstract  int conversionPreference(java.lang.Class required, Configuration config)
          Get conversion preference for this value to a Java class.
abstract  java.lang.Object convertToJava(java.lang.Class target, Configuration config)
          Convert the value to a Java object (for passing to external functions)
 int getDependencies()
          Determine which aspects of the context the expression depends on.
 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.
 Expression[] getSubExpressions()
          Get the sub-expressions of this expression.
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"
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()
          Simplify an expression
static double stringToNumber(java.lang.CharSequence s)
          Static method to convert strings to numbers.
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, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.expr.Expression
display, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getItemType, iterate
 

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()
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)
TypeCheck an expression

Specified by:
analyze in interface Expression
Parameters:
env - the static context of the expression
Returns:
for a Value, this always returns the value unchanged

getSubExpressions

public final Expression[] getSubExpressions()
Get the sub-expressions of this expression.

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

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. For QNames and NOTATIONS, or lists containing them, it fails.

XPathException

convertToJava

public abstract java.lang.Object convertToJava(java.lang.Class target,
                                               Configuration config)
                                        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

conversionPreference

public abstract int conversionPreference(java.lang.Class required,
                                         Configuration config)
Get conversion preference for this value to a Java class. A low result indicates higher preference.