com.marklogic.xcc

## Class ValueFactory

- java.lang.Object
- - com.marklogic.xcc.ValueFactory

-     public final class ValueFactory
      extends java.lang.Object

  This class contains various static factory methods that return instances of `XdmValue` and `XdmVariable`.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ArrayNode` | `newArrayNode(java.lang.Object value)` Convenience method to construct an `ArrayNode` value.
    `static XdmBinary` | `newBinaryNode(java.lang.Object value)`
    `static BooleanNode` | `newBooleanNode(boolean value)` Convenience method to construct an `BooleanNode` value.
    `static BooleanNode` | `newBooleanNode(java.lang.Object value)` Convenience method to construct an `BooleanNode` value.
    `static XdmComment` | `newCommentNode(java.lang.Object value)` A convenience method to construct an `XdmComment` value.
    `static CtsBox` | `newCtsBox(java.lang.String south, java.lang.String west, java.lang.String north, java.lang.String east)` Convenience method to construct a `CtsBox` value.
    `static CtsCircle` | `newCtsCircle(java.lang.String radius, CtsPoint center)` Convenience method to construct a `CtsCircle` value.
    `static CtsPoint` | `newCtsPoint(java.lang.String latitude, java.lang.String longitude)` Convenience method to construct a `CtsPoint` value.
    `static CtsPolygon` | `newCtsPolygon(java.util.List<CtsPoint> vertices)` Convenience method to construct a `CtsPolygon` value.
    `static XdmDocument` | `newDocumentNode(java.lang.Object value)` A convenience method to construct an `XdmDocument` value.
    `static XdmDuration` | `newDuration(java.lang.String serializedString)` Convenience method to construct an `XdmDuration` value.
    `static XdmElement` | `newElement(java.lang.Object value)` A convenience method to construct an `XdmElement` value.
    `static JSArray` | `newJSArray(com.fasterxml.jackson.databind.node.ArrayNode value)` Convenience method to construct an `JSArray` value from a Jackson ArrayNode.
    `static JSArray` | `newJSArray(java.lang.String serializedString)` Convenience method to construct an `JSArray` value.
    `static JSNull` | `newJSNull()` Convenience method to construct an `JSNull` value.
    `static JSObject` | `newJSObject(com.fasterxml.jackson.databind.node.ObjectNode value)` Convenience method to construct an `JSObject` value from a Jackson ObjectNode.
    `static JSObject` | `newJSObject(java.lang.String serializedString)` Convenience method to construct an `JSObject` value.
    `static NullNode` | `newNullNode(java.lang.Object value)` Convenience method to construct an `NullNode` value.
    `static NumberNode` | `newNumberNode(double value)` Convenience method to construct an `NumberNode` value.
    `static NumberNode` | `newNumberNode(java.lang.Object value)` Convenience method to construct an `NumberNode` value.
    `static XdmNode` | `newObjectNode(java.lang.Object value)` Convenience method to construct an `ObjectNode` value.
    `static XdmProcessingInstruction` | `newProcessingInstructionNode(java.lang.Object value)` A convenience method to construct an `XdmProcessingInstruction` value.
    `static XdmSequence<XdmItem>` | `newSequence(XdmValue[] values)` Factory method to construct an `XdmSequence` from an array of `XdmValue` objects.
    `static XdmText` | `newTextNode(java.lang.Object value)` A convenience method to construct an `XdmText` value.
    `static XdmValue` | `newValue(ValueType valueType, java.lang.Object value)` Generic `XdmValue` creation factory method.
    `static XdmVariable` | `newVariable(XName name, XdmValue value)` Factory method to create a variable (named value) from the given `XName` and `XdmValue` objects.
    `static VecVector` | `newVecVector(float[] values)` Convenience method to construct a `VecVector` value.
    `static XSBoolean` | `newXSBoolean(boolean value)` A convenience method to construct an `XSBoolean` value.
    `static XSDate` | `newXSDate(java.lang.String value, java.util.TimeZone timeZone, java.util.Locale locale)` A convenience method to construct an `XSDate` value.
    `static XSDateTime` | `newXSDateTime(java.lang.String value, java.util.TimeZone timeZone, java.util.Locale locale)` A convenience method to construct an `XSDateTime` value.
    `static XSDuration` | `newXSDuration(java.lang.String value)` A convenience method to construct an `XSDuration` value.
    `static XSDuration` | `newXSDuration(XdmDuration duration)` A convenience method to construct an `XSDuration` value from an `XdmDuration` object.
    `static XSInteger` | `newXSInteger(java.math.BigInteger value)` A convenience method to construct an `XSInteger` value.
    `static XSInteger` | `newXSInteger(long value)` A convenience method to construct an `XSInteger` value.
    `static XSString` | `newXSString(java.lang.String value)` A convenience method to construct an `XSString` value.
    `static XSTime` | `newXSTime(java.lang.String value, java.util.TimeZone timeZone, java.util.Locale locale)` A convenience method to construct an `XSTime` value.

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

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

- - ### Method Detail

    - #### newValue

          public static XdmValue newValue(ValueType valueType,
                                          java.lang.Object value)

      Generic `XdmValue` creation factory method. Value types are enumerated in `ValueType`. Examples are `ValueType.XS_INTEGER`, `ValueType.XS_BOOLEAN`, `ValueType.SEQUENCE`, `ValueType.XS_STRING`, etc.

      NOTE: If you pass a valueType of `ValueType.NODE`, it will be treated as `ValueType.ELEMENT`. Using `ValueType.NODE` directly is discouraged, it is defined as the common super-type for all node types. Other node types that may be constructed are `ValueType.TEXT` and `ValueType.BINARY`. In future releases, creation of additional node value types will be supported.

      Parameters:
        `valueType` - An concrete subclass of `ValueType` which indicates the type of value to create.
        `value` - An `Object` containing the actual value to construct the object with. The specific class of this object is be dependent on the valueType argument. If the provided value is not consistent with the valueType then a `IllegalArgumentException` may be thrown.
      Returns:
        An instance of `XdmValue`.
      Throws:
        `java.lang.IllegalArgumentException` - If the provided value is not consistent with the valueType.

    - #### newElement

          public static XdmElement newElement(java.lang.Object value)

      A convenience method to construct an `XdmElement` value. `XdmElement` objects can be constructed from an XML `String`, a W3C DOM `Element` or an `InputStream`.

      Parameters:
        `value` - An instance of `String`, `Element` or `InputStream`.
      Returns:
        An instance of `XdmElement`.
      Throws:
        `java.lang.IllegalArgumentException` - If value is not a `String`, `Element` or `InputStream`.

    - #### newDocumentNode

          public static XdmDocument newDocumentNode(java.lang.Object value)

      A convenience method to construct an `XdmDocument` value. `XdmDocument` objects can be constructed from an XML `String`, a W3C DOM `Document` or an `InputStream`.

      Parameters:
        `value` - An instance of `String`, `Document` or `InputStream`.
      Returns:
        An instance of `XdmDocument`.
      Throws:
        `java.lang.IllegalArgumentException` - If value is not a `String`, `Document` or `InputStream`.

    - #### newTextNode

          public static XdmText newTextNode(java.lang.Object value)

      A convenience method to construct an `XdmText` value. `XdmText` objects can be constructed from an XML `String`, a W3C DOM `Text` node or an `InputStream` .
      Parameters:
        `value` - An instance of `String`, `Text` or `InputStream`.
      Returns:
        An instance of `XdmText`.
      Throws:
        `java.lang.IllegalArgumentException` - If value is not a `String`, `Text` or `InputStream`.

    - #### newCommentNode

          public static XdmComment newCommentNode(java.lang.Object value)

      A convenience method to construct an `XdmComment` value. `XdmComment` objects can be constructed from an XML `String`, a W3C DOM `Comment` node or an `InputStream` .
      Parameters:
        `value` - An instance of `String`, `Comment` or `InputStream`.
      Returns:
        An instance of `XdmComment`.
      Throws:
        `java.lang.IllegalArgumentException` - If value is not a `String`, `Comment` or `InputStream`.

    - #### newProcessingInstructionNode

          public static XdmProcessingInstruction newProcessingInstructionNode(java.lang.Object value)

      A convenience method to construct an `XdmProcessingInstruction` value. `XdmProcessingInstruction` objects can be constructed from an XML `String`, a W3C DOM `ProcessingInstruction` node or an `InputStream` .
      Parameters:
        `value` - An instance of `String`, `ProcessingInstruction` or `InputStream`.
      Returns:
        An instance of `XdmProcessingInstruction`.
      Throws:
        `java.lang.IllegalArgumentException` - If value is not a `String`, `ProcessingInstruction` or `InputStream`.

    - #### newBinaryNode

          public static XdmBinary newBinaryNode(java.lang.Object value)

    - #### newArrayNode

          public static ArrayNode newArrayNode(java.lang.Object value)

      Convenience method to construct an `ArrayNode` value. Object can be constructed from `String`, `ArrayNode`, or `InputStream`.
      Parameters:
        `value` - An instance of `String`, `ArrayNode` or `InputStream`.
      Returns:
        An instance of `ArrayNode`.

    - #### newBooleanNode

          public static BooleanNode newBooleanNode(java.lang.Object value)

      Convenience method to construct an `BooleanNode` value. Object can be constructed from `String`, `BooleanNode`, or `InputStream`.
      Parameters:
        `value` - An instance of `String`, `BooleanNode` or `InputStream`.
      Returns:
        An instance of `BooleanNode`.

    - #### newBooleanNode

          public static BooleanNode newBooleanNode(boolean value)

      Convenience method to construct an `BooleanNode` value.
      Parameters:
        `value` - a boolean value
      Returns:
        An instance of `BooleanNode`.

    - #### newXSString

          public static XSString newXSString(java.lang.String value)

      A convenience method to construct an `XSString` value.
      Parameters:
        `value` - A String to construct the `XSString` object with.
      Returns:
        An instance of `XSString`.

    - #### newXSInteger

          public static XSInteger newXSInteger(long value)

      A convenience method to construct an `XSInteger` value. Note that an XQuery xs:integer can hold values larger than a Java int or long.
      Parameters:
        `value` - A long to construct the `XSInteger` object with.
      Returns:
        An instance of `XSInteger`.

    - #### newXSInteger

          public static XSInteger newXSInteger(java.math.BigInteger value)

      A convenience method to construct an `XSInteger` value. Note that an XQuery xs:integer can hold values larger than a Java int or long, but these large value may be represented with a `BigInteger` object.
      Parameters:
        `value` - A `BigInteger` to construct the `XSInteger` object with.
      Returns:
        An instance of `XSInteger`.

    - #### newXSBoolean

          public static XSBoolean newXSBoolean(boolean value)

      A convenience method to construct an `XSBoolean` value.
      Parameters:
        `value` - A boolean to construct the `XSBoolean` object with.
      Returns:
        An instance of `XSBoolean`.

    - #### newCtsBox

          public static CtsBox newCtsBox(java.lang.String south,
                                         java.lang.String west,
                                         java.lang.String north,
                                         java.lang.String east)

      Convenience method to construct a `CtsBox` value.
      Parameters:
        `south` - The southern boundary of the box.
        `west` - The western boundary of the box.
        `north` - The northern boundary of the box.
        `east` - The eastern boundary of the box.
      Returns:
        An instance of `CtsBox`.

    - #### newCtsCircle

          public static CtsCircle newCtsCircle(java.lang.String radius,
                                               CtsPoint center)

      Convenience method to construct a `CtsCircle` value.
      Parameters:
        `radius` - The radius of the circle.
        `center` - A point representing the center of the circle.
      Returns:
        An instance of `CtsCircle`.

    - #### newCtsPoint

          public static CtsPoint newCtsPoint(java.lang.String latitude,
                                             java.lang.String longitude)

      Convenience method to construct a `CtsPoint` value.
      Parameters:
        `latitude` - The latitude of the point.
        `longitude` - The longitude of the point.
      Returns:
        An instance of `CtsPoint`.

    - #### newCtsPolygon

          public static CtsPolygon newCtsPolygon(java.util.List<CtsPoint> vertices)

      Convenience method to construct a `CtsPolygon` value.
      Parameters:
        `vertices` - The vertices of the polygon, given in order.
      Returns:
        An instance of `CtsPolygon`.

    - #### newVecVector

          public static VecVector newVecVector(float[] values)

      Convenience method to construct a `VecVector` value.
      Parameters:
        `values` - The float values of the vector
      Returns:
        An instance of `VecVector`

    - #### newXSDateTime

          public static XSDateTime newXSDateTime(java.lang.String value,
                                                 java.util.TimeZone timeZone,
                                                 java.util.Locale locale)

      A convenience method to construct an `XSDateTime` value.
      Parameters:
        `value` - A `String` representation of the date/time in standard XQuery form (ie 2006-04-23T11:32:46).
        `timeZone` - A `TimeZone` object to apply to value, null for default.
        `locale` - A `Locale` object to apply to the value, null for default.
      Returns:
        An instance of `XSDateTime`.

    - #### newXSDate

          public static XSDate newXSDate(java.lang.String value,
                                         java.util.TimeZone timeZone,
                                         java.util.Locale locale)

      A convenience method to construct an `XSDate` value.
      Parameters:
        `value` - A `String` representation of the date/time in standard XQuery form (ie 2006-04-23).
        `timeZone` - A `TimeZone` object to apply to value, null for default.
        `locale` - A `Locale` object to apply to the value, null for default.
      Returns:
        An instance of `XSDate`.

    - #### newXSTime

          public static XSTime newXSTime(java.lang.String value,
                                         java.util.TimeZone timeZone,
                                         java.util.Locale locale)

      A convenience method to construct an `XSTime` value.
      Parameters:
        `value` - A `String` representation of the date/time in standard XQuery form (ie 11:32:46).
        `timeZone` - A `TimeZone` object to apply to value, null for default.
        `locale` - A `Locale` object to apply to the value, null for default.
      Returns:
        An instance of `XSDate`.

    - #### newXSDuration

          public static XSDuration newXSDuration(java.lang.String value)

      A convenience method to construct an `XSDuration` value.
      Parameters:
        `value` - A `String` representation of the duration (ie P2Y3M141DT12H46M12.34S).
      Returns:
        An instance of `XSDuration`.

    - #### newXSDuration

          public static XSDuration newXSDuration(XdmDuration duration)

      A convenience method to construct an `XSDuration` value from an `XdmDuration` object.
      Parameters:
        `duration` - An instance XdmDuration
      Returns:
        An instance of `XSDuration`.

    - #### newDuration

          public static XdmDuration newDuration(java.lang.String serializedString)

      Convenience method to construct an `XdmDuration` value.
      Parameters:
        `serializedString` - A `String` representation of the duration (ie P2Y3M141DT12H46M12.34S).
      Returns:
        An instance of `XdmDuration`.

    - #### newJSObject

          public static JSObject newJSObject(java.lang.String serializedString)

      Convenience method to construct an `JSObject` value.
      Parameters:
        `serializedString` - A `String` representation of the JavaScript Object (ie {a:1}).
      Returns:
        An instance of `JSObject`.

    - #### newJSObject

          public static JSObject newJSObject(com.fasterxml.jackson.databind.node.ObjectNode value)

      Convenience method to construct an `JSObject` value from a Jackson ObjectNode.
      Parameters:
        `value` - A `ObjectNode` representation of the JavaScript Object.
      Returns:
        An instance of `JSObject`.

    - #### newJSArray

          public static JSArray newJSArray(java.lang.String serializedString)

      Convenience method to construct an `JSArray` value.
      Parameters:
        `serializedString` - A `String` representation of the JavaScript Array (ie [a,b]).
      Returns:
        An instance of `JSObject`.

    - #### newJSArray

          public static JSArray newJSArray(com.fasterxml.jackson.databind.node.ArrayNode value)

      Convenience method to construct an `JSArray` value from a Jackson ArrayNode.
      Parameters:
        `value` - A `com.fasterxml.jackson.databind.node.ArraytNode` representation of the JavaScript Object.
      Returns:
        An instance of `JSObject`.

    - #### newJSNull

          public static JSNull newJSNull()

      Convenience method to construct an `JSNull` value.
      Returns:
        An instance of `JSNull`.

    - #### newSequence

          public static XdmSequence<XdmItem> newSequence(XdmValue[] values)

      Factory method to construct an `XdmSequence` from an array of `XdmValue` objects. Note XdmSequence is not a supported type for external variables.
      Parameters:
        `values` - An array of `XdmValue` instances.
      Returns:
        A new `XdmSequence` object.

    - #### newVariable

          public static XdmVariable newVariable(XName name,
                                                XdmValue value)

      Factory method to create a variable (named value) from the given `XName` and `XdmValue` objects.
      Parameters:
        `name` - An `XName` that defines the name and (optional) namespace of the `XdmVariable`.
        `value` - An instance of `XdmValue` which is the value of the variable.
      Returns:
        An instance of `XdmVariable` that encapsulates the name and value parameters.

    - #### newNullNode

          public static NullNode newNullNode(java.lang.Object value)

      Convenience method to construct an `NullNode` value. Object can be constructed from `String`, `NullNode`, or `InputStream`.
      Parameters:
        `value` - An instance of `String`, `NullNode` or `InputStream`.
      Returns:
        An instance of `NullNode`.

    - #### newNumberNode

          public static NumberNode newNumberNode(java.lang.Object value)

      Convenience method to construct an `NumberNode` value. Object can be constructed from `String`, `NumericNode`, or `InputStream`.
      Parameters:
        `value` - An instance of `String`, `com.fasterxml.jackson.databind.node.NumberNode` or `InputStream`.
      Returns:
        An instance of `NumberNode`.

    - #### newNumberNode

          public static NumberNode newNumberNode(double value)

      Convenience method to construct an `NumberNode` value.
      Parameters:
        `value` - A value in double.
      Returns:
        An instance of `NumberNode`.

    - #### newObjectNode

          public static XdmNode newObjectNode(java.lang.Object value)

      Convenience method to construct an `ObjectNode` value. Object can be constructed from `String`, `ObjectNode`, or `InputStream`.
      Parameters:
        `value` - An instance of `String`, `ObjectNode` or `InputStream`.
      Returns:
        An instance of `ObjectNode`.

Copyright © 2025 MarkLogic Corporation. All Rights Reserved.

Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com