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.ArrayList;
11 import java.util.Collection;
12 import java.util.Collections;
13 import java.util.List;
16 import java.util.TreeSet;
17 import org.opendaylight.controller.config.api.ModuleFactoryNotFoundException;
18 import org.opendaylight.controller.config.spi.ModuleFactory;
19 import org.osgi.framework.BundleContext;
22 * Hold sorted ConfigMBeanFactories by their module names. Check that module
23 * names are globally unique.
25 public class HierarchicalConfigMBeanFactoriesHolder {
27 private final Map<String, Map.Entry<ModuleFactory, BundleContext>> moduleNamesToConfigBeanFactories;
28 private final Set<String> moduleNames;
29 private final List<ModuleFactory> moduleFactories;
34 * @param factoriesMap map of factories
35 * @throws IllegalArgumentException
36 * if unique constraint on module names is violated
38 public HierarchicalConfigMBeanFactoriesHolder(
39 final Map<String, Map.Entry<ModuleFactory, BundleContext>> factoriesMap) {
40 this.moduleNamesToConfigBeanFactories = Collections.unmodifiableMap(factoriesMap);
41 moduleNames = Collections.unmodifiableSet(new TreeSet<>(moduleNamesToConfigBeanFactories.keySet()));
42 List<ModuleFactory> factories = new ArrayList<>(this.moduleNamesToConfigBeanFactories.size());
43 Collection<Map.Entry<ModuleFactory, BundleContext>> entryCollection = this.moduleNamesToConfigBeanFactories
45 for (Map.Entry<ModuleFactory, BundleContext> entry : entryCollection) {
46 factories.add(entry.getKey());
48 this.moduleFactories = Collections.unmodifiableList(factories);
52 * Get ModuleFactory by their name.
56 * @return module factory
57 * @throws IllegalArgumentException
58 * if factory is not found
60 public ModuleFactory findByModuleName(final String moduleName) {
61 Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
63 throw new ModuleFactoryNotFoundException(moduleName);
65 return result.getKey();
68 public Set<String> getModuleNames() {
72 public List<ModuleFactory> getModuleFactories() {
73 return moduleFactories;