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
8 package org.opendaylight.yangtools.yang.data.jaxen;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Converter;
13 import javax.annotation.Nonnull;
14 import org.jaxen.NamespaceContext;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
18 final class ConverterNamespaceContext extends Converter<String, QNameModule> implements NamespaceContext {
19 private final Converter<String, QNameModule> delegate;
21 ConverterNamespaceContext(final Converter<String, QNameModule> converter) {
22 this.delegate = requireNonNull(converter);
26 @SuppressWarnings("checkstyle:parameterName")
27 protected QNameModule doForward(@Nonnull final String a) {
28 return delegate.convert(a);
32 @SuppressWarnings("checkstyle:parameterName")
33 protected String doBackward(@Nonnull final QNameModule b) {
34 return delegate.reverse().convert(b);
38 public String translateNamespacePrefixToUri(final String prefix) {
39 return convert(prefix).getNamespace().toString();
42 String jaxenQName(final QName qname) {
43 return reverse().convert(qname.getModule()) + ':' + qname.getLocalName();