Package net.sf.saxon.value
Class Value
java.lang.Object
net.sf.saxon.value.Value
- All Implemented Interfaces:
Serializable
,Expression
,ValueRepresentation
- Direct Known Subclasses:
AtomicValue
,Closure
,EmptySequence
,IntegerRange
,SequenceExtent
,ShareableSequence
,SingletonNode
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:
-
Field Summary
FieldsFields inherited from interface net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Item
asItem
(ValueRepresentation value) Static method to make an Item from a Valuestatic SequenceIterator
asIterator
(ValueRepresentation val, XPathContext context) Static method to get an Iterator over any ValueRepresentation (which may be either a Value or a NodeInfostatic Value
Static method to make a Value from a given Item (which may be either an AtomicValue or a NodeInfovoid
checkPermittedContents
(SchemaType parentType, StaticContext env, boolean whole) Check statically that the results of the expression are capable of constructing the content of a given schema type.static Object
Internal method to convert an XPath value to a Java object.static Value
convertJavaObjectToXPath
(Object object, SequenceType requiredType, Configuration config) Convert a Java object to an XPath value.convertToJava
(Class target, XPathContext context) Convert to Java object (for passing to external functions)void
display
(int level, PrintStream out, Configuration config) Diagnostic display of the expressionboolean
effectiveBooleanValue
(XPathContext context) Get the effective boolean value of the expression.boolean
Compare two (sequence) values for equality.evaluateAsString
(XPathContext context) Evaluate an expression as a String.evaluateItem
(XPathContext context) Evaluate as a singleton item (or empty sequence).int
Determine the cardinalityfinal int
Determine which aspects of the context the expression depends on.Determine the data type of the items in the expression, if possiblestatic SequenceIterator
Get a SequenceIterator over a ValueRepresentationint
Get the length of the sequencefinal Container
Get the expression that immediately contains this expression.int
Get the static properties of this expression (other than its type).Convert the value to a string, using the serialization rules.Get the value of the item as a CharSequence.int
hashCode()
Return a hash code to support the equals() functionitemAt
(int n) Get the n'th item in the sequence (starting from 0).final Iterator
Get the sub-expressions of this expression.static QNameValue
makeQNameValue
(Object object, Configuration config) Temporary method to make a QNameValue from a JAXP 1.3 QName, without creating a compile-time link to the JDK 1.5 QName classfinal Expression
optimize
(Optimizer opt, StaticContext env, ItemType contextItemType) Optimize an expressionvoid
process
(XPathContext context) Process the value as an instruction, without returning any tail callsfinal Expression
promote
(PromotionOffer offer) Offer promotion for this subexpression.reduce()
Reduce a value to its simplest form.final Expression
simplify
(StaticContext env) Simplify an expressionstatic double
Static method to convert strings to numbers.toString()
Convert to a string for diagnostic outputfinal Expression
typeCheck
(StaticContext env, ItemType contextItemType) TypeCheck an expressionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.saxon.expr.Expression
getImplementationMethod, iterate
-
Field Details
-
EMPTY_CLASS_ARRAY
-
-
Constructor Details
-
Value
public Value()
-
-
Method Details
-
asValue
Static method to make a Value from a given Item (which may be either an AtomicValue or a NodeInfo- Parameters:
val
- The supplied value, or null, indicating the empty sequence.- Returns:
- The supplied value, 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
Static method to make an Item from a Value- Parameters:
value
- the value to be converted- 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
-
asIterator
public static SequenceIterator asIterator(ValueRepresentation val, XPathContext context) throws XPathException Static method to get an Iterator over any ValueRepresentation (which may be either a Value or a NodeInfo- Parameters:
val
- The supplied value, or null, indicating the empty sequence.context
- The evaluation context. This may be null. It should always be possible to iterate over a value without supplying a context, but sometimes the context can provide access to better error information- Returns:
- The supplied value, 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
- Throws:
XPathException
-
stringToNumber
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:
NumberFormatException
- if the value cannot be converted
-
getIterator
Get a SequenceIterator over a ValueRepresentation- Throws:
XPathException
-
getStringValueCS
Get the value of the item as a CharSequence. This is in some cases more efficient than the version of the method that returns a String.- Specified by:
getStringValueCS
in interfaceValueRepresentation
- Throws:
XPathException
- The method can fail if evaluation of the value has been deferred, and if a failure occurs during the deferred evaluation. No failure is possible in the case of an AtomicValue or a Node.
-
simplify
Simplify an expression- Specified by:
simplify
in interfaceExpression
- Parameters:
env
- the static context- Returns:
- for a Value, this always returns the value unchanged
-
typeCheck
TypeCheck an expression- Specified by:
typeCheck
in interfaceExpression
- Parameters:
env
- the static context of the expressioncontextItemType
- 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 toType.ITEM_TYPE
- Returns:
- for a Value, this always returns the value unchanged
-
optimize
Optimize an expression- Specified by:
optimize
in interfaceExpression
- Parameters:
opt
- the optimizer in use. This provides access to supporting functions; it also allows different optimization strategies to be used in different circumstances.env
- the static context of the expressioncontextItemType
- 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 toType.ITEM_TYPE
- Returns:
- for a Value, this always returns the value unchanged
-
getItemType
Determine the data type of the items in the expression, if possible- Specified by:
getItemType
in interfaceExpression
- Parameters:
th
- The TypeHierarchy. Can be null if the target is an AtomicValue.- Returns:
- for the default implementation: AnyItemType (not known)
-
getCardinality
public int getCardinality()Determine the cardinality- Specified by:
getCardinality
in interfaceExpression
- Returns:
- one of the values
StaticProperty.ALLOWS_ONE
,StaticProperty.ALLOWS_ZERO_OR_MORE
,StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.ALLOWS_ONE_OR_MORE
,StaticProperty.EMPTY
. This default implementation returns ZERO_OR_MORE (which effectively gives no information).
-
iterateSubExpressions
Get the sub-expressions of this expression.- Specified by:
iterateSubExpressions
in interfaceExpression
- Returns:
- for a Value, this always returns an empty array
-
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 interfaceExpression
- 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, the only special property isStaticProperty.NON_CREATIVE
.- Specified by:
getSpecialProperties
in interfaceExpression
- Returns:
StaticProperty.NON_CREATIVE
-
promote
Offer promotion for this subexpression. Values (constant expressions) are never promoted- Specified by:
promote
in interfaceExpression
- 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 interfaceExpression
- Returns:
- for a Value, this always returns zero.
-
itemAt
Get the n'th item in the sequence (starting from 0). This is defined for all Values, but its real benefits come for a sequence Value stored extensionally (or for a MemoClosure, once all the values have been read)- Throws:
XPathException
-
getLength
Get the length of the sequence- Throws:
XPathException
-
evaluateItem
Evaluate as a singleton item (or empty sequence). Note: this implementation returns the first item in the sequence. The method should not be used unless appropriate type-checking has been done to ensure that the value will be a singleton.- Specified by:
evaluateItem
in interfaceExpression
- Parameters:
context
- The context in which the expression is to be evaluated. Note that this context must contain a stackframe with sufficient slots to allow evaluation of any variables contained in the expression (including variables allocated internally by the optimizer)- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
process
Process the value as an instruction, without returning any tail calls- Specified by:
process
in interfaceExpression
- Parameters:
context
- The dynamic context, giving access to the current node, the current variables, etc.- Throws:
XPathException
-
getStringValue
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.- Specified by:
getStringValue
in interfaceValueRepresentation
- Throws:
XPathException
- The method can fail if evaluation of the value has been deferred, and if a failure occurs during the deferred evaluation. No failure is possible in the case of an AtomicValue.
-
evaluateAsString
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.- Specified by:
evaluateAsString
in interfaceExpression
- 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 expressionClassCastException
- if the result type of the expression is not xs:string?
-
effectiveBooleanValue
Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.- Specified by:
effectiveBooleanValue
in interfaceExpression
- Parameters:
context
- The context in which the expression is to be evaluated- Returns:
- the effective boolean value
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
equals
Compare two (sequence) values for equality. This supports identity constraints in XML Schema, which allow list-valued elements and attributes to participate in key and uniqueness constraints. This method returns false if any error occurs during the comparison, or if any of the items in either sequence is a node rather than an atomic value. -
hashCode
public int hashCode()Return a hash code to support the equals() function -
checkPermittedContents
public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException Check statically that the results of the expression are capable of constructing the content of a given schema type.- Specified by:
checkPermittedContents
in interfaceExpression
- Parameters:
parentType
- The schema typeenv
- the static contextwhole
-- Throws:
XPathException
- if the expression doesn't match the required content type
-
reduce
Reduce a value to its simplest form. If the value is a closure or some other form of deferred value such as a FunctionCallPackage, then it is reduced to a SequenceExtent. If it is a SequenceExtent containing a single item, then it is reduced to that item. One consequence that is exploited by class FilterExpression is that if the value is a singleton numeric value, then the result will be an instance of NumericValue- Throws:
XPathException
-
convertToJava
Convert to Java object (for passing to external functions)- Throws:
XPathException
-
display
Diagnostic display of the expression- Specified by:
display
in interfaceExpression
- Parameters:
level
- indentation level for this expressionout
- Output destinationconfig
-
-
convertJavaObjectToXPath
public static Value convertJavaObjectToXPath(Object object, SequenceType requiredType, Configuration config) 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 or query.- Parameters:
object
- The Java object to be convertedrequiredType
- The required type of the result (if known)config
- The Configuration: may be null, in which case certain kinds of object (eg. DOM nodes) cannot be handled- Returns:
- the result of converting the value. If the value is null, returns null.
- Throws:
XPathException
-
makeQNameValue
Temporary method to make a QNameValue from a JAXP 1.3 QName, without creating a compile-time link to the JDK 1.5 QName class- Parameters:
object
- an instance of javax.xml.namespace.QName- Returns:
- a corresponding Saxon QNameValue, or null if any error occurs performing the conversion
-
toString
Convert to a string for diagnostic output -
convert
Internal method to convert an XPath value to a Java object. An atomic value is returned as an instance of the best available Java class. If the item is a node, the node is "unwrapped", to return the underlying node in the original model (which might be, for example, a DOM or JDOM node).- Throws:
XPathException
-