* @param seq sequence number of attribute, used for generating distinctive prefixes
* @return the actual allocated name, which may be different.
*/
private int checkProposedPrefix(int nameCode, int seq) throws XPathException {
NamePool namePool = getNamePool();
int nscode = namePool.getNamespaceCode(nameCode);
if (nscode == -1) {
// avoid calling allocate where possible, because it's synchronized
nscode = namePool.allocateNamespaceCode(nameCode);
}
int nsprefix = nscode>>16;
short existingURICode = getURICode((short)nsprefix);
if (existingURICode == -1) {
// prefix has not been declared: declare it now (namespace fixup)
namespace(nscode, 0);
return nameCode;
} else {
if ((nscode & 0xffff) == existingURICode) {
// prefix is already bound to this URI
return nameCode; // all is well
} else {
// conflict: prefix is currently bound to a different URI
String prefix = getSubstitutePrefix(nscode, seq);
int newCode = namePool.allocate(
prefix,
namePool.getURI(nameCode),
namePool.getLocalName(nameCode));
namespace(namePool.allocateNamespaceCode(newCode), 0);
return newCode;
}
}
}