Worldwind public release 0.2.1
[worldwind-tracker.git] / gov / nasa / worldwind / wms / SimpleNamespaceContext.java
blobeac83336fea264ed0d04c16047e8c9c0594ab568
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.wms;
9 import javax.xml.namespace.*;
10 import javax.xml.*;
11 import java.util.*;
13 /**
14 * @author Java & XML 3e
15 * @version $Id: SimpleNamespaceContext.java 1982 2007-06-09 00:27:13Z tgaskins $
17 public class SimpleNamespaceContext implements NamespaceContext
20 private Map<String, String> urisByPrefix = new HashMap<String, String>();
21 private Map<String, Set<String>> prefixesByURI = new HashMap<String, Set<String>>();
23 public SimpleNamespaceContext()
25 // prepopulate with xml and xmlns prefixes
26 // per JavaDoc of NamespaceContext interface
27 addNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
28 addNamespace(XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
29 addNamespace("xlink", "http://www.w3.org/1999/xlink");
30 addNamespace("wms", "http://www.opengis.net/wms");
31 addNamespace(XMLConstants.DEFAULT_NS_PREFIX, "http://www.opengis.net/wms");
34 public synchronized void addNamespace(String prefix, String namespaceURI)
36 urisByPrefix.put(prefix, namespaceURI);
37 if (prefixesByURI.containsKey(namespaceURI))
39 (prefixesByURI.get(namespaceURI)).add(prefix);
41 else
43 Set<String> set = new HashSet<String>();
44 set.add(prefix);
45 prefixesByURI.put(namespaceURI, set);
49 public String getNamespaceURI(String prefix)
51 if (prefix == null)
52 throw new IllegalArgumentException("prefix cannot be null");
53 if (urisByPrefix.containsKey(prefix))
54 return urisByPrefix.get(prefix);
55 else
56 return XMLConstants.NULL_NS_URI;
59 public String getPrefix(String namespaceURI)
61 return (String) getPrefixes(namespaceURI).next();
64 public Iterator getPrefixes(String namespaceURI)
66 if (namespaceURI == null)
67 throw new IllegalArgumentException("namespaceURI cannot be null");
68 if (prefixesByURI.containsKey(namespaceURI))
70 return (prefixesByURI.get(namespaceURI)).iterator();
72 else
74 return Collections.EMPTY_SET.iterator();