Example usage for javax.xml.soap SOAPFactory createName

List of usage examples for javax.xml.soap SOAPFactory createName

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFactory createName.

Prototype

public abstract Name createName(String localName) throws SOAPException;

Source Link

Document

Creates a new Name object initialized with the given local name.

Usage

From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java

private SOAPElement getSOAPElement(SOAPBody soapBody, Element elem) {
    String xmlns = IRegistry.UDDI_V2_NAMESPACE;
    SOAPElement soapElement = null;
    SOAPFactory factory = null;
    try {/*from w ww .j av  a 2s  .com*/
        factory = SOAPFactory.newInstance();
        //Go through the element
        String name = elem.getNodeName();
        String nsuri = elem.getNamespaceURI();
        if (nsuri == null)
            nsuri = xmlns;
        soapElement = factory.createElement(name, "ns1", nsuri);
        //Get Attributes
        if (elem.hasAttributes()) {
            NamedNodeMap nnm = elem.getAttributes();
            int len = nnm != null ? nnm.getLength() : 0;
            for (int i = 0; i < len; i++) {
                Node n = nnm.item(i);
                String nodename = n.getNodeName();
                String nodevalue = n.getNodeValue();
                soapElement.addAttribute(factory.createName(nodename), nodevalue);
            }
        } else {
            soapElement.addAttribute(factory.createName("xmlns:ns1"), nsuri);
        }

        NodeList nlist = elem.getChildNodes();
        int len = nlist != null ? nlist.getLength() : 0;

        for (int i = 0; i < len; i++) {
            Node node = nlist.item(i);
            short nodeType = node != null ? node.getNodeType() : -100;
            if (Node.ELEMENT_NODE == nodeType) {
                soapElement.addChildElement(getSOAPElement(soapBody, (Element) node));
            } else if (nodeType == Node.TEXT_NODE) {
                soapElement.addTextNode(node.getNodeValue());
            }

        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return soapElement;
}