Introduce home workspace.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / CmsDeployment.java
index 59d8c910f9640c287d564d924ac5da48db1a378a..7a6ae064667817ff764d0bc3dc37e2da1ea1a45a 100644 (file)
@@ -42,6 +42,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleWire;
@@ -54,10 +55,8 @@ import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.UserAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
+/** Implementation of a CMS deployment. */
 public class CmsDeployment implements NodeDeployment {
-       // private final static String LEGACY_JCR_REPOSITORY_ALIAS =
-       // "argeo.jcr.repository.alias";
-
        private final Log log = LogFactory.getLog(getClass());
        private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
 
@@ -199,6 +198,15 @@ public class CmsDeployment implements NodeDeployment {
                if (nodeHttp != null)
                        nodeHttp.destroy();
 
+               try {
+                       for (ServiceReference<JackrabbitLocalRepository> sr : bc
+                                       .getServiceReferences(JackrabbitLocalRepository.class, null)) {
+                               bc.getService(sr).destroy();
+                       }
+               } catch (InvalidSyntaxException e1) {
+                       log.error("Cannot sclean repsoitories", e1);
+               }
+
                try {
                        JettyConfigurator.stopServer(KernelConstants.DEFAULT_JETTY_SERVER);
                } catch (Exception e) {
@@ -276,11 +284,11 @@ public class CmsDeployment implements NodeDeployment {
                        JcrUtils.logoutQuietly(adminSession);
                }
 
-               Hashtable<String, String> regProps = new Hashtable<String, String>();
+               // Publish home with the highest service ranking
+               Hashtable<String, Object> regProps = new Hashtable<>();
                regProps.put(NodeConstants.CN, NodeConstants.HOME);
-               // regProps.put(LEGACY_JCR_REPOSITORY_ALIAS, NodeConstants.HOME);
+               regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
                homeRepository = new HomeRepository(deployedRepository, false);
-               // register
                bc.registerService(Repository.class, homeRepository, regProps);
 
                // Keyring only if Argeo extensions are available
@@ -398,12 +406,18 @@ public class CmsDeployment implements NodeDeployment {
 
        private void publishLocalRepo(String dataModelName, Repository repository) {
                Hashtable<String, Object> properties = new Hashtable<>();
-               // properties.put(LEGACY_JCR_REPOSITORY_ALIAS, name);
                properties.put(NodeConstants.CN, dataModelName);
-               if (dataModelName.equals(NodeConstants.NODE))
-                       properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
-               LocalRepository localRepository = new LocalRepository(repository, dataModelName);
-               bc.registerService(Repository.class, localRepository, properties);
+               LocalRepository localRepository;
+               String[] classes;
+               if (repository instanceof RepositoryImpl) {
+                       localRepository = new JackrabbitLocalRepository((RepositoryImpl) repository, dataModelName);
+                       classes = new String[] { Repository.class.getName(), LocalRepository.class.getName(),
+                                       JackrabbitLocalRepository.class.getName() };
+               } else {
+                       localRepository = new LocalRepository(repository, dataModelName);
+                       classes = new String[] { Repository.class.getName(), LocalRepository.class.getName() };
+               }
+               bc.registerService(classes, localRepository, properties);
                if (log.isTraceEnabled())
                        log.trace("Published data model " + dataModelName);
        }