2 * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.attributes.toxml;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
14 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
15 import org.opendaylight.controller.netconf.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;
28 public ObjectNameAttributeWritingStrategy(Document document, String key) {
29 this.document = document;
34 public void writeElement(Element parentElement, String namespace, Object value) {
35 Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
36 Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
38 String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName();
39 String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName();
40 String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace();
42 Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY, XmlNetconfConstants.PREFIX,
43 namespaceForType, moduleName);
45 innerNode.appendChild(typeElement);
47 final Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, refName, Optional.<String>absent());
48 innerNode.appendChild(nameElement);
50 parentElement.appendChild(innerNode);