Class ConstantFunction

java.lang.Object
net.sf.saxon.functions.AbstractFunction
net.sf.saxon.functions.ConstantFunction
All Implemented Interfaces:
Callable, FunctionItem, GroundedValue, Item, Sequence

public class ConstantFunction extends AbstractFunction
A ConstantFunction is a zero-argument function that always delivers the same result, supplied at the time the function is created.
  • Constructor Details

    • ConstantFunction

      public ConstantFunction(StructuredQName name, GroundedValue value, SequenceType resultType)
      Create a ConstantFunction
      Parameters:
      name - the function name.
      value - the value to be returned by the function
      resultType - the return type of the function (must match the type of value
    • ConstantFunction

      public ConstantFunction(GroundedValue value, SequenceType resultType)
      Create an anonymous ConstantFunction
      Parameters:
      value - the value to be returned by the function
      resultType - the return type of the function (must match the type of value
  • Method Details

    • withAnnotationList

      public ConstantFunction withAnnotationList(AnnotationList annotationList)
      Add an annotation list
    • getAnnotations

      public AnnotationList getAnnotations()
      Get the annotation list
      Specified by:
      getAnnotations in interface FunctionItem
      Overrides:
      getAnnotations in class AbstractFunction
      Returns:
      the function annotations
    • getFunctionItemType

      public FunctionItemType getFunctionItemType()
      Get the item type of the function item
      Returns:
      the function item's type
    • getFunctionName

      public StructuredQName getFunctionName()
      Get the name of the function, or null if it is anonymous
      Returns:
      the function name, or null for an anonymous inline function
    • getArity

      public int getArity()
      Get the arity of the function
      Returns:
      the number of arguments in the function signature
    • getDescription

      public String getDescription()
      Get a description of this function for use in error messages. For named functions, the description is the function name (as a lexical QName). For others, it might be, for example, "inline function", or "partially-applied ends-with function".
      Returns:
      a description of the function for use in error messages
    • toShortString

      public String toShortString()
      Description copied from interface: FunctionItem
      Provide a short string showing the contents of the item, suitable for use in error messages
      Specified by:
      toShortString in interface FunctionItem
      Specified by:
      toShortString in interface GroundedValue
      Specified by:
      toShortString in interface Item
      Overrides:
      toShortString in class AbstractFunction
      Returns:
      a depiction of the item suitable for use in error messages
    • call

      public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException
      Description copied from interface: Callable
      Call the Callable.
      Parameters:
      context - the dynamic evaluation context
      arguments - the values of the arguments, supplied as Sequences.

      Generally it is advisable, if calling iterate() to process a supplied sequence, to call it only once; if the value is required more than once, it should first be converted to a GroundedValue by calling the utility method SequenceTool.toGroundedValue().

      If the expected value is a single item, the item should be obtained by calling Sequence.head(): it cannot be assumed that the item will be passed as an instance of Item or AtomicValue.

      It is the caller's responsibility to perform any type conversions required to convert arguments to the type expected by the callee. An exception is where this Callable is explicitly an argument-converting wrapper around the original Callable.

      Returns:
      the result of the evaluation, in the form of a Sequence. It is the responsibility of the callee to ensure that the type of result conforms to the expected result type.
      Throws:
      XPathException - if a dynamic error occurs during the evaluation of the expression
    • getConstantValue

      public GroundedValue getConstantValue()