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
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
11 import com.google.common.collect.HashMultimap;
12 import com.google.common.collect.Maps;
13 import com.google.common.collect.Multimap;
14 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
15 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
16 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
20 import javax.management.ObjectName;
24 public class Runtime {
26 private final Map<String, Map<String, ModuleRuntime>> moduleRuntimes;
28 public Runtime(Map<String, Map<String, ModuleRuntime>> moduleRuntimes) {
29 this.moduleRuntimes = moduleRuntimes;
32 private Map<String, Multimap<String, ObjectName>> mapInstancesToModules(Set<ObjectName> instancesToMap) {
33 Map<String, Multimap<String, ObjectName>> retVal = Maps.newHashMap();
35 for (ObjectName objectName : instancesToMap) {
36 String moduleName = ObjectNameUtil.getFactoryName(objectName);
38 Multimap<String, ObjectName> multimap = retVal.get(moduleName);
39 if (multimap == null) {
40 multimap = HashMultimap.create();
41 retVal.put(moduleName, multimap);
44 String instanceName = ObjectNameUtil.getInstanceName(objectName);
46 multimap.put(instanceName, objectName);
52 public Element toXml(Set<ObjectName> instancesToMap, Document document) {
53 Element root = document.createElement(XmlNetconfConstants.DATA_KEY);
55 Element modulesElement = document.createElement(XmlNetconfConstants.MODULES_KEY);
56 XmlUtil.addNamespaceAttr(modulesElement,
57 XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
58 root.appendChild(modulesElement);
60 Map<String, Multimap<String, ObjectName>> moduleToInstances = mapInstancesToModules(instancesToMap);
62 for (String localNamespace : moduleRuntimes.keySet()) {
63 for (String moduleName : moduleRuntimes.get(localNamespace).keySet()) {
64 Multimap<String, ObjectName> instanceToRbe = moduleToInstances.get(moduleName);
66 if (instanceToRbe == null)
69 ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
70 Element innerXml = moduleRuntime.toXml(localNamespace, instanceToRbe, document);
71 modulesElement.appendChild(innerXml);