Search in sources :

Example 86 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.

the class SimpleInOutMessageReceiver method invokeBusinessLogic.

public void invokeBusinessLogic(MessageContext inMessageContext, MessageContext outMessageContext) throws AxisFault {
    log.debug("Got The message to the MessageReceiver");
    String soapNamespace = inMessageContext.getEnvelope().getNamespace().getNamespaceURI();
    // creating a soap factory according the the soap namespce uri
    SOAPFactory soapFactory = null;
    if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP11Factory();
    } else if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
        soapFactory = OMAbstractFactory.getSOAP12Factory();
    } else {
        System.out.println("Unknow soap message");
    }
    SOAPEnvelope responseEnvelope = soapFactory.getDefaultEnvelope();
    // creating a body element
    OMFactory omFactory = OMAbstractFactory.getOMFactory();
    OMNamespace omNamespace = omFactory.createOMNamespace("http://sms.test", "ns1");
    OMElement omElement = omFactory.createOMElement("Response", omNamespace);
    omElement.setText("Sucess");
    responseEnvelope.getBody().addChild(omElement);
    outMessageContext.setEnvelope(responseEnvelope);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 87 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class OMFactoryImpl method importChildNode.

private AxiomChildNode importChildNode(OMNode child) {
    int type = child.getType();
    switch(type) {
        case OMNode.ELEMENT_NODE:
            {
                OMElement element = (OMElement) child;
                AxiomElement importedElement = createNode(AxiomElement.class);
                copyName(element, importedElement);
                for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
                    importedElement.coreAppendAttribute(importAttribute(it.next()));
                }
                for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
                    OMNamespace ns = it.next();
                    AxiomNamespaceDeclaration nsDecl = createNode(AxiomNamespaceDeclaration.class);
                    nsDecl.coreSetDeclaredNamespace(ns.getPrefix(), ns.getNamespaceURI());
                    importedElement.coreAppendAttribute(nsDecl);
                }
                importChildren(element, importedElement);
                return importedElement;
            }
        case OMNode.TEXT_NODE:
        case OMNode.SPACE_NODE:
        case OMNode.CDATA_SECTION_NODE:
            {
                OMText text = (OMText) child;
                Object content;
                if (text.isBinary()) {
                    content = new TextContent(text.getContentID(), text.getDataHandler(), text.isOptimized());
                } else {
                    content = text.getText();
                }
                return createAxiomText(null, content, type);
            }
        case OMNode.PI_NODE:
            {
                OMProcessingInstruction pi = (OMProcessingInstruction) child;
                AxiomProcessingInstruction importedPI = createNode(AxiomProcessingInstruction.class);
                importedPI.setTarget(pi.getTarget());
                importedPI.setValue(pi.getValue());
                return importedPI;
            }
        case OMNode.COMMENT_NODE:
            {
                OMComment comment = (OMComment) child;
                AxiomComment importedComment = createNode(AxiomComment.class);
                importedComment.setValue(comment.getValue());
                return importedComment;
            }
        case OMNode.DTD_NODE:
            {
                OMDocType docType = (OMDocType) child;
                AxiomDocType importedDocType = createNode(AxiomDocType.class);
                importedDocType.coreSetRootName(docType.getRootName());
                importedDocType.coreSetPublicId(docType.getPublicId());
                importedDocType.coreSetSystemId(docType.getSystemId());
                importedDocType.coreSetInternalSubset(docType.getInternalSubset());
                return importedDocType;
            }
        case OMNode.ENTITY_REFERENCE_NODE:
            AxiomEntityReference importedEntityRef = createNode(AxiomEntityReference.class);
            importedEntityRef.coreSetName(((OMEntityReference) child).getName());
            return importedEntityRef;
        default:
            throw new IllegalArgumentException("Unsupported node type");
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomDocType(org.apache.axiom.om.impl.intf.AxiomDocType) AxiomProcessingInstruction(org.apache.axiom.om.impl.intf.AxiomProcessingInstruction) AxiomEntityReference(org.apache.axiom.om.impl.intf.AxiomEntityReference) OMElement(org.apache.axiom.om.OMElement) AxiomNamespaceDeclaration(org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMDocType(org.apache.axiom.om.OMDocType) OMComment(org.apache.axiom.om.OMComment) AxiomComment(org.apache.axiom.om.impl.intf.AxiomComment) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) TextContent(org.apache.axiom.om.impl.intf.TextContent)

Example 88 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class OMFactoryImpl method createOMElement.

@Override
public final OMElement createOMElement(QName qname, OMContainer parent) {
    AxiomElement element = createNode(AxiomElement.class);
    if (parent != null) {
        parent.addChild(element);
    }
    element.internalSetLocalName(qname.getLocalPart());
    String prefix = qname.getPrefix();
    String namespaceURI = qname.getNamespaceURI();
    if (namespaceURI.length() > 0) {
        // The goal here is twofold:
        //  * check if the namespace needs to be declared;
        //  * locate an existing OMNamespace object, so that we can avoid creating a new one.
        OMNamespace ns = element.findNamespace(namespaceURI, prefix.length() == 0 ? null : prefix);
        if (ns == null) {
            if ("".equals(prefix)) {
                prefix = generatePrefix(namespaceURI);
            }
            ns = element.declareNamespace(namespaceURI, prefix);
        }
        element.internalSetNamespace(ns);
    } else if (prefix.length() > 0) {
        throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
    } else {
        if (element.getDefaultNamespace() != null) {
            element.declareDefaultNamespace("");
        }
        element.internalSetNamespace(null);
    }
    return element;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement)

Example 89 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class DeferredNamespace method equals.

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof OMNamespace)) {
        return false;
    }
    OMNamespace other = (OMNamespace) obj;
    String otherPrefix = other.getPrefix();
    String thisPrefix = getPrefix();
    return (uri.equals(other.getNamespaceURI()) && (thisPrefix == null ? otherPrefix == null : thisPrefix.equals(otherPrefix)));
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace)

Example 90 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class OMChildrenWithSpecificAttributeIteratorTest method testChildrenRetrievalWithNoDetaching.

public void testChildrenRetrievalWithNoDetaching() {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
    OMElement documentElement = getSampleDocumentElement(testNamespace);
    Iterator childrenIter = new OMChildrenWithSpecificAttributeIterator(documentElement.getFirstOMChild(), new QName(testNamespace.getNamespaceURI(), "myAttr", testNamespace.getPrefix()), "Axis2", false);
    int childCount = getChidrenCount(childrenIter);
    assertEquals("Iterator must return 5 children with the given attribute", childCount, 5);
    Iterator children = documentElement.getChildren();
    childCount = getChidrenCount(children);
    assertEquals("Iterator must return 6 children, having not detached the children", childCount, 6);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

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