ElementImpl extends NodeImpl implements Element { public void setNamespacePrefixMapping(Map<String, String> namespace2Prefix) { Assert.notNull(namespace2Prefix, "namespace2Prefix"); HashSet<String> prefixes = new HashSet<String>(); for (Map.Entry<String, String> entry : namespace2Prefix.entrySet()) { String namespace = entry.getKey(); String prefix = entry.getValue(); if (namespace == null) { throw new NullPointerException( "Map 'namespace2Prefix' must not contain a null key"); } if (prefix == null) { throw new NullPointerException( "Map 'namespace2Prefix' must not contain null values"); } if (prefixes.contains(prefix)) { String msg = MessageFormat .format( "Map ''namespace2Prefix'' contains the prefix ''{0}'' twice", prefix); throw new IllegalArgumentException(msg); } prefixes.add(prefix); } this.namespace2Prefix = new TreeMap<String, String>(namespace2Prefix); for (Map.Entry<String, String> entry : namespace2Prefix.entrySet()) { this.prefix2Namespace.put(entry.getValue(), entry.getKey()); } } protected  ElementImpl(String namespaceUri, String prefix, String name); protected  ElementImpl(String namespaceUri, String name,
			org.w3c.dom.Element xmlElement); String getNamespaceUri(); String getPrefix(); String getName(); Map<String, String> getNamespacePrefixMapping(); void setNamespacePrefixMapping(Map<String, String> namespace2Prefix); Collection<? extends Attribute> getAttributes(); abstract List<? extends Node> getChildren(); org.w3c.dom.Element asXmlNode(Document document); Object clone(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testNamespacePrefixMapping() { ConcreteElementImpl elem = new ConcreteElementImpl("ns", null, "name"); HashMap<String, String> mapping = new HashMap<String, String>(); mapping.put("abcns", "abc"); mapping.put("ns", ""); elem.setNamespacePrefixMapping(mapping); mapping.put("ijk", null); try { elem.setNamespacePrefixMapping(mapping); fail("Expected NullPointerException"); } catch (NullPointerException e) { mapping.remove("ijk"); } mapping.put(null, "ijk"); try { elem.setNamespacePrefixMapping(mapping); fail("Expected NullPointerException"); } catch (NullPointerException e) { mapping.remove(null); } mapping.put("abc2ns", "abc"); try { elem.setNamespacePrefixMapping(mapping); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { mapping.remove("abc2ns"); } }