Add filtering capability to config.ini in order to reference logging bridge version.
[controller.git] / opendaylight / config / yang-store-impl / src / main / java / org / opendaylight / controller / config / yang / store / impl / YangStoreSnapshotImpl.java
1 /*
2  * Copyright (c) 2013 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.yang.store.impl;
9
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;
16
17 import java.util.Collections;
18 import java.util.Map;
19 import java.util.Set;
20
21 public class YangStoreSnapshotImpl implements YangStoreSnapshot {
22     private static final Logger logger = LoggerFactory.getLogger(YangStoreSnapshotImpl.class);
23
24     @Deprecated
25     private final Map<String /* Namespace from yang file */,
26             Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> moduleMXBeanEntryMap;
27
28     private final Map<Module, String> modulesToSources;
29     private final Map<QName, Map<String, ModuleMXBeanEntry>> qNamesToIdentitiesToModuleMXBeanEntries;
30
31     public YangStoreSnapshotImpl(Map<String, Map<String, ModuleMXBeanEntry>> moduleMXBeanEntryMap,
32                                  Map<Module, String> modulesToSources,
33                                  Map<QName, Map<String, ModuleMXBeanEntry>> qNamesToIdentitiesToModuleMXBeanEntries) {
34
35         this.moduleMXBeanEntryMap = Collections.unmodifiableMap(moduleMXBeanEntryMap);
36         this.modulesToSources = Collections.unmodifiableMap(modulesToSources);
37         this.qNamesToIdentitiesToModuleMXBeanEntries = Collections.unmodifiableMap(qNamesToIdentitiesToModuleMXBeanEntries);
38     }
39
40     public static YangStoreSnapshotImpl copy(YangStoreSnapshot yangStoreSnapshot) {
41         return new YangStoreSnapshotImpl(
42                 yangStoreSnapshot.getModuleMXBeanEntryMap(),
43                 yangStoreSnapshot.getModulesToSources(),
44                 yangStoreSnapshot.getQNamesToIdentitiesToModuleMXBeanEntries());
45     }
46
47     /**
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.
50      */
51     @Override
52     public Map<String, Map<String, ModuleMXBeanEntry>> getModuleMXBeanEntryMap() {
53         return moduleMXBeanEntryMap;
54     }
55
56     @Override
57     public Map<QName, Map<String, ModuleMXBeanEntry>> getQNamesToIdentitiesToModuleMXBeanEntries() {
58         return qNamesToIdentitiesToModuleMXBeanEntries;
59     }
60
61     @Override
62     public Set<Module> getModules() {
63         return modulesToSources.keySet();
64     }
65
66     @Override
67     public String getModuleSource(Module module) {
68         String result = modulesToSources.get(module);
69         if (result == null) {
70             logger.trace("Cannot find module {} in {}", module, modulesToSources);
71             throw new IllegalArgumentException("Module not found in this snapshot:" + module);
72         }
73         return result;
74     }
75
76     @Override
77     public Map<Module, String> getModulesToSources() {
78         return modulesToSources;
79     }
80
81     @Override
82     public int countModuleMXBeanEntries() {
83         int i = 0;
84         for (Map<String, ModuleMXBeanEntry> value : moduleMXBeanEntryMap
85                 .values()) {
86             i += value.keySet().size();
87         }
88         return i;
89     }
90
91     @Override
92     public void close() {
93         // TODO: reference counting
94     }
95
96 }