Add support for identity-ref config attributes to config/netconf subsystem
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / toxml / SimpleAttributeWritingStrategy.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 org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
12 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Element;
15
16 public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy {
17
18     private final Document document;
19     private final String key;
20
21     /**
22      * @param document
23      * @param key
24      */
25     public SimpleAttributeWritingStrategy(Document document, String key) {
26         this.document = document;
27         this.key = key;
28     }
29
30     @Override
31     public void writeElement(Element parentElement, String namespace, Object value) {
32         value = preprocess(value);
33         Util.checkType(value, String.class);
34         Element innerNode = createElement(document, key, (String) value);
35         XmlUtil.addNamespaceAttr(innerNode, namespace);
36         parentElement.appendChild(innerNode);
37     }
38
39     protected Element createElement(Document document, String key, String value) {
40         return XmlUtil.createTextElement(document, key, (String) value);
41     }
42
43     protected Object preprocess(Object value) {
44         return value;
45     }
46
47
48 }