]> git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/ArgeoJcrUtils.java
Prepare next development cycle
[lgpl/argeo-commons.git] / jcr / ArgeoJcrUtils.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.jcr;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import javax.jcr.Repository;
22 import javax.jcr.RepositoryException;
23 import javax.jcr.RepositoryFactory;
24
25 /** Utilities related to Argeo model in JCR */
26 public class ArgeoJcrUtils implements ArgeoJcrConstants {
27 /**
28 * Wraps the call to the repository factory based on parameter
29 * {@link ArgeoJcrConstants#JCR_REPOSITORY_ALIAS} in order to simplify it
30 * and protect against future API changes.
31 */
32 public static Repository getRepositoryByAlias(
33 RepositoryFactory repositoryFactory, String alias) {
34 try {
35 Map<String, String> parameters = new HashMap<String, String>();
36 parameters.put(JCR_REPOSITORY_ALIAS, alias);
37 return repositoryFactory.getRepository(parameters);
38 } catch (RepositoryException e) {
39 throw new ArgeoJcrException(
40 "Unexpected exception when trying to retrieve repository with alias "
41 + alias, e);
42 }
43 }
44
45 /**
46 * Wraps the call to the repository factory based on parameter
47 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
48 * protect against future API changes.
49 */
50 public static Repository getRepositoryByUri(
51 RepositoryFactory repositoryFactory, String uri) {
52 return getRepositoryByUri(repositoryFactory, uri, null);
53 }
54
55 /**
56 * Wraps the call to the repository factory based on parameter
57 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
58 * protect against future API changes.
59 */
60 public static Repository getRepositoryByUri(
61 RepositoryFactory repositoryFactory, String uri, String alias) {
62 try {
63 Map<String, String> parameters = new HashMap<String, String>();
64 parameters.put(JCR_REPOSITORY_URI, uri);
65 if (alias != null)
66 parameters.put(JCR_REPOSITORY_ALIAS, alias);
67 return repositoryFactory.getRepository(parameters);
68 } catch (RepositoryException e) {
69 throw new ArgeoJcrException(
70 "Unexpected exception when trying to retrieve repository with uri "
71 + uri, e);
72 }
73 }
74
75 private ArgeoJcrUtils() {
76 }
77
78 }