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 com.google.common.collect.ImmutableMap;
12 import java.util.Collections;
13 import java.util.Iterator;
15 import javax.xml.namespace.NamespaceContext;
17 // http://www.ibm.com/developerworks/library/x-nmspccontext/
18 public class HardcodedNamespaceResolver implements NamespaceContext {
19 private final Map<String/* prefix */, String/* namespace */> prefixesToNamespaces;
21 public HardcodedNamespaceResolver(String prefix, String namespace) {
22 this(ImmutableMap.of(prefix, namespace));
25 public HardcodedNamespaceResolver(Map<String, String> prefixesToNamespaces) {
26 this.prefixesToNamespaces = Collections.unmodifiableMap(prefixesToNamespaces);
30 * This method returns the uri for all prefixes needed. Wherever possible it
37 public String getNamespaceURI(String prefix) {
38 if (prefixesToNamespaces.containsKey(prefix)) {
39 return prefixesToNamespaces.get(prefix);
41 throw new IllegalStateException("Prefix mapping not found for " + prefix);
46 public String getPrefix(String namespaceURI) {
47 // Not needed in this context.
52 public Iterator<?> getPrefixes(String namespaceURI) {
53 // Not needed in this context.