2 * Copyright (c) 2015, 2017 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.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
13 import org.opendaylight.controller.config.facade.xml.util.Util;
14 import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
15 import org.opendaylight.controller.config.util.xml.XmlUtil;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
19 public class ObjectNameAttributeWritingStrategy implements AttributeWritingStrategy {
21 private final Document document;
22 private final String key;
24 public ObjectNameAttributeWritingStrategy(final Document document, final String key) {
25 this.document = document;
30 public void writeElement(final Element parentElement, final String namespace, final Object value) {
31 Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
32 Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
34 String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName();
35 String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName();
36 String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace();
38 Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY,
39 XmlMappingConstants.PREFIX, namespaceForType, moduleName);
41 innerNode.appendChild(typeElement);
43 final Element nameElement = XmlUtil.createTextElement(document, XmlMappingConstants.NAME_KEY, refName,
44 Optional.<String>absent());
45 innerNode.appendChild(nameElement);
47 parentElement.appendChild(innerNode);