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 com.google.common.base.Preconditions;
14 import org.opendaylight.controller.config.facade.xml.util.Util;
15 import org.opendaylight.controller.config.util.xml.XmlUtil;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
20 public class SimpleIdentityRefAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
22 private static final String PREFIX = "prefix";
24 public SimpleIdentityRefAttributeWritingStrategy(final Document document, final String key) {
29 protected Object preprocess(final Object value) {
30 Util.checkType(value, Map.class);
31 Preconditions.checkArgument(((Map<?, ?>) value).size() == 1, "Unexpected number of values in %s, expected 1",
33 Object stringValue = ((Map<?, ?>) value).values().iterator().next();
34 Util.checkType(stringValue, String.class);
40 protected Element createElement(final Document doc, final String key, final String value,
41 final Optional<String> namespace) {
42 QName qualifiedName = QName.create(value);
43 String identityValue = qualifiedName.getLocalName();
44 String identityNamespace = qualifiedName.getNamespace().toString();
45 return XmlUtil.createTextElementWithNamespacedContent(doc, key, PREFIX, identityNamespace, identityValue,