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
8 package org.opendaylight.netconf.util.xml;
10 import com.google.common.collect.ImmutableMap;
11 import java.util.Collections;
12 import java.util.Iterator;
14 import javax.xml.namespace.NamespaceContext;
16 // http://www.ibm.com/developerworks/library/x-nmspccontext/
17 public class HardcodedNamespaceResolver implements NamespaceContext {
18 private final Map<String/* prefix */, String/* namespace */> prefixesToNamespaces;
20 public HardcodedNamespaceResolver(final String prefix, final String namespace) {
21 this(ImmutableMap.of(prefix, namespace));
24 public HardcodedNamespaceResolver(final Map<String, String> prefixesToNamespaces) {
25 this.prefixesToNamespaces = Collections.unmodifiableMap(prefixesToNamespaces);
29 * Returns the URI for all prefixes needed. Wherever possible it
30 * uses {@code XMLConstants}.
32 * @param prefix prefix
33 * @return uri uniform resource identifier
36 public String getNamespaceURI(final String prefix) {
37 if (prefixesToNamespaces.containsKey(prefix)) {
38 return prefixesToNamespaces.get(prefix);
41 throw new IllegalStateException("Prefix mapping not found for " + prefix);
45 public String getPrefix(final String namespaceURI) {
46 // Not needed in this context.
51 public Iterator<String> getPrefixes(final String namespaceURI) {
52 // Not needed in this context.