Merge "BUG 652 leafref CCE & BUG 720 colons problem"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / runtime / ModuleRuntime.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
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
10
11 import com.google.common.collect.Sets;
12 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ModuleConfig;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
14 import org.w3c.dom.Document;
15 import org.w3c.dom.Element;
16
17 import javax.management.ObjectName;
18 import java.util.Collection;
19 import java.util.Set;
20
21 public class ModuleRuntime {
22
23     private final InstanceRuntime instanceRuntime;
24
25     public ModuleRuntime(String moduleName, InstanceRuntime instanceRuntime) {
26         this.instanceRuntime = instanceRuntime;
27     }
28
29     public InstanceRuntime getMbeanMapping() {
30         return instanceRuntime;
31     }
32
33     private ObjectName findRoot(Collection<ObjectName> runtimeBeanOns) {
34         for (ObjectName objectName : runtimeBeanOns) {
35             if (objectName.getKeyPropertyList().size() == 3){
36                 return objectName;
37             }
38         }
39         throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns);
40     }
41
42     public Element toXml(String namespace, Collection<ObjectName> runtimeBeanOns,
43                          Document document, ModuleConfig moduleConfig, ObjectName configBeanON, ServiceRegistryWrapper serviceTracker) {
44
45         Element moduleElement = moduleConfig.toXml(configBeanON, serviceTracker, document, namespace);
46
47         ObjectName rootName = findRoot(runtimeBeanOns);
48
49         Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
50         childrenRuntimeBeans.remove(rootName);
51
52         instanceRuntime.toXml(rootName, childrenRuntimeBeans, document, moduleElement, namespace);
53
54         return moduleElement;
55     }
56
57 }