Overview | Package | Class | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.sf.saxon.expr
Class Literal

    java.lang.Object
      net.sf.saxon.expr.Expression
          net.sf.saxon.expr.Literal

All Implemented Interfaces:
  Serializable, SourceLocator, Container, EvaluableItem, SequenceIterable, InstructionInfoProvider

Direct Known Subclasses:
  StringLiteral

    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')

See Also:
  Serialized Form

Field Summary

Fields inherited from class net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD`

Constructor Summary
`Literal(Value value)` Create a literal as a wrapper around a Value

Method Summary
`int` | `computeCardinality()` Determine the cardinality
`int` | `computeSpecialProperties()` Compute the static properties of this expression (other than its type).
`void` | `display(int level, PrintStream out, Configuration config)` Diagnostic display of the expression
`boolean` | `effectiveBooleanValue(XPathContext context)` Get the effective boolean value of the expression.
`boolean` | `equals(Object obj)` Determine whether two literals are equal, when considered as expressions.
`String` | `evaluateAsString(XPathContext context)` Evaluate an expression as a String.
`Item` | `evaluateItem(XPathContext context)` Evaluate as a singleton item (or empty sequence).
`int` | `getDependencies()` Determine which aspects of the context the expression depends on.
`ItemType` | `getItemType(TypeHierarchy th)` Determine the data type of the items in the expression, if possible
`Value` | `getValue()` Get the value represented by this Literal
`int` | `hashCode()` Return a hash code to support the equals() function
`static boolean` | `isAtomic(Expression exp)` Test whether the literal wraps an atomic value.
`static boolean` | `isConstantBoolean(Expression exp, boolean value)` Test if a literal represents the boolean value true
`static boolean` | `isConstantOne(Expression exp)` Test if a literal represents the integer value 1
`static boolean` | `isEmptySequence(Expression exp)` Test whether the literal explicitly wraps an empty sequence.
`SequenceIterator` | `iterate(XPathContext context)` Return an Iterator to iterate over the values of a sequence.
`static Literal` | `makeLiteral(Value value)` Create a literal as a wrapper around a Value
`Expression` | `optimize(Optimizer opt, StaticContext env, ItemType contextItemType)` Optimize an expression
`void` | `process(XPathContext context)` Process the value as an instruction, without returning any tail calls
`Expression` | `simplify(StaticContext env)` Simplify an expression
`Expression` | `typeCheck(StaticContext env, ItemType contextItemType)` TypeCheck an expression

Methods inherited from class net.sf.saxon.expr.Expression
`adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, getCardinality, getColumnNumber, getContainingProcedure, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getLineNumber, getLocationId, getLocationProvider, getParentExpression, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasBadParentPointer, iterateSubExpressions, markTailFunctionCalls, promote, replaceSubExpression, resetStaticProperties, setLocationId, setParentExpression, setParentExpression, suppressValidation`

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Literal

    public Literal(Value value)

  Create a literal as a wrapper around a Value

  Parameters:
    `value` -

Method Detail

### makeLiteral

    public static Literal makeLiteral(Value value)

  Create a literal as a wrapper around a Value

  Parameters:
    `value` -

### getValue

    public Value getValue()

  Get the value represented by this Literal

### simplify

    public final Expression simplify(StaticContext env)

  Simplify an expression

  Overrides:
    `simplify` in class `Expression`
  Returns:
    for a Value, this always returns the value unchanged

### typeCheck

    public final Expression typeCheck(StaticContext env,
                                      ItemType contextItemType)

  TypeCheck an expression

  Overrides:
    `typeCheck` in class `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

### optimize

    public final Expression optimize(Optimizer opt,
                                     StaticContext env,
                                     ItemType contextItemType)

  Optimize an expression

  Overrides:
    `optimize` in class `Expression`
  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 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

### getItemType

    public ItemType getItemType(TypeHierarchy th)

  Determine the data type of the items in the expression, if possible

  Specified by:
    `getItemType` in class `Expression`
  Parameters:
    `th` - The TypeHierarchy. Can be null if the target is an AtomicValue.
  Returns:
    for the default implementation: AnyItemType (not known)

### 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 `StaticProperty.NON_CREATIVE`.

  Overrides:
    `computeSpecialProperties` in class `Expression`
  Returns:
    `StaticProperty.NON_CREATIVE`

### 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

  Overrides:
    `getDependencies` in class `Expression`
  Returns:
    for a Value, this always returns zero.

### 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.

  Specified by:
    `iterate` in interface `SequenceIterable`
  Overrides:
    `iterate` in class `Expression`
  Parameters:
    `context` - supplies the context for evaluation
  Returns:
    a SequenceIterator that can be used to iterate over the result of the expression
  Throws:
    `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.

  Specified by:
    `evaluateItem` in interface `EvaluableItem`
  Overrides:
    `evaluateItem` in class `Expression`
  Parameters:
    `context` - The context in which the expression is to be evaluated
  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

    public void process(XPathContext context)
                 throws XPathException

  Process the value as an instruction, without returning any tail calls

  Overrides:
    `process` in class `Expression`
  Parameters:
    `context` - The dynamic context, giving access to the current node, the current variables, etc.
  Throws:
    `XPathException`

### evaluateAsString

    public String evaluateAsString(XPathContext context)
                            throws XPathException

  Description copied from class: `Expression`
  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.

  Overrides:
    `evaluateAsString` in class `Expression`
  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 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.

  Overrides:
    `effectiveBooleanValue` in class `Expression`
  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

    public boolean equals(Object obj)

  Determine whether two literals are equal, when considered as expressions.

  Overrides:
    `equals` in class `Object`
  Parameters:
    `obj` - the other expression
  Returns:
    true if the two literals are equal

### hashCode

    public int hashCode()

  Return a hash code to support the equals() function

  Overrides:
    `hashCode` in class `Object`

### display

    public void display(int level,
                        PrintStream out,
                        Configuration config)

  Diagnostic display of the expression

  Specified by:
    `display` in class `Expression`
  Parameters:
    `level` - indentation level for this expression
    `out` - Output destination

### 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

### 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

### 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

Overview | Package | Class | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) Michael H. Kay. All rights reserved.