2 * Copyright (c) 2013 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 * @throws IllegalArgumentException
35 * if unique constraint on module names is violated
37 public HierarchicalConfigMBeanFactoriesHolder(
38 final Map<String, Map.Entry<ModuleFactory, BundleContext>> factoriesMap) {
39 this.moduleNamesToConfigBeanFactories = Collections
40 .unmodifiableMap(factoriesMap);
41 moduleNames = Collections.unmodifiableSet(new TreeSet<>(
42 moduleNamesToConfigBeanFactories.keySet()));
43 List<ModuleFactory> factories = new ArrayList<>(this.moduleNamesToConfigBeanFactories.size());
44 Collection<Map.Entry<ModuleFactory, BundleContext>> entryCollection = this.moduleNamesToConfigBeanFactories.values();
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.
54 * @throws IllegalArgumentException
55 * if factory is not found
57 public ModuleFactory findByModuleName(final String moduleName) {
58 Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
60 throw new ModuleFactoryNotFoundException(moduleName);
62 return result.getKey();
65 public Set<String> getModuleNames() {
69 public List<ModuleFactory> getModuleFactories() {
70 return moduleFactories;