- try {
- Collection<ServiceReference<Repository>> 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<ServiceReference<Repository>> 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;