X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FNodeRepositoryFactory.java;h=efbb724ff9174a751bad9ae639809e14b44fc443;hb=ed3d525b21f55ed76763381b91c888404487e3e1;hp=a0dd38e3e9779088066450e61fc3937a35e1f535;hpb=71196c25959b53964edf87aeb4387ed8b11b4868;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeRepositoryFactory.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeRepositoryFactory.java index a0dd38e3e..efbb724ff 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeRepositoryFactory.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeRepositoryFactory.java @@ -15,7 +15,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory; import org.argeo.api.NodeConstants; import org.argeo.cms.internal.jcr.RepoConf; -import org.argeo.jcr.ArgeoJcrException; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; @@ -27,23 +26,29 @@ import org.osgi.framework.ServiceReference; */ class NodeRepositoryFactory implements RepositoryFactory { private final Log log = LogFactory.getLog(getClass()); - private final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); +// private final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); // private Resource fileRepositoryConfiguration = new ClassPathResource( // "/org/argeo/cms/internal/kernel/repository-localfs.xml"); protected Repository getRepositoryByAlias(String alias) { - try { - Collection> srs = bundleContext.getServiceReferences(Repository.class, - "(" + NodeConstants.CN + "=" + alias + ")"); - if (srs.size() == 0) - throw new ArgeoJcrException("No repository with alias " + alias + " found in OSGi registry"); - else if (srs.size() > 1) - throw new ArgeoJcrException( - srs.size() + " repositories with alias " + alias + " found in OSGi registry"); - return bundleContext.getService(srs.iterator().next()); - } catch (InvalidSyntaxException e) { - throw new ArgeoJcrException("Cannot find repository with alias " + alias, e); + BundleContext bundleContext = Activator.getBundleContext(); + if (bundleContext != null) { + try { + Collection> srs = bundleContext.getServiceReferences(Repository.class, + "(" + NodeConstants.CN + "=" + alias + ")"); + if (srs.size() == 0) + throw new IllegalArgumentException("No repository with alias " + alias + " found in OSGi registry"); + else if (srs.size() > 1) + throw new IllegalArgumentException( + srs.size() + " repositories with alias " + alias + " found in OSGi registry"); + return bundleContext.getService(srs.iterator().next()); + } catch (InvalidSyntaxException e) { + throw new IllegalArgumentException("Cannot find repository with alias " + alias, e); + } + } else { + // TODO ability to filter static services + return null; } } @@ -85,7 +90,7 @@ class NodeRepositoryFactory implements RepositoryFactory { // JCR repository factory"); repository = getRepositoryByAlias(getAliasFromURI(uri)); } else - throw new ArgeoJcrException("Unrecognized URI format " + uri); + throw new IllegalArgumentException("Unrecognized URI format " + uri); } @@ -98,10 +103,10 @@ class NodeRepositoryFactory implements RepositoryFactory { // with properties " + properties); repository = getRepositoryByAlias(alias); } else - throw new ArgeoJcrException("Not enough information in " + parameters); + throw new IllegalArgumentException("Not enough information in " + parameters); if (repository == null) - throw new ArgeoJcrException("Repository not found " + parameters); + throw new IllegalArgumentException("Repository not found " + parameters); return repository; } @@ -113,7 +118,7 @@ class NodeRepositoryFactory implements RepositoryFactory { params.put(KernelConstants.JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, defaultWorkspace); Repository repository = new Jcr2davRepositoryFactory().getRepository(params); if (repository == null) - throw new ArgeoJcrException("Remote Davex repository " + uri + " not found"); + throw new IllegalArgumentException("Remote Davex repository " + uri + " not found"); log.info("Initialized remote Jackrabbit repository from uri " + uri); return repository; } @@ -173,7 +178,7 @@ class NodeRepositoryFactory implements RepositoryFactory { alias = alias.substring(0, alias.length() - 1); return alias; } catch (URISyntaxException e) { - throw new ArgeoJcrException("Cannot interpret URI " + uri, e); + throw new IllegalArgumentException("Cannot interpret URI " + uri, e); } }