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')
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.
- addToPathMap in interface Expression
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
-
- 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
copy
public Expression copy()
Copy an expression. This makes a deep copy.
- copy in interface Expression
- the copy of the original expression
effectiveBooleanValue
public boolean effectiveBooleanValue(XPathContext context)
throws XPathException
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.
- effectiveBooleanValue in interface Expression
context
- The context in which the expression is to be evaluated
- the effective boolean value
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.
obj
- the other expression
- true if the two literals are equal
evaluateAsString
public CharSequence 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.
- evaluateAsString in interface Expression
context
- The context in which the expression is to be evaluated
- 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 "".
XPathException
- if any dynamic error occurs evaluating the
expression
evaluateItem
public Item evaluateItem(XPathContext context)
throws XPathException
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.
- evaluateItem in interface EvaluableItem
- evaluateItem in interface Expression
explain
public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree
is written to the supplied output destination.
- explain in interface Expression
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
- getDependencies in interface Expression
- 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
- getItemType in interface Expression
th
- The TypeHierarchy. Can be null if the target is an AtomicValue.
- for the default implementation: AnyItemType (not known)
getValue
public Value getValue()
Get the value represented by this Literal
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).
- 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
exp
- an expressionvalue
- true or false
- 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
- 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).
- if the expression is a literal and the literal wraps an AtomicValue
iterate
public SequenceIterator iterate(XPathContext context)
throws XPathException
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.
- iterate in interface SequenceIterable
- iterate in interface Expression
context
- supplies the context for evaluation
- a SequenceIterator that can be used to iterate over the result
of the expression
XPathException
- if any dynamic error occurs evaluating the
expression
makeEmptySequence
public static Literal makeEmptySequence()
Make an empty-sequence literal
- 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)
value
- the value of this literal
process
public void process(XPathContext context)
throws XPathException
Process the value as an instruction, without returning any tail calls
- process in interface Expression
context
- The dynamic context, giving access to the current node,
the current variables, etc.
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
- toString in interface Expression