2 * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.manager.impl.factoriesresolver;
10 import java.util.AbstractMap;
11 import java.util.HashMap;
13 import org.opendaylight.controller.config.spi.ModuleFactory;
14 import org.osgi.framework.BundleContext;
16 public class HardcodedModuleFactoriesResolver implements ModuleFactoriesResolver {
17 private final Map<String, Map.Entry<ModuleFactory, BundleContext>> factories;
19 public HardcodedModuleFactoriesResolver(final BundleContext bundleContext, final ModuleFactory... list) {
20 this.factories = new HashMap<>(list.length);
21 for (ModuleFactory moduleFactory : list) {
22 String moduleName = moduleFactory.getImplementationName();
23 if (moduleName == null || moduleName.isEmpty()) {
24 throw new IllegalStateException("Invalid implementation name for " + moduleFactory);
26 Map.Entry<ModuleFactory, BundleContext> conflicting = factories.get(moduleName);
27 if (conflicting == null) {
28 factories.put(moduleName, new AbstractMap.SimpleEntry<>(moduleFactory, bundleContext));
30 throw new IllegalArgumentException(String.format(
31 "Module name is not unique. Found two conflicting factories with same name '%s':\n\t%s\n\t%s\n",
32 moduleName, conflicting.getKey(), moduleFactory));
38 public Map<String, Map.Entry<ModuleFactory, BundleContext>> getAllFactories() {