Class JndiRepositoryFactory

  extended by org.modeshape.jcr.JndiRepositoryFactory
All Implemented Interfaces:

public class JndiRepositoryFactory
extends Object
implements ObjectFactory

The JndiRepositoryFactory class provides a means of initializing and accessing repositories in a JNDI tree.

Example JNDI Configurations

Tomcat 5.5

The following configuration can be added to added to server.xml in Tomcat 5.5 to initialize a JcrRepository and add it to the JNDI tree.

         <!-- Other configuration omitted -->
      <Resource name="jcr/local" auth="Container"
           repositoryName="Test Repository Source"
This will create a repository loaded from the or file "/tck/default/configRepository.xml" and return the JCR repository named "Test Repository Source". The name of the repository is important as a single configuration file may contain configuration information for many JCR repositories.

Note that if the "repositoryName" property is not specified or is empty, the factory will register the ModeShape engine at the supplied location in JNDI. This approach is compatible with the traditional JNDI URLs used with the JCR 2.0-style RepositoryFactory.

Field Summary
protected static Logger log
Constructor Summary
Method Summary
 Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
          Creates an JcrRepository or ModeShape engine using the reference information specified.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected static final Logger log
Constructor Detail


public JndiRepositoryFactory()
Method Detail


public Object getObjectInstance(Object obj,
                                Name name,
                                Context nameCtx,
                                Hashtable<?,?> environment)
                         throws IOException,
Creates an JcrRepository or ModeShape engine using the reference information specified.

This method first attempts to convert the obj parameter into a reference to JNDI configuration information. If that is successful, a JcrEngine will be created (if not previously created by a call to this method) and it will be configured from the resource or file at the location specified by the configFile key in the reference. After the configuration is successful, the JcrEngine will be queried for the repository with the name specified by the value of the @{code repositoryName} key in the reference.

Specified by:
getObjectInstance in interface ObjectFactory
obj - the reference to the JNDI configuration information; must be a non-null instance of Reference
name - the name of the object
nameCtx - used to register the ModeShape engine when no repository name is provided in the Reference obj
environment - ignored
the object registered in JDNI, which will be the named repository name or (if no repository name is given) the ModeShape engine; never null
IOException - if there is an error or problem reading the configuration resource at the supplied path
SAXException - if the contents of the configuration resource are not valid XML
NamingException - if there is an error registering the namespace listener
RepositoryException - if the JcrEngine could not be started, the named repository does not exist in the given configuration resource, or the named repository could not be created

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.