Example usage for javax.xml.soap SOAPElement getAttributeNode

List of usage examples for javax.xml.soap SOAPElement getAttributeNode

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement getAttributeNode.

Prototype

public Attr getAttributeNode(String name);

Source Link

Document

Retrieves an attribute node by name.

Usage

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

/**
 * add attributes//from  w w  w  .  java 2  s  .  c  o m
 *
 * @param NameCreator nc
 * @param element     SOAPElement which is the target of the new attributes
 * @param reader      XMLStreamReader whose cursor is at START_ELEMENT
 * @throws SOAPException
 */
protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException {
    if (log.isDebugEnabled()) {
        log.debug("addAttributes: Entry");
    }

    // Add the attributes from the reader
    int size = reader.getAttributeCount();
    for (int i = 0; i < size; i++) {
        QName qName = reader.getAttributeName(i);
        String prefix = reader.getAttributePrefix(i);
        String value = reader.getAttributeValue(i);
        Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI());
        element.addAttribute(name, value);

        try {
            if (log.isDebugEnabled()) {
                log.debug("Setting attrType");
            }
            String namespace = qName.getNamespaceURI();
            Attr attr = null; // This is an org.w3c.dom.Attr
            if (namespace == null || namespace.length() == 0) {
                attr = element.getAttributeNode(qName.getLocalPart());
            } else {
                attr = element.getAttributeNodeNS(namespace, qName.getLocalPart());
            }
            if (attr != null) {
                String attrType = reader.getAttributeType(i);
                attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null);
                if (log.isDebugEnabled()) {
                    log.debug("Storing attrType in UserData: " + attrType);
                }
            }
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("An error occured while processing attrType: " + e.getMessage());
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("addAttributes: Exit");
    }
}