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.util.xml;
11 import java.util.Collections;
12 import java.util.Iterator;
15 import javax.xml.namespace.NamespaceContext;
17 import com.google.common.collect.ImmutableMap;
19 // http://www.ibm.com/developerworks/library/x-nmspccontext/
20 public class HardcodedNamespaceResolver implements NamespaceContext {
21 private final Map<String/* prefix */, String/* namespace */> prefixesToNamespaces;
23 public HardcodedNamespaceResolver(String prefix, String namespace) {
24 this(ImmutableMap.of(prefix, namespace));
27 public HardcodedNamespaceResolver(Map<String, String> prefixesToNamespaces) {
28 this.prefixesToNamespaces = Collections.unmodifiableMap(prefixesToNamespaces);
32 * This method returns the uri for all prefixes needed. Wherever possible it
39 public String getNamespaceURI(String prefix) {
40 if (prefixesToNamespaces.containsKey(prefix)) {
41 return prefixesToNamespaces.get(prefix);
43 throw new IllegalStateException("Prefix mapping not found for " + prefix);
48 public String getPrefix(String namespaceURI) {
49 // Not needed in this context.
54 public Iterator<?> getPrefixes(String namespaceURI) {
55 // Not needed in this context.