Index: src/test/java/org/modeshape/jcr/JcrConfigurationTest.java =================================================================== --- src/test/java/org/modeshape/jcr/JcrConfigurationTest.java (revision 2494) +++ src/test/java/org/modeshape/jcr/JcrConfigurationTest.java (working copy) @@ -257,6 +257,7 @@ options.put(Option.QUERY_INDEX_DIRECTORY, DefaultOption.QUERY_INDEX_DIRECTORY); options.put(Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY, DefaultOption.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY); options.put(Option.PERFORM_REFERENTIAL_INTEGRITY_CHECKS, DefaultOption.PERFORM_REFERENTIAL_INTEGRITY_CHECKS); + options.put(Option.REPOSITORY_JNDI_LOCATION,DefaultOption.REPOSITORY_JNDI_LOCATION); assertThat(repository.getOptions(), is(options)); } Index: src/main/java/org/modeshape/jcr/JcrI18n.java =================================================================== --- src/main/java/org/modeshape/jcr/JcrI18n.java (revision 2494) +++ src/main/java/org/modeshape/jcr/JcrI18n.java (working copy) @@ -115,6 +115,7 @@ public static I18n cannotRemoveNodeFromClone; public static I18n cannotRemoveNodeFromCloneDueToChangesInSession; public static I18n constraintViolatedOnReference; + public static I18n unableToBindToJndi; public static I18n cannotRemoveRootNode; public static I18n cannotRemoveParentNodeOfTarget; Index: src/main/java/org/modeshape/jcr/JcrRepository.java =================================================================== --- src/main/java/org/modeshape/jcr/JcrRepository.java (revision 2494) +++ src/main/java/org/modeshape/jcr/JcrRepository.java (working copy) @@ -104,6 +104,8 @@ import org.modeshape.jcr.xpath.XPathQueryParser; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; +import javax.naming.InitialContext; +import javax.naming.NamingException; /** * Creates JCR {@link Session sessions} to an underlying repository (which may be a federated repository). @@ -268,9 +270,17 @@ * The default value is 'true', meaning that these checks are performed. *

*/ - PERFORM_REFERENTIAL_INTEGRITY_CHECKS; + PERFORM_REFERENTIAL_INTEGRITY_CHECKS, /** + * A String property that when specified tells the {@link JcrEngine} where to put the + * {@link Repository} in to JNDI. Assumes that you have write access + * to the JNDI tree. If no value set, then the {@link Repository} will not be bound to JNDI. + * + */ + REPOSITORY_JNDI_LOCATION; + + /** * Determine the option given the option name. This does more than {@link Option#valueOf(String)}, since this method first * tries to match the supplied string to the option's {@link Option#name() name}, then the uppercase version of the * supplied string to the option's name, and finally if the supplied string is a camel-case version of the name (e.g., @@ -353,6 +363,11 @@ */ public static final String PERFORM_REFERENTIAL_INTEGRITY_CHECKS = Boolean.TRUE.toString(); + /** + * The default value for the {@link Option#REPOSITORY_JNDI_LOCATION} option is {@value} + */ + public static final String REPOSITORY_JNDI_LOCATION = ""; + } /** @@ -411,6 +426,7 @@ defaults.put(Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY, DefaultOption.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY); defaults.put(Option.QUERY_INDEX_DIRECTORY, DefaultOption.QUERY_INDEX_DIRECTORY); defaults.put(Option.PERFORM_REFERENTIAL_INTEGRITY_CHECKS, DefaultOption.PERFORM_REFERENTIAL_INTEGRITY_CHECKS); + defaults.put(Option.REPOSITORY_JNDI_LOCATION,DefaultOption.REPOSITORY_JNDI_LOCATION); DEFAULT_OPTIONS = Collections.unmodifiableMap(defaults); } @@ -744,6 +760,19 @@ // This observer picks up notification of changes to the system graph in a cluster. It's a NOP if there is no cluster. repositoryObservationManager.register(new SystemChangeObserver(Arrays.asList(new JcrSystemObserver[] { repositoryLockManager, namespaceObserver, repositoryTypeManager}))); + + //If the JNDI Location is set and not trivial, attempt the bind. + String jndiLocation = this.options.get(Option.REPOSITORY_JNDI_LOCATION); + if(!jndiLocation.equals("")) { + try{ + InitialContext ic = new InitialContext(); + ic.rebind(jndiLocation,(javax.jcr.Repository)this); + } catch (NamingException e) { + I18n msg = JcrI18n.unableToBindToJndi; + LOGGER.error(msg, jndiLocation); + throw new RepositoryException(msg.text(jndiLocation),e); + } + } } protected void addWorkspace( String workspaceName, Index: src/main/resources/org/modeshape/jcr/JcrI18n.properties =================================================================== --- src/main/resources/org/modeshape/jcr/JcrI18n.properties (revision 2494) +++ src/main/resources/org/modeshape/jcr/JcrI18n.properties (working copy) @@ -105,6 +105,7 @@ cannotRemoveNodeFromClone = The node at "{0}" with UUID "{1}" exists in the current workspace but cannot be removed because it is a mandatory child node cannotRemoveNodeFromCloneDueToChangesInSession = The node at "{0}" with UUID "{1}" already exists in the current workspace and would be removed by the clone, but that node has been changed within this session and therefore cannot be removed constraintViolatedOnReference = The property "{0}" does not satisfy the constraints defined on the "{1}" property definition +unableToBindToJndi = Unable to bind repository to JNDI location {0} cannotRemoveRootNode = Unable to remove the root node cannotRemoveParentNodeOfTarget = The node at "{0}" with UUID "{1}" is a parent of the target node for this operation "{2}"