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.attributes.toxml;
11 import com.google.common.base.Optional;
13 import java.util.Map.Entry;
14 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
15 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
19 public class RuntimeBeanEntryWritingStrategy extends CompositeAttributeWritingStrategy {
21 public RuntimeBeanEntryWritingStrategy(Document document, String key,
22 Map<String, AttributeWritingStrategy> innerStrats) {
23 super(document, key, innerStrats);
29 * @see org.opendaylight.controller.config.netconf.mapping.attributes.toxml.
30 * AttributeWritingStrategy#writeElement(org.w3c.dom.Element,
34 public void writeElement(Element parentElement, String namespace, Object value) {
35 Util.checkType(value, Map.class);
37 Element innerNode = XmlUtil.createElement(getDocument(), getKey(), Optional.<String>absent());
39 Map<?, ?> map = (Map<?, ?>) value;
41 for (Entry<?, ?> runtimeBeanInstanceMappingEntry : map.entrySet()) {
43 // wrap runtime attributes with number assigned to current runtime
45 Util.checkType(runtimeBeanInstanceMappingEntry.getValue(), Map.class);
46 Map<?, ?> innerMap = (Map<?, ?>) runtimeBeanInstanceMappingEntry.getValue();
47 Element runtimeInstanceNode = XmlUtil.createElement(getDocument(), "_"
48 + runtimeBeanInstanceMappingEntry.getKey(), Optional.<String>absent());
49 innerNode.appendChild(runtimeInstanceNode);
51 for (Entry<?, ?> innerObjectEntry : innerMap.entrySet()) {
53 Util.checkType(innerObjectEntry.getKey(), String.class);
55 String innerKey = (String) innerObjectEntry.getKey();
56 Object innerValue = innerObjectEntry.getValue();
58 getInnerStrats().get(innerKey).writeElement(runtimeInstanceNode, namespace, innerValue);
61 parentElement.appendChild(innerNode);