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;
13 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
14 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.w3c.dom.Document;
18 import com.google.common.base.Preconditions;
19 import org.w3c.dom.Element;
21 public class SimpleIdentityRefAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
23 private static final char QNAME_SEPARATOR = ':';
24 private static final String PREFIX = "prefix";
30 public SimpleIdentityRefAttributeWritingStrategy(Document document, String key) {
34 protected Object preprocess(Object value) {
35 Util.checkType(value, Map.class);
36 Preconditions.checkArgument(((Map)value).size() == 1, "Unexpected number of values in %s, expected 1", value);
37 Object stringValue = ((Map) value).values().iterator().next();
38 Util.checkType(stringValue, String.class);
44 protected Element createElement(Document doc, String key, String value) {
45 QName qName = QName.create(value);
46 String identity = qName.getLocalName();
47 Element element = XmlUtil.createPrefixedTextElement(doc, key, PREFIX, identity);
49 String identityNamespace = qName.getNamespace().toString();
50 XmlUtil.addPrefixedNamespaceAttr(element, PREFIX, identityNamespace);