SimpleNamespaceContext implements NamespaceContext { @Override public Iterator<String> getPrefixes(String namespaceURI) { List<String> result = new ArrayList<String>(); for(Entry<String, String> e : prefix2Namespaces.entrySet()) { if(namespaceURI.equals(e.getValue())) { result.add(e.getKey()); } } return result.iterator(); }  void addNamespace(String prefix, String namespaceURI); @Override String getNamespaceURI(String prefix); @Override String getPrefix(String namespaceURI); @Override Iterator<String> getPrefixes(String namespaceURI);  }
@Test public void testGetPrefixes() throws Exception { Iterator<String> prefixes = context.getPrefixes("A"); assertTrue(prefixes.hasNext()); assertEquals("a", prefixes.next()); assertFalse(prefixes.hasNext()); prefixes = context.getPrefixes("B"); assertTrue(prefixes.hasNext()); assertEquals("b", prefixes.next()); assertTrue(prefixes.hasNext()); assertEquals("c", prefixes.next()); assertFalse(prefixes.hasNext()); }