AccessDeniedException, RepositoryException {
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");
}
if (reservedURIs.contains(uri)) {
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri + ": reserved URI");
}
if (reservedPrefixes.contains(prefix)) {
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri + ": reserved prefix");
}
// special case: prefixes xml*
if (prefix.toLowerCase().startsWith(QName.NS_XML_PREFIX)) {
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri + ": reserved prefix");
}
// check if the prefix is a valid XML prefix
if (!XMLChar.isValidNCName(prefix)) {
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri + ": invalid prefix");
}
// check existing mappings
String oldPrefix = (String) uriToPrefix.get(uri);
if (prefix.equals(oldPrefix)) {
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri + ": mapping already exists");
}
if (prefixToURI.containsKey(prefix)) {
/**
* prevent remapping of existing prefixes because this would in effect
* remove the previously assigned namespace;
* as we can't guarantee that there are no references to this namespace
* (in names of nodes/properties/node types etc.) we simply don't allow it.
*/
throw new NamespaceException("failed to register namespace "
+ prefix + " -> " + uri
+ ": remapping existing prefixes is not supported.");
}
if (oldPrefix != null) {