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;
12 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 CompositeAttributeWritingStrategy implements AttributeWritingStrategy {
21 protected final String key;
22 protected final Document document;
23 protected final Map<String, AttributeWritingStrategy> innerStrats;
25 public CompositeAttributeWritingStrategy(Document document, String key,
26 Map<String, AttributeWritingStrategy> innerStrats) {
27 this.document = document;
29 this.innerStrats = innerStrats;
33 public void writeElement(Element parentElement, String namespace, Object value) {
34 Util.checkType(value, Map.class);
36 Element innerNode = document.createElement(key);
37 XmlUtil.addNamespaceAttr(innerNode, namespace);
39 Map<?, ?> map = (Map<?, ?>) value;
41 for (Entry<?, ?> innerObjectEntry : map.entrySet()) {
42 Util.checkType(innerObjectEntry.getKey(), String.class);
44 String innerKey = (String) innerObjectEntry.getKey();
45 Object innerValue = innerObjectEntry.getValue();
47 innerStrats.get(innerKey).writeElement(innerNode, namespace, innerValue);
49 parentElement.appendChild(innerNode);