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 import org
.argeo
.ArgeoException
;
27 /** Utilities related to Argeo model in JCR */
28 public class ArgeoJcrUtils
implements ArgeoJcrConstants
{
30 * Wraps the call to the repository factory based on parameter
31 * {@link ArgeoJcrConstants#JCR_REPOSITORY_ALIAS} in order to simplify it
32 * and protect against future API changes.
34 public static Repository
getRepositoryByAlias(
35 RepositoryFactory repositoryFactory
, String alias
) {
37 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
38 parameters
.put(JCR_REPOSITORY_ALIAS
, alias
);
39 return repositoryFactory
.getRepository(parameters
);
40 } catch (RepositoryException e
) {
41 throw new ArgeoException(
42 "Unexpected exception when trying to retrieve repository with alias "
48 * Wraps the call to the repository factory based on parameter
49 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
50 * protect against future API changes.
52 public static Repository
getRepositoryByUri(
53 RepositoryFactory repositoryFactory
, String uri
) {
54 return getRepositoryByUri(repositoryFactory
, uri
, null);
58 * Wraps the call to the repository factory based on parameter
59 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
60 * protect against future API changes.
62 public static Repository
getRepositoryByUri(
63 RepositoryFactory repositoryFactory
, String uri
, String alias
) {
65 Map
<String
, String
> parameters
= new HashMap
<String
, String
>();
66 parameters
.put(JCR_REPOSITORY_URI
, uri
);
68 parameters
.put(JCR_REPOSITORY_ALIAS
, alias
);
69 return repositoryFactory
.getRepository(parameters
);
70 } catch (RepositoryException e
) {
71 throw new ArgeoException(
72 "Unexpected exception when trying to retrieve repository with uri "
77 private ArgeoJcrUtils() {