2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml;
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;
17 public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy {
19 private final Document document;
20 private final String key;
26 public SimpleAttributeWritingStrategy(Document document, String key) {
27 this.document = document;
32 public void writeElement(Element parentElement, String namespace, Object value) {
33 value = preprocess(value);
34 Util.checkType(value, String.class);
35 Element innerNode = createElement(document, key, (String) value, Optional.of(namespace));
36 parentElement.appendChild(innerNode);
39 protected Element createElement(Document document, String key, String value, Optional<String> namespace) {
40 Element typeElement = XmlUtil.createElement(document, key, namespace);
42 typeElement.appendChild(document.createTextNode(value));
45 protected Object preprocess(Object value) {