com.marklogic.xcc.jndi

## Class ContentSourceBeanFactory

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

- All Implemented Interfaces:
    javax.naming.spi.ObjectFactory

      public class ContentSourceBeanFactory
      extends java.lang.Object
      implements javax.naming.spi.ObjectFactory

  This class implements the JNDI `ObjectFactory` interface and may be used in a J2EE container as a source of `ContentSource` instances. This class is preferred over `ContentSourceBean` if you have the option because it does a little more consistency checking when creating new objects. Neither does it depend on a container-provided bean factory.

  JNDI resources are typically specified as part of the container configuration. The specifics of configuration vary by container. Below is an example of using this class with Apache Tomcat version 5.5 to configure a `ContentSource`. Further details of JNDI configuration in Tomcat are available on the JNDI-HowTo page.

  There are two places where JNDI resources can be configured in the Tomcat 5.5 container. One is globally in Tomcat's config file in $CATALINA_HOME/conf/server.xml, the other is within an individual webapp in META-INF/context.xml. In either file, an XML element like this should be placed as a child of the <Context> element, like this:

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

  An alternate means of specifying the content source is via the "url" attribute, like this:

       <Context path="/">
          <Resource name="marklogic/ContentSource" auth="Container"
               type="com.marklogic.xcc.ContentSource"
               factory="com.marklogic.xcc.jndi.ContentSourceBeanFactory"
               url="xcc://fred:hush@somehost.mycorp.com:8003/productiondb"/>
       <Context>

  The value of the "name" attribute is the JNDI lookup key that you will use in your code (servlet, JSP scriptlet, etc) to locate the `ContentSource`. A typical method to do the lookup would look something like this:

       private ContentSource findContentSource() throws ServletException {
           try {
               Context initCtx = new InitialContext();
               Context envCtx = (Context)initCtx.lookup("java:comp/env");

               return (ContentSource)envCtx.lookup("marklogic/ContentSource");
           } catch (NamingException e) {
               throw new ServletException("ContentSource lookup failed: " + e, e);
           }
       }

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContentSourceBeanFactory()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable<?,?> environment)`

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

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

- - ### Constructor Detail

    - #### ContentSourceBeanFactory

          public ContentSourceBeanFactory()

  - ### Method Detail

    - #### getObjectInstance

          public java.lang.Object getObjectInstance(java.lang.Object obj,
                                                    javax.naming.Name name,
                                                    javax.naming.Context nameCtx,
                                                    java.util.Hashtable<?,?> environment)
                                             throws java.lang.Exception

      Specified by:
        `getObjectInstance` in interface `javax.naming.spi.ObjectFactory`
      Throws:
        `java.lang.Exception`

Copyright © 2025 MarkLogic Corporation

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