in mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreElementMixin.java [191:235]
public final String coreLookupPrefix(String namespaceURI, Semantics semantics)
throws CoreModelException {
if (namespaceURI == null) {
throw new IllegalArgumentException("namespaceURI must not be null");
}
if (!semantics.isUseStrictNamespaceLookup()) {
String prefix = getImplicitPrefix(namespaceURI);
if (prefix != null) {
return prefix;
}
}
for (CoreAttribute attr = coreGetFirstAttribute();
attr != null;
attr = attr.coreGetNextAttribute()) {
if (attr instanceof CoreNamespaceDeclaration) {
CoreNamespaceDeclaration decl = (CoreNamespaceDeclaration) attr;
if (decl.coreGetCharacterData().toString().equals(namespaceURI)) {
return decl.coreGetDeclaredPrefix();
}
}
}
CoreElement parentElement = coreGetParentElement();
if (parentElement != null) {
String prefix = parentElement.coreLookupPrefix(namespaceURI, semantics);
// The prefix declared on one of the ancestors may be masked by another
// namespace declaration on this element (or one of its descendants).
if (!semantics.isUseStrictNamespaceLookup()
&& getImplicitNamespaceURI(prefix) != null) {
return null;
}
for (CoreAttribute attr = coreGetFirstAttribute();
attr != null;
attr = attr.coreGetNextAttribute()) {
if (attr instanceof CoreNamespaceDeclaration) {
CoreNamespaceDeclaration decl = (CoreNamespaceDeclaration) attr;
if (decl.coreGetDeclaredPrefix().equals(prefix)) {
return null;
}
}
}
return prefix;
} else {
return null;
}
}