Merge "BUG-624 make netconf tcp address optional in config.ini with default value...
[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 java.util.Collection;
13 import java.util.Set;
14 import javax.management.ObjectName;
15 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ModuleConfig;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18
19 public class ModuleRuntime {
20
21     private final InstanceRuntime instanceRuntime;
22
23     public ModuleRuntime(InstanceRuntime instanceRuntime) {
24         this.instanceRuntime = instanceRuntime;
25     }
26
27     private ObjectName findRoot(Collection<ObjectName> runtimeBeanOns) {
28         for (ObjectName objectName : runtimeBeanOns) {
29             if (objectName.getKeyPropertyList().size() == 3){
30                 return objectName;
31             }
32         }
33         throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns);
34     }
35
36     public Element toXml(String namespace, Collection<ObjectName> runtimeBeanOns,
37                          Document document, ModuleConfig moduleConfig, ObjectName configBeanON) {
38
39         Element moduleElement = moduleConfig.toXml(configBeanON, document, namespace);
40
41         ObjectName rootName = findRoot(runtimeBeanOns);
42
43         Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
44         childrenRuntimeBeans.remove(rootName);
45
46         // FIXME: why is this called and not used?
47         instanceRuntime.toXml(rootName, childrenRuntimeBeans, document, moduleElement, namespace);
48
49         return moduleElement;
50     }
51
52 }