]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/src/org/argeo/jcr/DefaultRepositoryRegister.java
Remove DocBook from defaults CNDs
[lgpl/argeo-commons.git] / org.argeo.server.jcr / src / org / argeo / jcr / DefaultRepositoryRegister.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.Collections;
19 import java.util.Map;
20 import java.util.Observable;
21 import java.util.TreeMap;
22
23 import javax.jcr.Repository;
24 import javax.jcr.RepositoryException;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 @Deprecated
30 public class DefaultRepositoryRegister extends Observable implements
31 RepositoryRegister, ArgeoJcrConstants {
32 private final static Log log = LogFactory
33 .getLog(DefaultRepositoryRegister.class);
34
35 /** Read only map which will be directly exposed. */
36 private Map<String, Repository> repositories = Collections
37 .unmodifiableMap(new TreeMap<String, Repository>());
38
39 @SuppressWarnings("rawtypes")
40 public synchronized Repository getRepository(Map parameters)
41 throws RepositoryException {
42 if (!parameters.containsKey(JCR_REPOSITORY_ALIAS))
43 throw new RepositoryException("Parameter " + JCR_REPOSITORY_ALIAS
44 + " has to be defined.");
45 String alias = parameters.get(JCR_REPOSITORY_ALIAS).toString();
46 if (!repositories.containsKey(alias))
47 throw new RepositoryException(
48 "No repository registered with alias " + alias);
49
50 return repositories.get(alias);
51 }
52
53 /** Access to the read-only map */
54 public synchronized Map<String, Repository> getRepositories() {
55 return repositories;
56 }
57
58 /** Registers a service, typically called when OSGi services are bound. */
59 @SuppressWarnings("rawtypes")
60 public synchronized void register(Repository repository, Map properties) {
61 String alias;
62 if (properties == null || !properties.containsKey(JCR_REPOSITORY_ALIAS)) {
63 log.warn("Cannot register a repository if no "
64 + JCR_REPOSITORY_ALIAS + " property is specified.");
65 return;
66 }
67 alias = properties.get(JCR_REPOSITORY_ALIAS).toString();
68 Map<String, Repository> map = new TreeMap<String, Repository>(
69 repositories);
70 map.put(alias, repository);
71 repositories = Collections.unmodifiableMap(map);
72 setChanged();
73 notifyObservers(alias);
74 }
75
76 /** Unregisters a service, typically called when OSGi services are unbound. */
77 @SuppressWarnings("rawtypes")
78 public synchronized void unregister(Repository repository, Map properties) {
79 // TODO: also check bean name?
80 if (properties == null || !properties.containsKey(JCR_REPOSITORY_ALIAS)) {
81 log.warn("Cannot unregister a repository without property "
82 + JCR_REPOSITORY_ALIAS);
83 return;
84 }
85
86 String alias = properties.get(JCR_REPOSITORY_ALIAS).toString();
87 Map<String, Repository> map = new TreeMap<String, Repository>(
88 repositories);
89 if (map.remove(alias) == null) {
90 log.warn("No repository was registered with alias " + alias);
91 return;
92 }
93 repositories = Collections.unmodifiableMap(map);
94 setChanged();
95 notifyObservers(alias);
96 }
97 }