Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / factoriesresolver / HardcodedModuleFactoriesResolver.java
1 /*
2  * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.manager.impl.factoriesresolver;
9
10 import java.util.AbstractMap;
11 import java.util.HashMap;
12 import java.util.Map;
13 import org.opendaylight.controller.config.spi.ModuleFactory;
14 import org.osgi.framework.BundleContext;
15
16 public class HardcodedModuleFactoriesResolver implements ModuleFactoriesResolver {
17     private final Map<String, Map.Entry<ModuleFactory, BundleContext>> factories;
18
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);
25             }
26             Map.Entry<ModuleFactory, BundleContext> conflicting = factories.get(moduleName);
27             if (conflicting == null) {
28                 factories.put(moduleName, new AbstractMap.SimpleEntry<>(moduleFactory, bundleContext));
29             } else {
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));
33             }
34         }
35     }
36
37     @Override
38     public Map<String, Map.Entry<ModuleFactory, BundleContext>> getAllFactories() {
39         return factories;
40     }
41 }