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 import com.google.common.base.Optional;
21 public class CompositeAttributeWritingStrategy implements AttributeWritingStrategy {
23 protected final String key;
24 protected final Document document;
25 protected final Map<String, AttributeWritingStrategy> innerStrats;
27 public CompositeAttributeWritingStrategy(Document document, String key,
28 Map<String, AttributeWritingStrategy> innerStrats) {
29 this.document = document;
31 this.innerStrats = innerStrats;
35 public void writeElement(Element parentElement, String namespace, Object value) {
36 Util.checkType(value, Map.class);
38 Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
40 Map<?, ?> map = (Map<?, ?>) value;
42 for (Entry<?, ?> innerObjectEntry : map.entrySet()) {
43 Util.checkType(innerObjectEntry.getKey(), String.class);
45 String innerKey = (String) innerObjectEntry.getKey();
46 Object innerValue = innerObjectEntry.getValue();
48 innerStrats.get(innerKey).writeElement(innerNode, namespace, innerValue);
50 parentElement.appendChild(innerNode);