Search in sources :

Example 21 with OMNamespace

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());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace)

Example 22 with OMNamespace

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;
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace)

Example 23 with OMNamespace

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();
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) NoSuchElementException(java.util.NoSuchElementException)

Example 24 with OMNamespace

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)));
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace)

Example 25 with OMNamespace

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);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)171 OMElement (org.apache.axiom.om.OMElement)108 OMFactory (org.apache.axiom.om.OMFactory)101 QName (javax.xml.namespace.QName)34 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)22 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4