1 package org
.argeo
.cms
.internal
.kernel
;
3 import java
.util
.Dictionary
;
4 import java
.util
.HashMap
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.apache
.jackrabbit
.api
.JackrabbitRepository
;
10 import org
.apache
.jackrabbit
.core
.RepositoryContext
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.jcr
.ArgeoJcrConstants
;
13 import org
.argeo
.node
.RepoConf
;
14 import org
.argeo
.util
.LangUtils
;
15 import org
.osgi
.framework
.BundleContext
;
16 import org
.osgi
.framework
.Constants
;
17 import org
.osgi
.framework
.FrameworkUtil
;
18 import org
.osgi
.service
.cm
.ConfigurationException
;
19 import org
.osgi
.service
.cm
.ManagedServiceFactory
;
21 class RepositoryServiceFactory
implements ManagedServiceFactory
{
22 private final static Log log
= LogFactory
.getLog(RepositoryServiceFactory
.class);
23 private final BundleContext bc
= FrameworkUtil
.getBundle(RepositoryServiceFactory
.class).getBundleContext();
25 private Map
<String
, RepositoryContext
> repositories
= new HashMap
<String
, RepositoryContext
>();
28 public String
getName() {
29 return "Jackrabbit repository service factory";
33 public void updated(String pid
, Dictionary
<String
, ?
> properties
) throws ConfigurationException
{
34 if (repositories
.containsKey(pid
))
35 throw new ArgeoException("Already a repository registered for " + pid
);
37 if (properties
== null)
40 if (repositories
.containsKey(pid
)) {
41 log
.warn("Ignore update of Jackrabbit repository " + pid
);
46 RepositoryBuilder repositoryBuilder
= new RepositoryBuilder();
47 RepositoryContext repositoryContext
= repositoryBuilder
.createRepositoryContext(properties
);
48 repositories
.put(pid
, repositoryContext
);
49 Dictionary
<String
, Object
> props
= LangUtils
.init(Constants
.SERVICE_PID
, pid
);
50 props
.put(ArgeoJcrConstants
.JCR_REPOSITORY_URI
, properties
.get(RepoConf
.labeledUri
.name()));
51 bc
.registerService(JackrabbitRepository
.class, repositoryContext
.getRepository(), props
);
52 } catch (Exception e
) {
53 throw new ArgeoException("Cannot create Jackrabbit repository " + pid
, e
);
59 public void deleted(String pid
) {
60 RepositoryContext repositoryContext
= repositories
.remove(pid
);
61 repositoryContext
.getRepository().shutdown();
62 if (log
.isDebugEnabled())
63 log
.debug("Deleted repository " + pid
);
66 public void shutdown() {
67 for (String pid
: repositories
.keySet()) {
69 repositories
.get(pid
).getRepository().shutdown();
70 } catch (Exception e
) {
71 log
.error("Error when shutting down Jackrabbit repository " + pid
, e
);