ServiceReference ref = bundleContext.getServiceReference(DocumentRepository.class.getName());
if (ref == null) {
throw new IllegalStateException("Can not get a reference to the DocumentRepository");
}
try {
DocumentRepository rep = (DocumentRepository) bundleContext.getService(ref);
this.documentId = rep.register(document.getBytes());
} finally {
if (ref != null) {
bundleContext.ungetService(ref);
}
}