3 import java
.util
.Collections
;
5 import java
.util
.Observable
;
6 import java
.util
.TreeMap
;
8 import javax
.jcr
.Repository
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
14 public class DefaultRepositoryRegister
extends Observable
implements
15 RepositoryRegister
, ArgeoJcrConstants
{
16 private final static Log log
= LogFactory
17 .getLog(DefaultRepositoryRegister
.class);
19 /** Read only map which will be directly exposed. */
20 private Map
<String
, Repository
> repositories
= Collections
21 .unmodifiableMap(new TreeMap
<String
, Repository
>());
23 @SuppressWarnings("rawtypes")
24 public synchronized Repository
getRepository(Map parameters
)
25 throws RepositoryException
{
26 if (!parameters
.containsKey(JCR_REPOSITORY_ALIAS
))
27 throw new RepositoryException("Parameter " + JCR_REPOSITORY_ALIAS
28 + " has to be defined.");
29 String alias
= parameters
.get(JCR_REPOSITORY_ALIAS
).toString();
30 if (!repositories
.containsKey(alias
))
31 throw new RepositoryException(
32 "No repository registered with alias " + alias
);
34 return repositories
.get(alias
);
37 /** Access to the read-only map */
38 public synchronized Map
<String
, Repository
> getRepositories() {
42 /** Registers a service, typically called when OSGi services are bound. */
43 @SuppressWarnings("rawtypes")
44 public synchronized void register(Repository repository
, Map properties
) {
45 // TODO: also check bean name?
47 if (properties
== null || !properties
.containsKey(JCR_REPOSITORY_ALIAS
)) {
48 log
.warn("Cannot register a repository if no "
49 + JCR_REPOSITORY_ALIAS
+ " property is speecified.");
52 alias
= properties
.get(JCR_REPOSITORY_ALIAS
).toString();
53 Map
<String
, Repository
> map
= new TreeMap
<String
, Repository
>(
55 map
.put(alias
, repository
);
56 repositories
= Collections
.unmodifiableMap(map
);
58 notifyObservers(alias
);
61 /** Unregisters a service, typically called when OSGi services are unbound. */
62 @SuppressWarnings("rawtypes")
63 public synchronized void unregister(Repository repository
, Map properties
) {
64 // TODO: also check bean name?
65 if (properties
== null || !properties
.containsKey(JCR_REPOSITORY_ALIAS
)) {
66 log
.warn("Cannot unregister a repository without property "
67 + JCR_REPOSITORY_ALIAS
);
71 String alias
= properties
.get(JCR_REPOSITORY_ALIAS
).toString();
72 Map
<String
, Repository
> map
= new TreeMap
<String
, Repository
>(
74 map
.put(alias
, repository
);
75 repositories
= Collections
.unmodifiableMap(map
);
77 notifyObservers(alias
);