@ThreadSafe public class JcrRepositoryFactory extends Object implements RepositoryFactory
RepositoryFactory
interface. This class provides a single public method,
getRepository(Map)
, that allows for a runtime link to a ModeShape JCR repository.
The canonical way to get a reference to this class is to use the ServiceLoader
:
String configUrl = ... ; // URL that points to your configuration file Map parameters = Collections.singletonMap(JcrRepositoryFactory.URL, configUrl); Repository repository; for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) { repository = factory.getRepository(parameters); if (repository != null) break; }It is also possible to instantiate this class directly.
RepositoryFactory repoFactory = new JcrRepositoryFactory(); String url = ... ; // URL that points to your configuration file Map params = Collections.singletonMap(JcrRepositoryFactory.URL, url); Repository repository = repoFactory.getRepository(params);]]>
Several URL formats are supported:
javax.jcr.Repository
instance. For example, "jndi:jcr/local/my_repository
" is a URL that identifies
the JCR repository located in JNDI at the name "jcr/local/my_repository". Note that the use of such URLs requires that the
repository already be registered in JNDI at that location.engine
instance and the name of the javax.jcr.Repository
repository as a URL query parameter. For example, "jndi:jcr/local?repositoryName=my_repository
" identifies a
ModeShape engine registered in JNDI at "jcr/local", and looks in that engine for a JCR repository named "
my_repository
".classpath:
, "file:
", http:
and
any other URL scheme that can be resolved and opened
. For example, "
file://path/to/myRepoConfig.json
" identifies the file on the file system at the absolute path "
/path/to/myRepoConfig.json
"; "classpath://path/to/myRepoConfig.json
" identifies the file at "
/path/to/myRepoConfig.json
" on the classpath, and "http://www.example.com/path/to/myRepoConfig.json
" identifies the file "myRepoConfig.json
" at the given URL.REPOSITORY_NAME, URL
Constructor and Description |
---|
JcrRepositoryFactory() |
Modifier and Type | Method and Description |
---|---|
Repository |
getRepository(Map parameters)
Returns a reference to the appropriate repository for the given parameter map, if one exists.
|
protected boolean |
shutdown(long timeout,
TimeUnit unit) |
public Repository getRepository(Map parameters) throws RepositoryException
parameters
map can have any number of entries, this method only considers the entry with the key
JcrRepositoryFactory#URL.
The value of this key is treated as a URL with the format PROTOCOL://PATH[?repositoryName=REPOSITORY_NAME]
where
PROTOCOL is "jndi" or "file", PATH is the JNDI name of the ModeShapeEngine
or the path to the configuration file,
and REPOSITORY_NAME is the name of the repository to return if there is more than one JCR repository in the given
ModeShapeEngine
or configuration file.
getRepository
in interface RepositoryFactory
parameters
- a map of parameters to use to look up the repository; may be nullRepositoryFactory.URL
, or null if any of the following are true:
RepositoryFactory.URL
; or,RepositoryFactory.URL
key is null or cannot be parsed into a ModeShape JCR URL; or,ModeShapeEngine
(in the JNDI tree) or a
configuration file (in the classpath or file system); or,ModeShapeEngine
with the given configuration information.RepositoryException
RepositoryFactory.getRepository(Map)
protected boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.