Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / toxml / SimpleAttributeWritingStrategy.java
1 /*
2  * Copyright (c) 2015, 2017 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 org.opendaylight.controller.config.facade.xml.util.Util;
13 import org.opendaylight.controller.config.util.xml.XmlUtil;
14 import org.w3c.dom.Document;
15 import org.w3c.dom.Element;
16
17 public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy {
18
19     private final Document document;
20     private final String key;
21
22     public SimpleAttributeWritingStrategy(final Document document, final String key) {
23         this.document = document;
24         this.key = key;
25     }
26
27     @Override
28     public void writeElement(final Element parentElement, final String namespace, Object value) {
29         value = preprocess(value);
30         Util.checkType(value, String.class);
31         Element innerNode = createElement(document, key, (String) value, Optional.of(namespace));
32         parentElement.appendChild(innerNode);
33     }
34
35     @SuppressWarnings("checkstyle:hiddenField")
36     protected Element createElement(final Document document, final String key, final String value,
37             final Optional<String> namespace) {
38         Element typeElement = XmlUtil.createElement(document, key, namespace);
39
40         typeElement.appendChild(document.createTextNode(value));
41         return typeElement;
42     }
43
44     protected Object preprocess(final Object value) {
45         return value;
46     }
47 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.