|
ModeShape Distribution 3.0.0.Beta4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.jcr.api.JndiRepositoryFactory
public class JndiRepositoryFactory
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(JndiRepositoryFactory.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(JndiRepositoryFactory.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.api.JndiRepositoryFactory.URL, jndiUrl); parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.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 | |
---|---|
JndiRepositoryFactory()
|
Method Summary | |
---|---|
Repository |
getRepository(Map parameters)
|
protected String |
getRepositoryNameFrom(URL url,
Map<String,Object> parameters)
|
Set<String> |
getRepositoryNames(Map<String,Object> parameters)
Get the names of the available repositories given the supplied parameters (which must have a URL pointing to a Repositories object). |
protected URL |
getUrlFrom(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.api.JndiRepositoryFactory.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.api.JndiRepositoryFactory.URL, jndiUrl); parameters.put(org.modeshape.jcr.api.JndiRepositoryFactory.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 JndiRepositoryFactory()
Method Detail |
---|
public Repository getRepository(Map parameters) throws RepositoryException
getRepository
in interface RepositoryFactory
RepositoryException
protected URL getUrlFrom(Map<String,Object> parameters)
protected String getRepositoryNameFrom(URL url, Map<String,Object> parameters)
public Set<String> getRepositoryNames(Map<String,Object> parameters) throws RepositoryException
Repositories
object).
parameters
- map of string key/value pairs as repository arguments or null
if none are provided and a
client wishes to connect to a default repository.
parameters
.
RepositoryException
- if if no suitable repository is found or another error occurs.
RepositoryException
|
ModeShape Distribution 3.0.0.Beta4 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |