Example usage for javax.xml.soap SOAPElement getAttributeValue

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

Introduction

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

Prototype

public String getAttributeValue(QName qname);

Source Link

Document

Returns the value of the attribute with the specified qname.

Usage

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test that {@link SOAPElement#getAttributeValue(Name)} returns <code>null</code> if the
 * requested attribute doesn't exist.//from   w  w  w. java2 s .c  o  m
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByNameNonExisting() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement("test", "p", "urn:test");
    assertNull(element.getAttributeValue(envelope.createName("attr")));
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test that {@link SOAPElement#getAttributeValue(QName)} returns <code>null</code> if the
 * requested attribute doesn't exist.//from   w w  w  . j  av  a  2 s  .  co  m
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByQNameNonExisting() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p");
    assertNull(element.getAttributeValue(new QName("attr")));
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void handleHierInfo(JRXmlaResultAxis axis, SOAPElement hierInfoElement) throws SOAPException {
    Name name = sf.createName("name");
    String dimName = hierInfoElement.getAttributeValue(name); // Get the Dimension Name

    if (log.isDebugEnabled()) {
        log.debug("Adding hierarchy: " + dimName);
    }/*from  w  w  w .j a  v  a 2  s  . c o  m*/

    JRXmlaHierarchy hier = new JRXmlaHierarchy(dimName);
    axis.addHierarchy(hier);
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void parseAxesElement(SOAPElement axesElement) throws SOAPException {
    // Cycle over Axis-Elements
    Name aName = sf.createName("Axis", "", MDD_URI);
    Iterator<?> itAxis = axesElement.getChildElements(aName);
    while (itAxis.hasNext()) {
        SOAPElement axisElement = (SOAPElement) itAxis.next();
        Name name = sf.createName("name");
        String axisName = axisElement.getAttributeValue(name);

        if (axisName.equals(SLICER_AXIS_NAME)) {
            continue;
        }/*from w  w w .ja v  a 2 s .  c o m*/

        // LookUp for the Axis
        JRXmlaResultAxis axis = xmlaResult.getAxisByName(axisName);

        // retrieve the tuples by <Tuples>
        name = sf.createName("Tuples", "", MDD_URI);
        Iterator<?> itTuples = axisElement.getChildElements(name);
        if (itTuples.hasNext()) {
            SOAPElement eTuples = (SOAPElement) itTuples.next();
            handleTuplesElement(axis, eTuples);
        }
    }
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void parseAxesInfoElement(SOAPElement axesInfoElement) throws SOAPException {
    // Cycle over AxisInfo-Elements
    Name axisInfoName = sf.createName("AxisInfo", "", MDD_URI);
    Iterator<?> itAxis = axesInfoElement.getChildElements(axisInfoName);
    while (itAxis.hasNext()) {
        SOAPElement axisElement = (SOAPElement) itAxis.next();
        Name name = sf.createName("name");
        String axisName = axisElement.getAttributeValue(name);
        if (axisName.equals(SLICER_AXIS_NAME)) {
            continue;
        }/*from   ww  w .  j a  va 2s .c om*/

        JRXmlaResultAxis axis = new JRXmlaResultAxis(axisName);
        xmlaResult.addAxis(axis);

        if (log.isDebugEnabled()) {
            log.debug("adding axis: " + axis.getAxisName());
        }

        // retrieve the hierarchies by <HierarchyInfo>
        name = sf.createName("HierarchyInfo", "", MDD_URI);
        Iterator<?> itHierInfo = axisElement.getChildElements(name);
        while (itHierInfo.hasNext()) {
            SOAPElement eHierInfo = (SOAPElement) itHierInfo.next();
            handleHierInfo(axis, eHierInfo);
        }
    }
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test the behavior of {@link SOAPElement#getAttributeValue(Name)} for an attribute without
 * namespace.//from  w  ww . j  av  a  2  s . c  o  m
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByNameWithoutNamespace() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement("test", "p", "urn:test");
    element.setAttributeNS(null, "attr", "value");
    assertEquals("value", element.getAttributeValue(envelope.createName("attr")));
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test the behavior of {@link SOAPElement#getAttributeValue(QName)} for an attribute without
 * namespace./*w  ww .  j a v  a 2 s.  co m*/
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByQNameWithoutNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p");
    element.setAttributeNS(null, "attr", "value");
    assertEquals("value", element.getAttributeValue(new QName("attr")));
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test the behavior of {@link SOAPElement#getAttributeValue(Name)} for an attribute with
 * namespace. In particular, check that the prefix is not considered when matching attribute
 * names.//ww  w  .  j  a  v  a2 s.c om
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByNameWithNamespace() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement("test", "p", "urn:test");
    element.setAttributeNS("urn:test", "p:attr", "value");
    assertEquals("value", element.getAttributeValue(envelope.createName("attr", "", "urn:test")));
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test the behavior of {@link SOAPElement#getAttributeValue(QName)} for an attribute with
 * namespace. In particular, check that the prefix is not considered when matching attribute
 * names.//from  www.  j ava  2s . com
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByQNameWithNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p");
    element.setAttributeNS("urn:test", "p:attr", "value");
    assertEquals("value", element.getAttributeValue(new QName("urn:test", "attr", "")));
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void handleTupleElement(JRXmlaResultAxis axis, SOAPElement tupleElement) throws SOAPException {
    JRXmlaMemberTuple tuple = new JRXmlaMemberTuple(axis.getHierarchiesOnAxis().length);

    Name memName = sf.createName("Member", "", MDD_URI);
    Iterator<?> itMember = tupleElement.getChildElements(memName);
    int memNum = 0;
    while (itMember.hasNext()) {
        SOAPElement memElement = (SOAPElement) itMember.next();

        Name name = sf.createName("Hierarchy", "", "");
        String hierName = memElement.getAttributeValue(name);

        String uName = "";
        Iterator<?> uNameElements = memElement.getChildElements(sf.createName("UName", "", MDD_URI));
        if (uNameElements.hasNext()) {
            uName = ((SOAPElement) uNameElements.next()).getValue();
        }/*from ww  w.  j  a v  a  2s .  c  o m*/
        String caption = "";
        Iterator<?> captionElements = memElement.getChildElements(sf.createName("Caption", "", MDD_URI));
        if (captionElements.hasNext()) {
            caption = ((SOAPElement) captionElements.next()).getValue();
        }
        String lName = "";
        Iterator<?> lNameElements = memElement.getChildElements(sf.createName("LName", "", MDD_URI));
        if (lNameElements.hasNext()) {
            String levelUniqueName = ((SOAPElement) lNameElements.next()).getValue();
            Matcher matcher = LEVEL_UNIQUE_NAME_PATTERN.matcher(levelUniqueName);
            if (matcher.matches()) {
                lName = matcher.group(LEVEL_UNIQUE_NAME_PATTERN_NAME_GROUP);
            } else {
                matcher = HIERARCHY_LEVEL_UNIQUE_NAME_PATTERN.matcher(levelUniqueName);
                if (matcher.matches()) {
                    lName = matcher.group(HIERARCHY_LEVEL_UNIQUE_NAME_PATTERN_NAME_GROUP);
                } else {
                    throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NO_LEVEL_NAME,
                            new Object[] { levelUniqueName });
                }
            }
        }

        int lNum = 0;
        Iterator<?> lNumElements = memElement.getChildElements(sf.createName("LNum", "", MDD_URI));
        if (lNumElements.hasNext()) {
            lNum = Integer.parseInt(((SOAPElement) lNumElements.next()).getValue());
        }
        JRXmlaMember member = new JRXmlaMember(caption, uName, hierName, lName, lNum);

        if (log.isDebugEnabled()) {
            log.debug("Adding member: axis - " + axis.getAxisName() + " hierName - " + hierName + " lName - "
                    + lName + " uName - " + uName);
        }
        tuple.setMember(memNum++, member);
    }

    axis.addTuple(tuple);
}