in mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/NSUtil.java [29:73]
public static OMNamespace handleNamespace(
AxiomElement context, OMNamespace ns, boolean attr, boolean decl) {
String namespaceURI = ns == null ? "" : ns.getNamespaceURI();
String prefix = ns == null ? "" : ns.getPrefix();
if (namespaceURI.length() == 0) {
if (prefix != null && prefix.length() != 0) {
throw new IllegalArgumentException(
"Cannot bind a prefix to the empty namespace name");
}
if (!attr && decl) {
// Special case: no namespace; we need to generate a namespace declaration only if
// there is a conflicting namespace declaration (i.e. a declaration for the default
// namespace with a non empty URI) is in scope
if (context.getDefaultNamespace() != null) {
context.declareDefaultNamespace("");
}
}
return null;
} else {
if (attr && prefix != null && prefix.length() == 0) {
throw new IllegalArgumentException(
"An attribute with a namespace must be prefixed");
}
boolean addNSDecl = false;
if (context != null && (decl || prefix == null)) {
OMNamespace existingNSDecl = context.findNamespace(namespaceURI, prefix);
if (existingNSDecl == null
|| (prefix != null && !existingNSDecl.getPrefix().equals(prefix))
|| (prefix == null && attr && existingNSDecl.getPrefix().length() == 0)) {
addNSDecl = decl;
} else {
prefix = existingNSDecl.getPrefix();
ns = existingNSDecl;
}
}
if (prefix == null) {
prefix = generatePrefix(namespaceURI);
ns = new OMNamespaceImpl(namespaceURI, prefix);
}
if (addNSDecl) {
context.addNamespaceDeclaration(ns);
}
return ns;
}
}