]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ArgeoJcrUtils.java
ed4ba421f53ac03c420ad6c7b6a3c9e2ac1d8485
[lgpl/argeo-commons.git] / ArgeoJcrUtils.java
1 package org.argeo.jcr;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.jcr.Repository;
7 import javax.jcr.RepositoryException;
8 import javax.jcr.RepositoryFactory;
9
10 import org.argeo.ArgeoException;
11
12 /** Utilities related to Argeo model in JCR */
13 public class ArgeoJcrUtils implements ArgeoJcrConstants {
14 /**
15 * Wraps the call to the repository factory based on parameter
16 * {@link ArgeoJcrConstants#JCR_REPOSITORY_ALIAS} in order to simplify it
17 * and protect against future API changes.
18 */
19 public static Repository getRepositoryByAlias(
20 RepositoryFactory repositoryFactory, String alias) {
21 try {
22 Map<String, String> parameters = new HashMap<String, String>();
23 parameters.put(JCR_REPOSITORY_ALIAS, alias);
24 return repositoryFactory.getRepository(parameters);
25 } catch (RepositoryException e) {
26 throw new ArgeoException(
27 "Unexpected exception when trying to retrieve repository with alias "
28 + alias, e);
29 }
30 }
31
32 /**
33 * Wraps the call to the repository factory based on parameter
34 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
35 * protect against future API changes.
36 */
37 public static Repository getRepositoryByUri(
38 RepositoryFactory repositoryFactory, String uri) {
39 try {
40 Map<String, String> parameters = new HashMap<String, String>();
41 parameters.put(JCR_REPOSITORY_URI, uri);
42 return repositoryFactory.getRepository(parameters);
43 } catch (RepositoryException e) {
44 throw new ArgeoException(
45 "Unexpected exception when trying to retrieve repository with uri "
46 + uri, e);
47 }
48 }
49
50 private ArgeoJcrUtils() {
51 }
52
53 }