ModeShape Distribution 3.0.0.Final

org.modeshape.jcr
Class JndiJcrRepositoryFactory

java.lang.Object
  extended by org.modeshape.jcr.JndiJcrRepositoryFactory
All Implemented Interfaces:
RepositoryFactory

public class JndiJcrRepositoryFactory
extends Object
implements RepositoryFactory

Service provider for the JCR2 RepositoryFactory interface. This class provides a single public method, getRepository(Map), that enables finding a JCR repository that is registered in JNDI.

The canonical way to get a reference to this class is to use the ServiceLoader. For example, when the Repository instance is registered in JNDI, the following code will find it via the ServiceLoader:

 String jndiUrl = "jndi:jcr/local/myRepository";
 Map parameters = Collections.singletonMap(JndiJcrRepositoryFactory.URL, configUrl);
 Repository repository;

 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
     repository = factory.getRepository(parameters);
     if (repository != null) break;
 }
 
Or, if the ModeShape engine is registered in JNDI at "jcr/local", the same technique can be used with a slightly modified URL parameter:
 String jndiUrl = "jndi:jcr/local?repositoryName=myRepository"; // Different URL
 Map parameters = Collections.singletonMap(JndiJcrRepositoryFactory.URL, configUrl);
 Repository repository;

 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
     repository = factory.getRepository(parameters);
     if (repository != null) break;
 }
 
Alternatively, the repository name can be provided completely separately from the JNDI URL (again, if the ModeShape engine is registered in JNDI at "jcr/local"):
 String jndiUrl = "jndi:jcr/local";
 String repoName = "myRepository";

 Map<String, String> parameters = new HashMap<String, String>();
 parameters.put(org.modeshape.jcr.JndiJcrRepositoryFactory.URL, jndiUrl);
 parameters.put(org.modeshape.jcr.JndiJcrRepositoryFactory.REPOSITORY_NAME, repoName);

 Repository repository = null;
 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
     repository = factory.getRepository(parameters);
     if (repository != null) break;
 }
 

See Also:
getRepository(Map), RepositoryFactory.getRepository(Map)

Field Summary
static String REPOSITORY_NAME
          The name of the key for the ModeShape JCR repository name in the parameter map.
static String REPOSITORY_NAME_PARAM
          The name of the URL parameter that specifies the repository name.
static String URL
          The name of the key for the ModeShape JCR URL in the parameter map.
 
Constructor Summary
JndiJcrRepositoryFactory()
           
 
Method Summary
 Repository getRepository(Map parameters)
           
protected  String getRepositoryNameFrom(URL url, Map<String,Object> parameters)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL

public static final String URL
The name of the key for the ModeShape JCR URL in the parameter map.

For example, define a URL that points to the configuration file for your repository:

 String jndiUrl = "jndi:jcr/local/myRepository";

 Map<String, String> parameters = new HashMap<String, String>();
 parameters.put(org.modeshape.jcr.JndiJcrRepositoryFactory.URL, configUrl);

 Repository repository = null;
 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
     repository = factory.getRepository(parameters);
     if (repository != null) break;
 }
 

See Also:
Constant Field Values

REPOSITORY_NAME

public static final String REPOSITORY_NAME
The name of the key for the ModeShape JCR repository name in the parameter map. This can be used as with a URL that contains the JNDI name of a Repositories implementation.

For example:

 String jndiUrl = "jndi:jcr/local";
 String repoName = "myRepository";

 Map<String, String> parameters = new HashMap<String, String>();
 parameters.put(org.modeshape.jcr.JndiJcrRepositoryFactory.URL, jndiUrl);
 parameters.put(org.modeshape.jcr.JndiJcrRepositoryFactory.REPOSITORY_NAME, repoName);

 Repository repository = null;
 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
     repository = factory.getRepository(parameters);
     if (repository != null) break;
 }
 

See Also:
Constant Field Values

REPOSITORY_NAME_PARAM

public static final String REPOSITORY_NAME_PARAM
The name of the URL parameter that specifies the repository name.

See Also:
Constant Field Values
Constructor Detail

JndiJcrRepositoryFactory

public JndiJcrRepositoryFactory()
Method Detail

getRepository

public Repository getRepository(Map parameters)
                         throws RepositoryException
Specified by:
getRepository in interface RepositoryFactory
Throws:
RepositoryException

getRepositoryNameFrom

protected String getRepositoryNameFrom(URL url,
                                       Map<String,Object> parameters)

ModeShape Distribution 3.0.0.Final

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