X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FRepositoryServiceFactory.java;h=630a453c2d5a40008c0d0af9af127c6278290b89;hb=3c7803ca05e2b0276d635e64046d924d3f1884c9;hp=a06b12bbd1852491de6a6f0f90a43167eabc645b;hpb=5b3108fe285bca50565b58b63fa4feddc96c0765;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java index a06b12bbd..630a453c2 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java @@ -12,19 +12,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.core.RepositoryContext; import org.argeo.api.NodeConstants; -import org.argeo.cms.CmsException; import org.argeo.cms.internal.jcr.RepoConf; import org.argeo.cms.internal.jcr.RepositoryBuilder; import org.argeo.util.LangUtils; -import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; -import org.osgi.framework.FrameworkUtil; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.cm.ManagedServiceFactory; +/** A {@link ManagedServiceFactory} creating or referencing JCR repositories. */ class RepositoryServiceFactory implements ManagedServiceFactory { private final static Log log = LogFactory.getLog(RepositoryServiceFactory.class); - private final BundleContext bc = FrameworkUtil.getBundle(RepositoryServiceFactory.class).getBundleContext(); +// private final BundleContext bc = FrameworkUtil.getBundle(RepositoryServiceFactory.class).getBundleContext(); private Map repositories = new HashMap(); private Map pidToCn = new HashMap(); @@ -37,7 +35,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (repositories.containsKey(pid)) - throw new CmsException("Already a repository registered for " + pid); + throw new IllegalArgumentException("Already a repository registered for " + pid); if (properties == null) return; @@ -53,7 +51,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { RepositoryBuilder repositoryBuilder = new RepositoryBuilder(); RepositoryContext repositoryContext = repositoryBuilder.createRepositoryContext(properties); repositories.put(pid, repositoryContext); - Dictionary props = LangUtils.dico(Constants.SERVICE_PID, pid); + Dictionary props = LangUtils.dict(Constants.SERVICE_PID, pid); // props.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, // properties.get(RepoConf.labeledUri.name())); Object cn = properties.get(NodeConstants.CN); @@ -62,7 +60,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { // props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn); pidToCn.put(pid, cn); } - bc.registerService(RepositoryContext.class, repositoryContext, props); + Activator.registerService(RepositoryContext.class, repositoryContext, props); } else { try { Object cn = properties.get(NodeConstants.CN); @@ -70,15 +68,16 @@ class RepositoryServiceFactory implements ManagedServiceFactory { if (defaultWorkspace == null) defaultWorkspace = RepoConf.defaultWorkspace.getDefault(); URI uri = new URI(labeledUri.toString()); - RepositoryFactory repositoryFactory = bc - .getService(bc.getServiceReference(RepositoryFactory.class)); +// RepositoryFactory repositoryFactory = bc +// .getService(bc.getServiceReference(RepositoryFactory.class)); + RepositoryFactory repositoryFactory = Activator.getService(RepositoryFactory.class); Map parameters = new HashMap(); parameters.put(RepoConf.labeledUri.name(), uri.toString()); parameters.put(RepoConf.defaultWorkspace.name(), defaultWorkspace.toString()); Repository repository = repositoryFactory.getRepository(parameters); // Repository repository = NodeUtils.getRepositoryByUri(repositoryFactory, // uri.toString()); - Dictionary props = LangUtils.dico(Constants.SERVICE_PID, pid); + Dictionary props = LangUtils.dict(Constants.SERVICE_PID, pid); props.put(RepoConf.labeledUri.name(), new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null) .toString()); @@ -87,13 +86,14 @@ class RepositoryServiceFactory implements ManagedServiceFactory { // props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn); pidToCn.put(pid, cn); } - bc.registerService(Repository.class, repository, props); + Activator.registerService(Repository.class, repository, props); // home - if (cn.equals(NodeConstants.NODE)) { - Dictionary homeProps = LangUtils.dico(NodeConstants.CN, NodeConstants.EGO); + if (cn.equals(NodeConstants.NODE_REPOSITORY)) { + Dictionary homeProps = LangUtils.dict(NodeConstants.CN, + NodeConstants.EGO_REPOSITORY); EgoRepository homeRepository = new EgoRepository(repository, true); - bc.registerService(Repository.class, homeRepository, homeProps); + Activator.registerService(Repository.class, homeRepository, homeProps); } } catch (Exception e) { // TODO Auto-generated catch block @@ -101,7 +101,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { } } } catch (Exception e) { - throw new CmsException("Cannot create Jackrabbit repository " + pid, e); + throw new IllegalStateException("Cannot create Jackrabbit repository " + pid, e); } } @@ -126,4 +126,5 @@ class RepositoryServiceFactory implements ManagedServiceFactory { } } } + }