net.sf.saxon.expr

Class Literal

public class Literal extends Expression

A Literal is an expression whose value is constant: it is a class that implements the Expression interface as a wrapper around a Value. This may derive from an actual literal in an XPath expression or query, or it may be the result of evaluating a constant subexpression such as true() or xs:date('2007-01-16')
Constructor Summary
Literal(Value value)
Create a literal as a wrapper around a Value
Method Summary
PathMap.PathMapNodeSetaddToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
intcomputeCardinality()
Determine the cardinality
intcomputeSpecialProperties()
Compute the static properties of this expression (other than its type).
Expressioncopy()
Copy an expression.
booleaneffectiveBooleanValue(XPathContext context)
Get the effective boolean value of the expression.
booleanequals(Object obj)
Determine whether two literals are equal, when considered as expressions.
CharSequenceevaluateAsString(XPathContext context)
ItemevaluateItem(XPathContext context)
Evaluate as a singleton item (or empty sequence).
voidevaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
intgetDependencies()
Determine which aspects of the context the expression depends on.
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items in the expression, if possible
ValuegetValue()
Get the value represented by this Literal
inthashCode()
Return a hash code to support the equals() function
static booleanisAtomic(Expression exp)
Test whether the literal wraps an atomic value.
static booleanisConstantBoolean(Expression exp, boolean value)
Test if a literal represents the boolean value true
static booleanisConstantOne(Expression exp)
Test if a literal represents the integer value 1
static booleanisEmptySequence(Expression exp)
Test whether the literal explicitly wraps an empty sequence.
booleanisSubtreeExpression()
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.
booleanisVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
static LiteralmakeEmptySequence()
Make an empty-sequence literal
static LiteralmakeLiteral(Value value)
Create a literal as a wrapper around a Value (factory method)
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize an expression
voidprocess(XPathContext context)
Process the value as an instruction, without returning any tail calls
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression
StringtoString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
TypeCheck an expression

Constructor Detail

Literal

public Literal(Value value)
Create a literal as a wrapper around a Value

Parameters: value the value of this literal

Method Detail

addToPathMap

public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.

Parameters: pathMap the PathMap to which the expression should be added pathMapNodeSet

Returns: the pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression

computeCardinality

public int computeCardinality()
Determine the cardinality

computeSpecialProperties

public int computeSpecialProperties()
Compute the static properties of this expression (other than its type). For a Value, the only special property is NON_CREATIVE.

Returns: the value NON_CREATIVE

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
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.

Parameters: context The context in which the expression is to be evaluated

Returns: the effective boolean value

Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression

equals

public boolean equals(Object obj)
Determine whether two literals are equal, when considered as expressions.

Parameters: obj the other expression

Returns: true if the two literals are equal. The test here requires (a) identity in the sense defined by XML Schema (same value in the same value space), and (b) identical type annotations. For example the literal xs:int(3) is not equal (as an expression) to xs:short(3), because the two expressions are not interchangeable.

evaluateAsString

public CharSequence evaluateAsString(XPathContext context)

evaluateItem

public Item evaluateItem(XPathContext context)
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.

evaluatePendingUpdates

public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List. The default implementation of this method, which is used for non-updating expressions, throws an UnsupportedOperationException. The implementation for a literal representing an empty sequence, however, is a no-op.

Parameters: context the XPath dynamic evaluation context pul the pending update list to which the results should be written

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

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

Returns: for a Value, this always returns zero.

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the items in the expression, if possible

Parameters: th The TypeHierarchy. Can be null if the target is an AtomicValue.

Returns: for the default implementation: AnyItemType (not known)

getValue

public Value getValue()
Get the value represented by this Literal

Returns: the constant value

hashCode

public int hashCode()
Return a hash code to support the equals() function

isAtomic

public static boolean isAtomic(Expression exp)
Test whether the literal wraps an atomic value. (Note, if this method returns false, this still leaves the possibility that the literal wraps a sequence that happens to contain a single atomic value).

Parameters: exp an expression

Returns: if the expression is a literal and the literal wraps an AtomicValue

isConstantBoolean

public static boolean isConstantBoolean(Expression exp, boolean value)
Test if a literal represents the boolean value true

Parameters: exp an expression value true or false

Returns: if the expression is a literal and the literal represents the boolean value given in the second argument

isConstantOne

public static boolean isConstantOne(Expression exp)
Test if a literal represents the integer value 1

Parameters: exp an expression

Returns: if the expression is a literal and the literal represents the integer value 1

isEmptySequence

public static boolean isEmptySequence(Expression exp)
Test whether the literal explicitly wraps an empty sequence. (Note, if this method returns false, this still leaves the possibility that the literal wraps a sequence that happens to be empty).

Parameters: exp an expression

Returns: if the expression is a literal and the literal wraps an AtomicValue

isSubtreeExpression

public boolean isSubtreeExpression()
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.

Returns: true if the expression has no dependencies on the context node, or if the only dependencies on the context node are downward selections using the self, child, descendant, attribute, and namespace axes.

isVacuousExpression

public boolean isVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification

Returns: true if this expression is vacuous

iterate

public SequenceIterator iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.

Parameters: context supplies the context for evaluation

Returns: a SequenceIterator that can be used to iterate over the result of the expression

Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression

makeEmptySequence

public static Literal makeEmptySequence()
Make an empty-sequence literal

Returns: a literal whose value is the empty sequence

makeLiteral

public static Literal makeLiteral(Value value)
Create a literal as a wrapper around a Value (factory method)

Parameters: value the value of this literal

Returns: the Literal

optimize

public final Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize an expression

Returns: for a Value, this always returns the value unchanged

process

public void process(XPathContext context)
Process the value as an instruction, without returning any tail calls

Parameters: context The dynamic context, giving access to the current node, the current variables, etc.

simplify

public Expression simplify(ExpressionVisitor visitor)
Simplify an expression

Parameters: visitor an expression visitor

Returns: for a Value, this always returns the value unchanged

toString

public String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
TypeCheck an expression

Returns: for a Value, this always returns the value unchanged