+ if(factory == null) {
+ throw new NullPointerException("ServiceReference of class" + serviceReference.getClass() + "not found.");
+ }
+
+ String moduleName = factory.getImplementationName();
+ if (moduleName == null || moduleName.isEmpty()) {
+ throw new IllegalStateException(
+ "Invalid implementation name for " + factory);
+ }
+ if (serviceReference.getBundle() == null || serviceReference.getBundle().getBundleContext() == null) {
+ throw new NullPointerException("Bundle context of " + factory + " ModuleFactory not found.");
+ }
+ LOG.debug("Reading factory {} {}", moduleName, factory);
+
+ Map.Entry<ModuleFactory, BundleContext> conflicting = result.get(moduleName);
+ if (conflicting != null) {
+ String error = String
+ .format("Module name is not unique. Found two conflicting factories with same name '%s': '%s' '%s'",
+ moduleName, conflicting.getKey(), factory);
+ LOG.error(error);
+ throw new IllegalArgumentException(error);
+ } else {
+ result.put(moduleName, new AbstractMap.SimpleImmutableEntry<>(factory,
+ serviceReference.getBundle().getBundleContext()));