## net.sf.saxon.value
Class AtomicValue

    java.lang.Object
      net.sf.saxon.value.Value
          net.sf.saxon.value.AtomicValue

All Implemented Interfaces:
  Expression, Item, java.io.Serializable, ValueRepresentation

Direct Known Subclasses:
  Base64BinaryValue, BooleanValue, CalendarValue, DurationValue, HexBinaryValue, NumericValue, ObjectValue, QNameValue, StringValue

public abstract class AtomicValue
extends Value
implements Item

The AtomicValue class corresponds to the concept of an atomic value in the XPath 2.0 data model. Atomic values belong to one of the 19 primitive types defined in XML Schema; or they are of type xdt:untypedAtomic; or they are "external objects", representing a Saxon extension to the XPath 2.0 type system.

The AtomicValue class contains some methods that are suitable for applications to use, and many others that are designed for internal use by Saxon itself. These have not been fully classified. At present, therefore, none of the methods on this class should be considered to be part of the public Saxon API.

See Also:
  Serialized Form

Field Summary

Fields inherited from class net.sf.saxon.value.Value
`EMPTY_CLASS_ARRAY`

Fields inherited from interface net.sf.saxon.om.ValueRepresentation
`EMPTY_VALUE_ARRAY`

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

Constructor Summary
`AtomicValue()`

