net.sf.saxon.s9api

## Class XdmAtomicValue

- java.lang.Object
- - net.sf.saxon.s9api.XdmValue
  - - net.sf.saxon.s9api.XdmItem
    - - net.sf.saxon.s9api.XdmAtomicValue

- All Implemented Interfaces:
    Iterable<XdmItem>

      public class XdmAtomicValue
      extends XdmItem

  The class XdmAtomicValue represents an item in an XPath 2.0 sequence that is an atomic value. The value may belong to any of the 19 primitive types defined in XML Schema, or to a type derived from these primitive types, or the XPath 2.0 type xs:untypedAtomic. The type may be either a built-in type or a user-defined type.

  An `XdmAtomicValue` is immutable.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `XdmAtomicValue(AtomicValue value)`
    `` | `XdmAtomicValue(BigDecimal value)` Create an `xs:decimal` atomic value
    `` | `XdmAtomicValue(boolean value)` Create an `xs:boolean` atomic value
    `` | `XdmAtomicValue(double value)` Create an `xs:double` atomic value
    `` | `XdmAtomicValue(float value)` Create an `xs:float` atomic value
    `` | `XdmAtomicValue(long value)` Create an `xs:integer` atomic value
    `` | `XdmAtomicValue(QName value)` Create an `xs:QName` atomic value
    `` | `XdmAtomicValue(String value)` Create an `xs:string` atomic value
    `` | `XdmAtomicValue(String lexicalForm, ItemType type)` Construct an atomic value given its lexical representation and the name of the required built-in atomic type.
    `` | `XdmAtomicValue(URI value)` Create an `xs:anyURI` atomic value

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `getBooleanValue()` Get the value converted to a boolean using the XPath casting rules
    `BigDecimal` | `getDecimalValue()` Get the value converted to a decimal using the XPath casting rules
    `double` | `getDoubleValue()` Get the value converted to a double using the XPath casting rules.
    `long` | `getLongValue()` Get the value converted to an integer using the XPath casting rules
    `QName` | `getPrimitiveTypeName()` Get the primitive type of this atomic value, as a QName.
    `Object` | `getValue()` Get the value as a Java object of the nearest equivalent type.
    `String` | `toString()` Get the result of converting the atomic value to a string.

    - ### Methods inherited from class net.sf.saxon.s9api.XdmItem

      `getStringValue, isAtomicValue, newAtomicValue, size, wrapItem`

    - ### Methods inherited from class net.sf.saxon.s9api.XdmValue

      `append, getUnderlyingValue, itemAt, iterator, setValue, wrap`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### XdmAtomicValue

          protected XdmAtomicValue(AtomicValue value)

    - #### XdmAtomicValue

          public XdmAtomicValue(boolean value)

      Create an `xs:boolean` atomic value
      Parameters:
        `value` - the boolean value, true or false

    - #### XdmAtomicValue

          public XdmAtomicValue(long value)

      Create an `xs:integer` atomic value
      Parameters:
        `value` - the `xs:integer` value, as a long

    - #### XdmAtomicValue

          public XdmAtomicValue(BigDecimal value)

      Create an `xs:decimal` atomic value
      Parameters:
        `value` - the `xs:decimal` value, as a BigDecimal

    - #### XdmAtomicValue

          public XdmAtomicValue(double value)

      Create an `xs:double` atomic value
      Parameters:
        `value` - the `xs:double` value, as a double

    - #### XdmAtomicValue

          public XdmAtomicValue(float value)

      Create an `xs:float` atomic value
      Parameters:
        `value` - the `xs:float` value, as a float

    - #### XdmAtomicValue

          public XdmAtomicValue(String value)

      Create an `xs:string` atomic value
      Parameters:
        `value` - the `xs:string` value, as a string

    - #### XdmAtomicValue

          public XdmAtomicValue(URI value)

      Create an `xs:anyURI` atomic value
      Parameters:
        `value` - the `xs:anyURI` value, as a URI

    - #### XdmAtomicValue

          public XdmAtomicValue(QName value)

      Create an `xs:QName` atomic value
      Parameters:
        `value` - the `xs:QName` value, as a QName

    - #### XdmAtomicValue

          public XdmAtomicValue(String lexicalForm,
                        ItemType type)
                         throws SaxonApiException

      Construct an atomic value given its lexical representation and the name of the required built-in atomic type.

      This method cannot be used to construct values that are namespace-sensitive (QNames and Notations)

      Parameters:
        `lexicalForm` - the value in the lexical space of the target data type. More strictly, the input value before the actions of the whitespace facet for the target data type are applied.
        `type` - the required atomic type. This must either be one of the built-in atomic types defined in XML Schema, or a user-defined type whose definition appears in a schema that is known to the Processor. It must not be an abstract type.
      Throws:
        `SaxonApiException` - if the type is unknown, or is not atomic, or is namespace-sensitive; or if the value supplied in `lexicalForm` is not in the lexical space of the specified atomic type.

  - ### Method Detail

    - #### toString

          public String toString()

      Get the result of converting the atomic value to a string. This has the same effect as the XPath string() function.
      Overrides:
        `toString` in class `Object`

    - #### getPrimitiveTypeName

          public QName getPrimitiveTypeName()

      Get the primitive type of this atomic value, as a QName. The primitive types for this purpose are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration, and xs:untypedAtomic. For external objects, the result is xs:anyAtomicType.
      Returns:
        a QName naming the primitive type of this atomic value. This will always be an atomic type.

    - #### getValue

          public Object getValue()

      Get the value as a Java object of the nearest equivalent type.

      The result type is as follows:

      XPath type | Java class
      --- | ---
      xs:string | String
      xs:integer | java.math.BigInteger
      xs:decimal | java.math.BigDecimal
      xs:double | Double
      xs:float | Float
      xs:boolean | Boolean
      xs:QName | QName
      xs:anyURI | String
      xs:untypedAtomic | String
      Other types | currently String, but this may change in the future

      Returns:
        the value, converted to a Java object of a suitable type

    - #### getBooleanValue

          public boolean getBooleanValue()
                                  throws SaxonApiException

      Get the value converted to a boolean using the XPath casting rules
      Returns:
        the result of converting to a boolean (Note: this is not the same as the effective boolean value).
      Throws:
        `SaxonApiException` - if the value cannot be cast to a boolean

    - #### getLongValue

          public long getLongValue()
                            throws SaxonApiException

      Get the value converted to an integer using the XPath casting rules
      Returns:
        the result of converting to an integer
      Throws:
        `SaxonApiException` - if the value cannot be cast to an integer

    - #### getDoubleValue

          public double getDoubleValue()
                                throws SaxonApiException

      Get the value converted to a double using the XPath casting rules.

      If the value is a string, the XSD 1.1 rules are used, which means that the string "+INF" is recognised.

      Returns:
        the result of converting to a double
      Throws:
        `SaxonApiException` - if the value cannot be cast to a double

    - #### getDecimalValue

          public BigDecimal getDecimalValue()
                                     throws SaxonApiException

      Get the value converted to a decimal using the XPath casting rules
      Returns:
        the result of converting to a decimal
      Throws:
        `SaxonApiException` - if the value cannot be cast to a double

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.