import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
}));
}
- public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document) {
- return toXml(rootOn, childRbeOns, document, null, null);
+ public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, Element parentElement, String namespace) {
+ return toXml(rootOn, childRbeOns, document, null, parentElement, namespace);
}
public Element toXml(ObjectName rootOn, Set<ObjectName> childRbeOns, Document document, String instanceIndex,
- String keyName) {
- Element xml = document.createElement(keyName == null ? XmlNetconfConstants.DATA_KEY : keyName);
+ Element parentElement, String namespace) {
// TODO namespace
- xml = instanceMapping.toXml(rootOn, null, "namespace", document, xml);
+ Element xml = instanceMapping.toXml(rootOn, null, namespace, document, parentElement);
if (instanceIndex != null) {
xml.setAttribute(KEY_ATTRIBUTE_KEY, instanceIndex);
String runtimeInstanceIndex = objectName.getKeyProperty(childMappingEntry.getKey());
String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey());
- xml.appendChild(childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
- runtimeInstanceIndex, elementName));
+
+ Element innerXml = document.createElement(elementName);
+ childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
+ runtimeInstanceIndex, innerXml, namespace);
+ xml.appendChild(innerXml);
}
}
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
-import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
import org.opendaylight.controller.netconf.util.xml.XmlUtil;
throw new IllegalStateException("Root runtime bean not found among " + runtimeBeanOns);
}
- public Element toXml(String namespace, Multimap<String, ObjectName> instances, Document document) {
- Element root = document.createElement(XmlNetconfConstants.MODULE_KEY);
- XmlUtil.addNamespaceAttr(root, namespace);
+ public Element toXml(String namespace, String instanceName, Collection<ObjectName> runtimeBeanOns, Document document) {
+ Element moduleElement = document.createElement(XmlNetconfConstants.MODULE_KEY);
- Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, moduleName);
- root.appendChild(nameElement);
+ final String prefix = getPrefix(namespace);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlNetconfConstants.TYPE_KEY, prefix,
+ moduleName);
+ XmlUtil.addPrefixedNamespaceAttr(typeElement, prefix, namespace);
+ moduleElement.appendChild(typeElement);
- for (String instanceName : instances.keySet()) {
- Element instance = document.createElement(XmlNetconfConstants.INSTANCE_KEY);
+ Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, instanceName);
+ moduleElement.appendChild(nameElement);
- Element innerNameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, instanceName);
- instance.appendChild(innerNameElement);
+ ObjectName rootName = findRoot(runtimeBeanOns);
- Collection<ObjectName> runtimeBeanOns = instances.get(instanceName);
- ObjectName rootName = findRoot(runtimeBeanOns);
+ Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
+ childrenRuntimeBeans.remove(rootName);
- Set<ObjectName> childrenRuntimeBeans = Sets.newHashSet(runtimeBeanOns);
- childrenRuntimeBeans.remove(rootName);
+ instanceRuntime.toXml(rootName, childrenRuntimeBeans, document, moduleElement, namespace);
- instance.appendChild(instanceRuntime.toXml(rootName, childrenRuntimeBeans, document));
-
- root.appendChild(instance);
- }
+ return moduleElement;
+ }
- return root;
+ private String getPrefix(String namespace) {
+ return XmlNetconfConstants.PREFIX;
}
}
if (instanceToRbe == null)
continue;
- ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
- Element innerXml = moduleRuntime.toXml(localNamespace, instanceToRbe, document);
- modulesElement.appendChild(innerXml);
+ for (String instanceName : instanceToRbe.keySet()) {
+ ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
+ Element innerXml = moduleRuntime.toXml(localNamespace, instanceName, instanceToRbe.get(instanceName), document);
+ modulesElement.appendChild(innerXml);
+ }
+
}
}
Element response = get();
- assertEquals(2, getElementsSize(response, "instance"));
+ System.err.println(XmlUtil.toString(response));
+
+ assertEquals(2, getElementsSize(response, "module"));
assertEquals(2, getElementsSize(response, "asdf"));
assertEquals(5, getElementsSize(response, "inner-running-data"));
assertEquals(5, getElementsSize(response, "deep2"));