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
.core
.RepositoryContext
;
10 import org
.argeo
.cms
.CmsException
;
11 import org
.argeo
.node
.NodeConstants
;
12 import org
.argeo
.util
.LangUtils
;
13 import org
.osgi
.framework
.BundleContext
;
14 import org
.osgi
.framework
.Constants
;
15 import org
.osgi
.framework
.FrameworkUtil
;
16 import org
.osgi
.service
.cm
.ConfigurationException
;
17 import org
.osgi
.service
.cm
.ManagedServiceFactory
;
19 class RepositoryServiceFactory
implements ManagedServiceFactory
{
20 private final static Log log
= LogFactory
.getLog(RepositoryServiceFactory
.class);
21 private final BundleContext bc
= FrameworkUtil
.getBundle(RepositoryServiceFactory
.class).getBundleContext();
23 private Map
<String
, RepositoryContext
> repositories
= new HashMap
<String
, RepositoryContext
>();
24 private Map
<String
, Object
> pidToCn
= new HashMap
<String
, Object
>();
27 public String
getName() {
28 return "Jackrabbit repository service factory";
32 public void updated(String pid
, Dictionary
<String
, ?
> properties
) throws ConfigurationException
{
33 if (repositories
.containsKey(pid
))
34 throw new CmsException("Already a repository registered for " + pid
);
36 if (properties
== null)
39 if (repositories
.containsKey(pid
)) {
40 log
.warn("Ignore update of Jackrabbit repository " + pid
);
45 RepositoryBuilder repositoryBuilder
= new RepositoryBuilder();
46 RepositoryContext repositoryContext
= repositoryBuilder
.createRepositoryContext(properties
);
47 repositories
.put(pid
, repositoryContext
);
48 Dictionary
<String
, Object
> props
= LangUtils
.dico(Constants
.SERVICE_PID
, pid
);
49 // props.put(ArgeoJcrConstants.JCR_REPOSITORY_URI,
50 // properties.get(RepoConf.labeledUri.name()));
51 Object cn
= properties
.get(NodeConstants
.CN
);
53 props
.put(NodeConstants
.CN
, cn
);
54 // props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
57 bc
.registerService(RepositoryContext
.class, repositoryContext
, props
);
58 } catch (Exception e
) {
59 throw new CmsException("Cannot create Jackrabbit repository " + pid
, e
);
65 public void deleted(String pid
) {
66 RepositoryContext repositoryContext
= repositories
.remove(pid
);
67 repositoryContext
.getRepository().shutdown();
68 if (log
.isDebugEnabled())
69 log
.debug("Deleted repository " + pid
);
72 public void shutdown() {
73 for (String pid
: repositories
.keySet()) {
75 repositories
.get(pid
).getRepository().shutdown();
76 if (log
.isDebugEnabled())
77 log
.debug("Shut down repository " + pid
78 + (pidToCn
.containsKey(pid
) ?
" (" + pidToCn
.get(pid
) + ")" : ""));
79 } catch (Exception e
) {
80 log
.error("Error when shutting down Jackrabbit repository " + pid
, e
);