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.yang.store.impl;
10 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
11 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.Module;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 import java.util.Collections;
21 public class YangStoreSnapshotImpl implements YangStoreSnapshot {
22 private static final Logger logger = LoggerFactory.getLogger(YangStoreSnapshotImpl.class);
25 private final Map<String /* Namespace from yang file */,
26 Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> moduleMXBeanEntryMap;
28 private final Map<Module, String> modulesToSources;
29 private final Map<QName, Map<String, ModuleMXBeanEntry>> qNamesToIdentitiesToModuleMXBeanEntries;
31 public YangStoreSnapshotImpl(Map<String, Map<String, ModuleMXBeanEntry>> moduleMXBeanEntryMap,
32 Map<Module, String> modulesToSources,
33 Map<QName, Map<String, ModuleMXBeanEntry>> qNamesToIdentitiesToModuleMXBeanEntries) {
35 this.moduleMXBeanEntryMap = Collections.unmodifiableMap(moduleMXBeanEntryMap);
36 this.modulesToSources = Collections.unmodifiableMap(modulesToSources);
37 this.qNamesToIdentitiesToModuleMXBeanEntries = Collections.unmodifiableMap(qNamesToIdentitiesToModuleMXBeanEntries);
40 public static YangStoreSnapshotImpl copy(YangStoreSnapshot yangStoreSnapshot) {
41 return new YangStoreSnapshotImpl(
42 yangStoreSnapshot.getModuleMXBeanEntryMap(),
43 yangStoreSnapshot.getModulesToSources(),
44 yangStoreSnapshot.getQNamesToIdentitiesToModuleMXBeanEntries());
48 * @return all loaded config modules. Key of outer map is namespace of yang file.
49 * Key of inner map is name of module entry. Value is module entry.
52 public Map<String, Map<String, ModuleMXBeanEntry>> getModuleMXBeanEntryMap() {
53 return moduleMXBeanEntryMap;
57 public Map<QName, Map<String, ModuleMXBeanEntry>> getQNamesToIdentitiesToModuleMXBeanEntries() {
58 return qNamesToIdentitiesToModuleMXBeanEntries;
62 public Set<Module> getModules() {
63 return modulesToSources.keySet();
67 public String getModuleSource(Module module) {
68 String result = modulesToSources.get(module);
70 logger.trace("Cannot find module {} in {}", module, modulesToSources);
71 throw new IllegalArgumentException("Module not found in this snapshot:" + module);
77 public Map<Module, String> getModulesToSources() {
78 return modulesToSources;
82 public int countModuleMXBeanEntries() {
84 for (Map<String, ModuleMXBeanEntry> value : moduleMXBeanEntryMap
86 i += value.keySet().size();
93 // TODO: reference counting