com.marklogic.xcc.examples

## Class ModuleRunner

- java.lang.Object
- - com.marklogic.xcc.examples.ModuleRunner

-     public class ModuleRunner
      extends java.lang.Object

  This is a very simple class that will invoke a named XQuery module on the server and return the result.

  Click here for the source code for this class

  The main() method looks for two command-line args, a URL for the server ( `ContentSourceFactory.newContentSource(java.net.URI)`) and theURI of a module to invoke. This URI should be relative to the "Library" path set in the XDBC server configuration for the content server you're connecting to (arg #1). This program invokes the named module and then prints the result sequence to stdout, one item per line.

  The class has methods that could be used to set request options and to obtain the results as an array of Strings or as a real `ResultSequence`.

  If you want to set external variables for a request, you can call `getRequest()` to obtain a reference to the internal `Request` object and set the variable values on it before calling `invoke(String)`.

  ToDo: Accept variable names and values on the command line.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ModuleRunner(java.net.URI serverUri)` Construct an instance that will invoke modules on the server represented by the given URI.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Request` | `getRequest()` Returns the `Request` object used internally to submit requests.
    `ResultSequence` | `invoke(java.lang.String moduleUri)` Invoke the module with the given URI and return the resulting `ResultSequence`.
    `java.lang.String` | `invokeToSingleString(java.lang.String moduleUri, java.lang.String separator)`
    `java.lang.String[]` | `invokeToStringArray(java.lang.String moduleUri)`
    `static void` | `main(java.lang.String[] args)`
    `void` | `setRequestOptions(RequestOptions options)` Set (or clear) the `RequestOptions` instance to associate with submitted queries.

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

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

- - ### Constructor Detail

    - #### ModuleRunner

          public ModuleRunner(java.net.URI serverUri)
                       throws XccConfigException

      Construct an instance that will invoke modules on the server represented by the given URI. Note that the URI will not be validated at this time.
      Parameters:
        `serverUri` - A URI that specifies a server per ( `ContentSourceFactory.newContentSource(java.net.URI)`).
      Throws:
        `XccConfigException` - If the URI is not a valid XCC server URL.

  - ### Method Detail

    - #### invoke

          public ResultSequence invoke(java.lang.String moduleUri)
                                throws RequestException

      Invoke the module with the given URI and return the resulting `ResultSequence`.
      Parameters:
        `moduleUri` -
      Returns:
        An instance `ResultSequence`, possibly with size zero.
      Throws:
        `RequestException` - If an unrecoverable error occurs when submitting or evaluating the request.

    - #### invokeToStringArray

          public java.lang.String[] invokeToStringArray(java.lang.String moduleUri)
                                                 throws RequestException

      Throws:
        `RequestException`

    - #### invokeToSingleString

          public java.lang.String invokeToSingleString(java.lang.String moduleUri,
                                                       java.lang.String separator)
                                                throws RequestException

      Throws:
        `RequestException`

    - #### getRequest

          public Request getRequest()

      Returns the `Request` object used internally to submit requests. This object can be used to set external variables that will be bound to the query when submitted. You should not set your own `RequestOptions` object, use `setRequestOptions(com.marklogic.xcc.RequestOptions)` instead.
      Returns:
        An instance of `Request`.

    - #### setRequestOptions

          public void setRequestOptions(RequestOptions options)

      Set (or clear) the `RequestOptions` instance to associate with submitted queries.
      Parameters:
        `options` - An instance of `RequestOptions` or null.

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

Copyright © 2025 MarkLogic Corporation. All Rights Reserved.

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