2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.jcr
;
18 import java
.util
.HashMap
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.RepositoryFactory
;
25 /** Utilities related to Argeo model in JCR */
26 public class ArgeoJcrUtils
implements ArgeoJcrConstants
{
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.
32 public static Repository
getRepositoryByAlias(
33 RepositoryFactory repositoryFactory
, String alias
) {
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 "
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.
50 public static Repository
getRepositoryByUri(
51 RepositoryFactory repositoryFactory
, String uri
) {
52 return getRepositoryByUri(repositoryFactory
, uri
, null);
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.
60 public static Repository
getRepositoryByUri(
61 RepositoryFactory repositoryFactory
, String uri
, String alias
) {
63 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
64 parameters
.put(JCR_REPOSITORY_URI
, uri
);
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 "
75 private ArgeoJcrUtils() {