a67b348f9fc61310fb69161d6901d033517117df
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / toxml / RuntimeBeanEntryWritingStrategy.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.attributes.toxml;
10
11 import java.util.Map;
12 import java.util.Map.Entry;
13
14 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
17
18 public class RuntimeBeanEntryWritingStrategy extends CompositeAttributeWritingStrategy {
19
20     public RuntimeBeanEntryWritingStrategy(Document document, String key,
21             Map<String, AttributeWritingStrategy> innerStrats) {
22         super(document, key, innerStrats);
23     }
24
25     /*
26      * (non-Javadoc)
27      *
28      * @see org.opendaylight.controller.config.netconf.mapping.attributes.toxml.
29      * AttributeWritingStrategy#writeElement(org.w3c.dom.Element,
30      * java.lang.Object)
31      */
32     @Override
33     public void writeElement(Element parentElement, String namespace, Object value) {
34         Util.checkType(value, Map.class);
35
36         Element innerNode = document.createElement(key);
37
38         Map<?, ?> map = (Map<?, ?>) value;
39
40         for (Entry<?, ?> runtimeBeanInstanceMappingEntry : map.entrySet()) {
41
42             // wrap runtime attributes with number assigned to current runtime
43             // bean
44             Util.checkType(runtimeBeanInstanceMappingEntry.getValue(), Map.class);
45             Map<?, ?> innerMap = (Map<?, ?>) runtimeBeanInstanceMappingEntry.getValue();
46             Element runtimeInstanceNode = document.createElement("_"
47                     + (String) runtimeBeanInstanceMappingEntry.getKey());
48             innerNode.appendChild(runtimeInstanceNode);
49
50             for (Entry<?, ?> innerObjectEntry : innerMap.entrySet()) {
51
52                 Util.checkType(innerObjectEntry.getKey(), String.class);
53
54                 String innerKey = (String) innerObjectEntry.getKey();
55                 Object innerValue = innerObjectEntry.getValue();
56
57                 innerStrats.get(innerKey).writeElement(runtimeInstanceNode, namespace, innerValue);
58             }
59         }
60         parentElement.appendChild(innerNode);
61
62     }
63
64 }