]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java
Moves JCR APIs to node.api bundle
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / RepositoryServiceFactory.java
index a4e3a9bb8db9982d443c0e632ab43cea29e34afd..f69c498e3f30dbe221d11ae019a1170034db725b 100644 (file)
@@ -6,11 +6,9 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.api.JackrabbitRepository;
 import org.apache.jackrabbit.core.RepositoryContext;
-import org.argeo.ArgeoException;
-import org.argeo.jcr.ArgeoJcrConstants;
-import org.argeo.node.RepoConf;
+import org.argeo.cms.CmsException;
+import org.argeo.node.NodeConstants;
 import org.argeo.util.LangUtils;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -23,6 +21,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory {
        private final BundleContext bc = FrameworkUtil.getBundle(RepositoryServiceFactory.class).getBundleContext();
 
        private Map<String, RepositoryContext> repositories = new HashMap<String, RepositoryContext>();
+       private Map<String, Object> pidToCn = new HashMap<String, Object>();
 
        @Override
        public String getName() {
@@ -32,7 +31,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory {
        @Override
        public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
                if (repositories.containsKey(pid))
-                       throw new ArgeoException("Already a repository registered for " + pid);
+                       throw new CmsException("Already a repository registered for " + pid);
 
                if (properties == null)
                        return;
@@ -47,10 +46,17 @@ class RepositoryServiceFactory implements ManagedServiceFactory {
                        RepositoryContext repositoryContext = repositoryBuilder.createRepositoryContext(properties);
                        repositories.put(pid, repositoryContext);
                        Dictionary<String, Object> props = LangUtils.init(Constants.SERVICE_PID, pid);
-                       props.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, properties.get(RepoConf.labeledUri.name()));
-                       bc.registerService(JackrabbitRepository.class, repositoryContext.getRepository(), props);
+                       // props.put(ArgeoJcrConstants.JCR_REPOSITORY_URI,
+                       // properties.get(RepoConf.labeledUri.name()));
+                       Object cn = properties.get(NodeConstants.CN);
+                       if (cn != null) {
+                               props.put(NodeConstants.CN, cn);
+                               props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
+                               pidToCn.put(pid, cn);
+                       }
+                       bc.registerService(RepositoryContext.class, repositoryContext, props);
                } catch (Exception e) {
-                       throw new ArgeoException("Cannot create Jackrabbit repository " + pid, e);
+                       throw new CmsException("Cannot create Jackrabbit repository " + pid, e);
                }
 
        }
@@ -67,6 +73,9 @@ class RepositoryServiceFactory implements ManagedServiceFactory {
                for (String pid : repositories.keySet()) {
                        try {
                                repositories.get(pid).getRepository().shutdown();
+                               if (log.isDebugEnabled())
+                                       log.debug("Shut down repository " + pid
+                                                       + (pidToCn.containsKey(pid) ? " (" + pidToCn.get(pid) + ")" : ""));
                        } catch (Exception e) {
                                log.error("Error when shutting down Jackrabbit repository " + pid, e);
                        }