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;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.List;
17 import java.util.TreeSet;
18 import javax.management.InstanceNotFoundException;
19 import org.opendaylight.controller.config.spi.ModuleFactory;
20 import org.osgi.framework.BundleContext;
23 * Hold sorted ConfigMBeanFactories by their module names. Check that module
24 * names are globally unique.
26 public class HierarchicalConfigMBeanFactoriesHolder {
28 private final Map<String, Map.Entry<ModuleFactory, BundleContext>> moduleNamesToConfigBeanFactories;
29 private final Set<String> moduleNames;
30 private final List<ModuleFactory> moduleFactories;
35 * @throws IllegalArgumentException
36 * if unique constraint on module names is violated
38 public HierarchicalConfigMBeanFactoriesHolder(
39 Map<String, Map.Entry<ModuleFactory, BundleContext>> factoriesMap) {
40 this.moduleNamesToConfigBeanFactories = Collections
41 .unmodifiableMap(factoriesMap);
42 moduleNames = Collections.unmodifiableSet(new TreeSet<>(
43 moduleNamesToConfigBeanFactories.keySet()));
44 List<ModuleFactory> factories = new ArrayList<>(this.moduleNamesToConfigBeanFactories.size());
45 Collection<Map.Entry<ModuleFactory, BundleContext>> entryCollection = this.moduleNamesToConfigBeanFactories.values();
46 for (Map.Entry<ModuleFactory, BundleContext> entry : entryCollection) {
47 factories.add(entry.getKey());
49 this.moduleFactories = Collections.unmodifiableList(factories);
53 * Get ModuleFactory by their name.
55 * @throws IllegalArgumentException
56 * if factory is not found
58 public ModuleFactory findByModuleName(String moduleName) throws InstanceNotFoundException {
59 Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
61 throw new InstanceNotFoundException(
62 "ModuleFactory not found with module name: " + moduleName);
64 return result.getKey();
67 public Set<String> getModuleNames() {
71 public List<ModuleFactory> getModuleFactories() {
72 return moduleFactories;