CDS: Add stress test RPC to the cars model
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / toxml / RuntimeBeanEntryWritingStrategy.java
1 /*
2  * Copyright (c) 2015 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.config.facade.xml.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.config.facade.xml.util.Util;
15 import org.opendaylight.controller.config.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     @Override
27     public void writeElement(Element parentElement, String namespace, Object value) {
28         Util.checkType(value, Map.class);
29
30         Element innerNode = XmlUtil.createElement(getDocument(), getKey(), Optional.<String>absent());
31
32         Map<?, ?> map = (Map<?, ?>) value;
33
34         for (Entry<?, ?> runtimeBeanInstanceMappingEntry : map.entrySet()) {
35
36             // wrap runtime attributes with number assigned to current runtime
37             // bean
38             Util.checkType(runtimeBeanInstanceMappingEntry.getValue(), Map.class);
39             Map<?, ?> innerMap = (Map<?, ?>) runtimeBeanInstanceMappingEntry.getValue();
40             Element runtimeInstanceNode = XmlUtil.createElement(getDocument(), "_"
41                     + runtimeBeanInstanceMappingEntry.getKey(), Optional.<String>absent());
42             innerNode.appendChild(runtimeInstanceNode);
43
44             for (Entry<?, ?> innerObjectEntry : innerMap.entrySet()) {
45
46                 Util.checkType(innerObjectEntry.getKey(), String.class);
47
48                 String innerKey = (String) innerObjectEntry.getKey();
49                 Object innerValue = innerObjectEntry.getValue();
50
51                 getInnerStrats().get(innerKey).writeElement(runtimeInstanceNode, namespace, innerValue);
52             }
53         }
54         parentElement.appendChild(innerNode);
55
56     }
57
58 }