use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class WriteNamespaceScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
OMNamespace decl = null;
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
while (it.hasNext()) {
OMNamespace ns = it.next();
if (!ns.getPrefix().equals("_p_")) {
if (decl != null) {
Assert.fail("Found unexpected namespace declaration");
} else {
decl = ns;
}
}
}
Assert.assertNotNull(decl);
Assert.assertEquals(prefix, decl.getPrefix());
Assert.assertEquals(namespaceURI, decl.getNamespaceURI());
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class NSUtil method handleNamespace.
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) {
// 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;
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class NamespaceIterator method next.
@Override
public OMNamespace next() {
if (hasNext()) {
OMNamespace result = next;
hasNextCalled = false;
next = null;
return result;
} else {
throw new NoSuchElementException();
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class OMNamespaceImpl method equals.
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OMNamespace))
return false;
OMNamespace other = (OMNamespace) obj;
String otherPrefix = other.getPrefix();
return (uri.equals(other.getNamespaceURI()) && (prefix == null ? otherPrefix == null : prefix.equals(otherPrefix)));
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class SAXResultContentHandler method processAttribute.
@Override
public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
OMElement element = (OMElement) target;
OMNamespace ns;
if (namespaceURI.length() > 0) {
ns = element.findNamespace(namespaceURI, prefix);
if (ns == null) {
throw new OMException("Unbound namespace " + namespaceURI);
}
} else {
ns = null;
}
OMAttribute attr = element.addAttribute(localName, value, ns);
attr.setAttributeType(type);
}
Aggregations