com.marklogic.xcc.jndi

## Class ContentSourceBean

- java.lang.Object
- - com.marklogic.xcc.jndi.ContentSourceBean

- All Implemented Interfaces:
    ContentSource

      public class ContentSourceBean
      extends java.lang.Object
      implements ContentSource

  This is a Java Bean compatible implementation of `ContentSource` intended for use in a JNDI context or container where configuration must be done via setter methods.

  Use of this class to directly instantiate a `ContentSource` is discouraged. If you wish to programmatically create an instance use the primary factory class `ContentSourceFactory` instead.

  This class depends on a container-provided `ObjectFactory` implementation. If you have the option of configuring a custom bean factory, you are encouraged to use `ContentSourceBeanFactory` instead.

  An example of configuring Tomcat to use this bean would look like this:

       <Context path="/">
          <Resource name="marklogic/ContentSource" auth="Container"
              type="com.marklogic.xcc.jndi.ContentSourceBean"
              factory="org.apache.naming.factory.BeanFactory"
               host="somehost.mycorp.com" port="8003" user="fred" password="hush"
               contentbase="productiondb"/>
       <Context>

  See `ContentSourceBeanFactory` for more details and an example of looking up a `ContentSource` with JNDI. The lookup code will be identical for both configuration approaches.

  See Also:
    `ContentSourceBeanFactory`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContentSourceBean()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ConnectionProvider` | `getConnectionProvider()`
    `java.util.logging.Logger` | `getDefaultLogger()` Returns the current Logger to which log messages will be sent.
    `UserCredentials` | `getUserCredentials()`
    `boolean` | `isAuthenticationPreemptive()`
    `Session` | `newSession()` Attempts to establish a `Session` with the default contentbase for this ContentSource.
    `Session` | `newSession(java.lang.String databaseId)` Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource.
    `Session` | `newSession(java.lang.String userName, char[] password)` Attempts to establish a `Session` with the default contentbase for this ContentSource using the provided login credentials.
    `Session` | `newSession(java.lang.String userName, char[] password, java.lang.String contentbaseId)` Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource, using the provided user credentials.
    `Session` | `newSession(java.lang.String userName, java.lang.String password)` Attempts to establish a `Session` with the default contentbase for this ContentSource using the provided login credentials.
    `Session` | `newSession(java.lang.String userName, java.lang.String password, java.lang.String databaseId)` Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource, using the provided user credentials.
    `void` | `setAuthenticationPreemptive(boolean value)` Sets whether basic authentication should be attempted preemptively, default is false.
    `void` | `setContentBase(java.lang.String contentBase)`
    `void` | `setDefaultLogger(java.util.logging.Logger logger)` Set the default java.util.Logger instance which will be inherited by new `Session` instances.
    `void` | `setHost(java.lang.String host)`
    `void` | `setPassword(java.lang.String password)`
    `void` | `setPort(int port)`
    `void` | `setUrl(java.lang.String url)`
    `void` | `setUser(java.lang.String user)`
    `java.lang.String` | `toString()`

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

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

- - ### Constructor Detail

    - #### ContentSourceBean

          public ContentSourceBean()

  - ### Method Detail

    - #### newSession

          public Session newSession()

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the default contentbase for this ContentSource. Login credentials are the defaults established when the instance was created or bound to the JNDI service.
      Specified by:
        `newSession` in interface `ContentSource`
      Returns:
        A `Session` instance.

    - #### newSession

          public Session newSession(java.lang.String databaseId)

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource.
      Specified by:
        `newSession` in interface `ContentSource`
      Parameters:
        `databaseId` - A contentbase name or numeric ID.
      Returns:
        A `Session` instance.

    - #### newSession

          public Session newSession(java.lang.String userName,
                                    java.lang.String password)

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the default contentbase for this ContentSource using the provided login credentials.
      Specified by:
        `newSession` in interface `ContentSource`
      Parameters:
        `userName` - The user name to connect as.
        `password` - The password associated with the user name.
      Returns:
        A `Session` instance.

    - #### newSession

          public Session newSession(java.lang.String userName,
                                    java.lang.String password,
                                    java.lang.String databaseId)

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource, using the provided user credentials.
      Specified by:
        `newSession` in interface `ContentSource`
      Parameters:
        `userName` - The user name to connect as.
        `password` - The password associated with the user name.
        `databaseId` - A contentbase name or numeric ID.
      Returns:
        A `Session` instance.

    - #### getDefaultLogger

          public java.util.logging.Logger getDefaultLogger()

      Description copied from interface: `ContentSource`

      Returns the current Logger to which log messages will be sent. If not overridden with `ContentSource.setDefaultLogger(Logger)`, an implementation default logger is returned. This Logger will be inherited by `Session` instances created from this ContentSource. The `Logger` for individual `Session`s can be overridden with the `Session.setLogger(java.util.logging.Logger)` method.

      The name of the implementation default logger is `com.marklogic.xcc`. This is the name which should be used in a logging properties file (see `LogManager`) to customize the logger.

      XCC includes a bundled properties file that augments the default JVM logging properties. This file, xcc.logging.properties, is read from the classpath when the first ContentSource instance is created. The properties file in xcc.jar looks like this. If you wish to customize these logging properties, place a copy of this file in your classpath ahead of xcc.jar.

      Default logging properties file in xcc.jar.

      Specified by:
        `getDefaultLogger` in interface `ContentSource`
      Returns:
        The currently set Logger instance, or a default created by the implementation.

    - #### setDefaultLogger

          public void setDefaultLogger(java.util.logging.Logger logger)

      Description copied from interface: `ContentSource`

      Set the default java.util.Logger instance which will be inherited by new `Session` instances.

      Specified by:
        `setDefaultLogger` in interface `ContentSource`
      Parameters:
        `logger` - An instance of java.util.logging.Logger

    - #### getConnectionProvider

          public ConnectionProvider getConnectionProvider()

      Specified by:
        `getConnectionProvider` in interface `ContentSource`
      Returns:
        The ConnectionProvider used to construct this ContentSource.

    - #### getUserCredentials

          public UserCredentials getUserCredentials()

      Specified by:
        `getUserCredentials` in interface `ContentSource`
      Returns:
        The UserCredentials used to construct this ContentSource.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### setHost

          public void setHost(java.lang.String host)

    - #### setPort

          public void setPort(int port)

    - #### setUser

          public void setUser(java.lang.String user)

    - #### setPassword

          public void setPassword(java.lang.String password)

    - #### setContentBase

          public void setContentBase(java.lang.String contentBase)

    - #### setUrl

          public void setUrl(java.lang.String url)
                      throws java.net.URISyntaxException

      Throws:
        `java.net.URISyntaxException`

    - #### isAuthenticationPreemptive

          public boolean isAuthenticationPreemptive()

      Specified by:
        `isAuthenticationPreemptive` in interface `ContentSource`
      Returns:
        true if basic authentication will be attempted preemptively, false otherwise.

    - #### setAuthenticationPreemptive

          public void setAuthenticationPreemptive(boolean value)

      Description copied from interface: `ContentSource`

      Sets whether basic authentication should be attempted preemptively, default is false.

      Preemptive authentication can reduce the overhead of making connections to servers that accept basic authentication by eliminating the challenge-response interaction otherwise required.

      Note that misuse of preemptive authentication entails potential security risks, and under most circumstances the credentials used to authenticate will be cached after the first connection. To avoid creating the illusion that credentials are protected, connections to a server requiring digest authentication will not be retried if this flag is set.

      Specified by:
        `setAuthenticationPreemptive` in interface `ContentSource`
      Parameters:
        `value` - true if basic authentication should be attempted preemptively, false otherwise.

    - #### newSession

          public Session newSession(java.lang.String userName,
                                    char[] password)

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the default contentbase for this ContentSource using the provided login credentials.
      Specified by:
        `newSession` in interface `ContentSource`
      Parameters:
        `userName` - The user name to connect as.
        `password` - The password associated with the user name.
      Returns:
        A `Session` instance.

    - #### newSession

          public Session newSession(java.lang.String userName,
                                    char[] password,
                                    java.lang.String contentbaseId)

      Description copied from interface: `ContentSource`
      Attempts to establish a `Session` with the specified contentbase on the server represented by this ContentSource, using the provided user credentials.
      Specified by:
        `newSession` in interface `ContentSource`
      Parameters:
        `userName` - The user name to connect as.
        `password` - The password associated with the user name.
        `contentbaseId` - A contentbase name or numeric ID.
      Returns:
        A `Session` instance.

Copyright © 2025 MarkLogic Corporation

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