CDS: Add stress test RPC to the cars model
[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.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public class ModuleRuntime {
21
22     private final InstanceRuntime instanceRuntime;
23
24     public ModuleRuntime(InstanceRuntime instanceRuntime) {
25         this.instanceRuntime = instanceRuntime;
26     }
27
28     private ObjectName findRoot(Collection<ObjectName> runtimeBeanOns) {
29         for (ObjectName objectName : runtimeBeanOns) {
30             if (objectName.getKeyPropertyList().size() == 3){
31                 return objectName;
32             }
33         }
34         throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns);
35     }
36
37     public Element toXml(String namespace, Collection<ObjectName> runtimeBeanOns,
38                          Document document, ModuleConfig moduleConfig, ObjectName configBeanON, final EnumResolver enumResolver) {
39
40         Element moduleElement = moduleConfig.toXml(configBeanON, document, namespace, enumResolver);
41
42         ObjectName rootName = findRoot(runtimeBeanOns);
43
44         Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
45         childrenRuntimeBeans.remove(rootName);
46
47         // FIXME: why is this called and not used?
48         instanceRuntime.toXml(rootName, childrenRuntimeBeans, document, moduleElement, namespace, enumResolver);
49
50         return moduleElement;
51     }
52
53 }