|
ModeShape Distribution 3.1.2.Final | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.modeshape.jcr.JndiJcrRepositoryFactory
public class JndiJcrRepositoryFactory
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;
}
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 |
|---|
public static final String URL
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;
}
public static final String REPOSITORY_NAME
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;
}
public static final String REPOSITORY_NAME_PARAM
| Constructor Detail |
|---|
public JndiJcrRepositoryFactory()
| Method Detail |
|---|
public Repository getRepository(Map parameters)
throws RepositoryException
getRepository in interface RepositoryFactoryRepositoryException
protected String getRepositoryNameFrom(URL url,
Map<String,Object> parameters)
|
ModeShape Distribution 3.1.2.Final | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||