Method Summary
`void` `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.
`AtomicValue` `convert(AtomicType targetType, XPathContext context, boolean validate)` Convert the value to a given type.
`AtomicValue` `convert(int requiredType, XPathContext context)` Convert the value to a given type.
`abstract AtomicValue` `convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)` Convert a value to another primitive data type, with control over how validation is handled.
`void` `display(int level, NamePool pool, java.io.PrintStream out)` Diagnostic print of expression structure
`boolean` `effectiveBooleanValue(XPathContext context)` Get the effective boolean value of the value
`java.lang.String` `evaluateAsString(XPathContext context)` Evaluate as a string
`Item` `evaluateItem(XPathContext context)` Evaluate the value (this simply returns the value unchanged)
`int` `getCardinality()` Determine the static cardinality
`AtomicValue` `getComponent(int component)` Method to extract components of a value.
`int` `getImplementationMethod()` An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
`int` `getLength()` Get the length of the sequence
`AtomicValue` `getPrimitiveValue()` Get the primitive value (the value in the value space).
`abstract java.lang.String` `getStringValue()` Convert the value to a string, using the serialization rules.
`java.lang.CharSequence` `getStringValueCS()` Get the value of the item as a CharSequence.
`SequenceIterator` `getTypedValue()` Get the typed value of this item
`boolean` `hasBuiltInType()` Test whether the type of this atomic value is a built-in type.
`SequenceIterator` `iterate(XPathContext context)` Iterate over the (single) item in the sequence
`void` `process(XPathContext context)` Process the instruction, without returning any tail calls
`boolean` `schemaEquals(Value obj)` Compare two values for equality.
`java.lang.String` `toString()` Get string value.

Methods inherited from class net.sf.saxon.value.Value
`asItem, asIterator, asValue, collapseWhitespace, convert, convertJavaObjectToXPath, convertToJava, equals, getDependencies, getItemType, getIterator, getParentExpression, getSpecialProperties, hashCode, itemAt, iterateSubExpressions, makeQNameValue, normalizeWhitespace, optimize, promote, reduce, simplify, stringToNumber, trimWhitespace, typeCheck`

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

Constructor Detail

### AtomicValue

    public AtomicValue()

Method Detail

### hasBuiltInType

    public boolean hasBuiltInType()

  Test whether the type of this atomic value is a built-in type. Default implementation returns true.

### getImplementationMethod

    public int getImplementationMethod()

  An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is prefered.

  Specified by:
    `getImplementationMethod` in interface `Expression`

### process

    public void process(XPathContext context)
                 throws XPathException

  Process the instruction, without returning any tail calls

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

### getCardinality

    public final int getCardinality()

  Determine the static cardinality

  Specified by:
    `getCardinality` in interface `Expression`
  Overrides:
    `getCardinality` in class `Value`
  Returns:
    code identifying the cardinality
  See Also:
    `Cardinality`

### convert

    public final AtomicValue convert(int requiredType,
                                     XPathContext context)
                              throws XPathException

  Convert the value to a given type. The result of the conversion will be an atomic value of the required type. This method works only where the target type is a built-in type.

  Parameters:
    `requiredType` - type code of the required atomic type
    `context` -
  Returns:
    the result of the conversion, if conversion was possible. This will always be an instance of the class corresponding to the type of value requested
  Throws:
    `XPathException` - if conversion is not allowed for this required type, or if the particular value cannot be converted

### convertPrimitive

    public abstract AtomicValue convertPrimitive(BuiltInAtomicType requiredType,
                                                 boolean validate,
                                                 XPathContext context)

  Convert a value to another primitive data type, with control over how validation is handled.

  Parameters:
    `requiredType` - type code of the required atomic type
    `validate` - true if validation is required. If set to false, the caller guarantees that the value is valid for the target data type, and that further validation is therefore not required. Note that a validation failure may be reported even if validation was not requested.
    `context` - The conversion context to be used. This is required at present only when converting to a date or time: it provides the implicit timezone.
  Returns:
    the result of the conversion, if successful. If unsuccessful, the value returned will be an ErrorValue. The caller must check for this condition. No exception is thrown, instead the exception will be encapsulated within the ErrorValue.

### convert

    public AtomicValue convert(AtomicType targetType,
                               XPathContext context,
                               boolean validate)

  Convert the value to a given type. The result of the conversion will be an atomic value of the required type. This method works where the target type is a built-in atomic type and also where it is a user-defined atomic type.

  Parameters:
    `targetType` - the type to which the value is to be converted
    `context` - provides access to conversion context
    `validate` - true if validation is required, false if the caller already knows that the value is valid
  Returns:
    the value after conversion if successful; or a `ValidationErrorValue` if conversion failed. The caller must check for this condition. Validation may fail even if validation was not requested.

### getLength

    public final int getLength()

  Get the length of the sequence

  Overrides:
    `getLength` in class `Value`
  Returns:
    always 1 for an atomic value

### evaluateItem

    public Item evaluateItem(XPathContext context)
                      throws XPathException

  Evaluate the value (this simply returns the value unchanged)

  Specified by:
    `evaluateItem` in interface `Expression`
  Overrides:
    `evaluateItem` in class `Value`
  Parameters:
    `context` - the evaluation context (not used in this implementation)
  Returns:
    the value, unchanged
  Throws:
    `XPathException`

### iterate

    public final SequenceIterator iterate(XPathContext context)

  Iterate over the (single) item in the sequence

  Specified by:
    `iterate` in interface `Expression`
  Parameters:
    `context` - the evaluation context (not used in this implementation)
  Returns:
    a SequenceIterator that iterates over the single item in this value

### evaluateAsString

    public final java.lang.String evaluateAsString(XPathContext context)

  Evaluate as a string

  Specified by:
    `evaluateAsString` in interface `Expression`
  Overrides:
    `evaluateAsString` in class `Value`
  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 "".

### getStringValue

    public abstract java.lang.String 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. This method is refined for AtomicValues so that it never throws an Exception.

  Specified by:
    `getStringValue` in interface `Item`
  Overrides:
    `getStringValue` in class `Value`

### getStringValueCS

    public java.lang.CharSequence 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 interface `Item`
  Returns:
    the string value of the item
  See Also:
    `Item.getStringValue()`

### getTypedValue

    public final SequenceIterator getTypedValue()

  Get the typed value of this item

  Specified by:
    `getTypedValue` in interface `Item`
  Returns:
    the typed value of the expression (which is this value)

### getPrimitiveValue

    public AtomicValue getPrimitiveValue()

  Get the primitive value (the value in the value space). This returns an AtomicValue of a class that would be used to represent the primitive value. In effect this means that for built-in types, it returns the value itself, but for user-defined type, it returns the primitive value minus the type annotation. Note that getItemType() when applied to the result of this function does not not necessarily return a primitive type: for example, this function may return a value of type xdt:dayTimeDuration, which is not a primitive type as defined by `Type.isPrimitiveType(int)`

### effectiveBooleanValue

    public boolean effectiveBooleanValue(XPathContext context)
                                  throws XPathException

  Get the effective boolean value of the value

  Specified by:
    `effectiveBooleanValue` in interface `Expression`
  Overrides:
    `effectiveBooleanValue` in class `Value`
  Parameters:
    `context` - the evaluation context (not used in this implementation)
  Returns:
    true, unless the value is boolean false, numeric zero, or zero-length string
  Throws:
    `XPathException` - if any dynamic error occurs evaluating the expression

### getComponent

    public AtomicValue getComponent(int component)
                             throws XPathException

  Method to extract components of a value. Implemented by some subclasses, but defined at this level for convenience

  Throws:
    `XPathException`

### 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 interface `Expression`
  Overrides:
    `checkPermittedContents` in class `Value`
  Parameters:
    `parentType` - The schema type
    `env` - the static context
    `whole` - true if this atomic value accounts for the entire content of the containing node
  Throws:
    `XPathException` - if the expression doesn't match the required content type

### toString

    public java.lang.String toString()

  Get string value. In general toString() for an atomic value displays the value as it would be written in XPath: that is, as a literal if available, or as a call on a constructor function otherwise.

  Overrides:
    `toString` in class `Value`

### schemaEquals

    public boolean schemaEquals(Value obj)

  Compare two 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. The default implementation of schemaEquals() is the same as equals(), but subclasses can override this.

  Overrides:
    `schemaEquals` in class `Value`

### display

    public final void display(int level,
                              NamePool pool,
                              java.io.PrintStream out)

  Diagnostic print of expression structure

  Specified by:
    `display` in interface `Expression`
  Overrides:
    `display` in class `Value`
  Parameters:
    `level` - the indentation level of the output
    `out` -