X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FBundleContextBackedModuleFactoriesResolver.java;h=e8639d588197c146483b434fd83b4fb653a32c49;hb=248f46ddb283452df60d0e084d5a03af82ed5ef5;hp=2a533ab9a3a6813ad4fed4c4dcfe4a5dbcec2cf6;hpb=089bfc0f3f32322b54dba2bf9402769638c09e06;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java index 2a533ab9a3..e8639d5881 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; +import java.util.AbstractMap; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver; import org.opendaylight.controller.config.spi.ModuleFactory; import org.osgi.framework.BundleContext; @@ -15,17 +19,12 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.AbstractMap; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - /** * Retrieves list of currently registered Module Factories using bundlecontext. */ public class BundleContextBackedModuleFactoriesResolver implements ModuleFactoriesResolver { - private static final Logger logger = LoggerFactory + private static final Logger LOG = LoggerFactory .getLogger(BundleContextBackedModuleFactoriesResolver.class); private final BundleContext bundleContext; @@ -53,7 +52,7 @@ public class BundleContextBackedModuleFactoriesResolver implements if(factory == null) { throw new NullPointerException("ServiceReference of class" + serviceReference.getClass() + "not found."); } - StringBuffer errors = new StringBuffer(); + String moduleName = factory.getImplementationName(); if (moduleName == null || moduleName.isEmpty()) { throw new IllegalStateException( @@ -62,24 +61,18 @@ public class BundleContextBackedModuleFactoriesResolver implements if (serviceReference.getBundle() == null || serviceReference.getBundle().getBundleContext() == null) { throw new NullPointerException("Bundle context of " + factory + " ModuleFactory not found."); } - logger.debug("Reading factory {} {}", moduleName, factory); - String error = null; + LOG.debug("Reading factory {} {}", moduleName, factory); + Map.Entry conflicting = result.get(moduleName); if (conflicting != null) { - error = String - .format("Module name is not unique. Found two conflicting factories with same name '%s': " + - "\n\t%s\n\t%s\n", moduleName, conflicting.getKey(), factory); - - } - - if (error == 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())); - } else { - errors.append(error); - } - if (errors.length() > 0) { - throw new IllegalArgumentException(errors.toString()); } } return result;