Fix checkstyle warnings for config-netconf-connector
[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 com.google.common.base.Optional;
12 import java.util.Map;
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;
18
19 public class RuntimeBeanEntryWritingStrategy extends CompositeAttributeWritingStrategy {
20
21     public RuntimeBeanEntryWritingStrategy(Document document, String key,
22             Map<String, AttributeWritingStrategy> innerStrats) {
23         super(document, key, innerStrats);
24     }
25
26     /*
27      * (non-Javadoc)
28      *
29      * @see org.opendaylight.controller.config.netconf.mapping.attributes.toxml.
30      * AttributeWritingStrategy#writeElement(org.w3c.dom.Element,
31      * java.lang.Object)
32      */
33     @Override
34     public void writeElement(Element parentElement, String namespace, Object value) {
35         Util.checkType(value, Map.class);
36
37         Element innerNode = XmlUtil.createElement(getDocument(), getKey(), Optional.<String>absent());
38
39         Map<?, ?> map = (Map<?, ?>) value;
40
41         for (Entry<?, ?> runtimeBeanInstanceMappingEntry : map.entrySet()) {
42
43             // wrap runtime attributes with number assigned to current runtime
44             // bean
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);
50
51             for (Entry<?, ?> innerObjectEntry : innerMap.entrySet()) {
52
53                 Util.checkType(innerObjectEntry.getKey(), String.class);
54
55                 String innerKey = (String) innerObjectEntry.getKey();
56                 Object innerValue = innerObjectEntry.getValue();
57
58                 getInnerStrats().get(innerKey).writeElement(runtimeInstanceNode, namespace, innerValue);
59             }
60         }
61         parentElement.appendChild(innerNode);
62
63     }
64
65 }