3 import java
.util
.Collections
;
4 import java
.util
.HashMap
;
6 import java
.util
.Observable
;
7 import java
.util
.SortedMap
;
8 import java
.util
.TreeMap
;
10 import javax
.jcr
.Repository
;
11 import javax
.jcr
.RepositoryException
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
16 public class DefaultRepositoryRegister
extends Observable
implements
18 private final static Log log
= LogFactory
19 .getLog(DefaultRepositoryRegister
.class);
21 /** Read only map which will be directly exposed. */
22 private Map
<String
, Repository
> repositories
= Collections
23 .unmodifiableMap(new TreeMap
<String
, Repository
>());
25 @SuppressWarnings("rawtypes")
26 public synchronized Repository
getRepository(Map parameters
)
27 throws RepositoryException
{
28 if (!parameters
.containsKey(JCR_REPOSITORY_NAME
))
29 throw new RepositoryException("Parameter " + JCR_REPOSITORY_NAME
30 + " has to be defined.");
31 String name
= parameters
.get(JCR_REPOSITORY_NAME
).toString();
32 if (!repositories
.containsKey(name
))
33 throw new RepositoryException("No repository registered with name "
36 return repositories
.get(name
);
39 /** Access to the read-only map */
40 public synchronized Map
<String
, Repository
> getRepositories() {
44 /** Registers a service, typically called when OSGi services are bound. */
45 @SuppressWarnings("rawtypes")
46 public synchronized void register(Repository repository
, Map properties
) {
47 // TODO: also check bean name?
48 if (properties
== null || !properties
.containsKey(JCR_REPOSITORY_NAME
)) {
49 log
.warn("Cannot register a repository without property "
50 + JCR_REPOSITORY_NAME
);
54 String name
= properties
.get(JCR_REPOSITORY_NAME
).toString();
55 Map
<String
, Repository
> map
= new TreeMap
<String
, Repository
>(
57 map
.put(name
, repository
);
58 repositories
= Collections
.unmodifiableMap(map
);
60 notifyObservers(repository
);
63 /** Unregisters a service, typically called when OSGi services are unbound. */
64 @SuppressWarnings("rawtypes")
65 public synchronized void unregister(Repository repository
, Map properties
) {
66 // TODO: also check bean name?
67 if (properties
== null || !properties
.containsKey(JCR_REPOSITORY_NAME
)) {
68 log
.warn("Cannot unregister a repository without property "
69 + JCR_REPOSITORY_NAME
);
73 String name
= properties
.get(JCR_REPOSITORY_NAME
).toString();
74 Map
<String
, Repository
> map
= new TreeMap
<String
, Repository
>(
76 map
.put(name
, repository
);
77 repositories
= Collections
.unmodifiableMap(map
);
79 notifyObservers(repository
);