if (prefix == null || uri == null) {
throw new IllegalArgumentException("prefix/uri can not be null");
}
if (QName.NS_EMPTY_PREFIX.equals(prefix)
|| QName.NS_DEFAULT_URI.equals(uri)) {
throw new NamespaceException("default namespace is reserved and can not be changed");
}
// special case: xml namespace
if (uri.equals(QName.NS_XML_URI)) {
throw new NamespaceException("xml namespace is reserved and can not be changed.");
}
// special case: prefixes xml*
if (prefix.toLowerCase().startsWith(QName.NS_XML_PREFIX)) {
throw new NamespaceException("reserved prefix: " + prefix);
}
// check if the prefix is a valid XML prefix
if (!XMLChar.isValidNCName(prefix)) {
throw new NamespaceException("invalid prefix: " + prefix);
}
// verify that namespace exists (the following call will
// trigger a NamespaceException if it doesn't)
nsReg.getPrefix(uri);
// check new prefix for collision
if (Arrays.asList(getPrefixes()).contains(prefix)) {
// prefix is already in use
if (getURI(prefix).equals(uri)) {
// redundant mapping, silently ignore
return;
}
throw new NamespaceException("prefix already in use: " + prefix);
}
// check if namespace is already locally mapped
String oldPrefix = (String) uriToPrefix.get(uri);
if (oldPrefix != null) {