Example usage for javax.xml.soap SOAPElement getChildElements

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

Introduction

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

Prototype

public Iterator<Node> getChildElements(QName qname);

Source Link

Document

Returns an Iterator over all the immediate child Node s of this element with the specified qname.

Usage

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException {
    Name name = sf.createName("Cell", "", MDD_URI);
    Iterator itCells = cellDataElement.getChildElements(name);
    while (itCells.hasNext()) {
        SOAPElement cellElement = (SOAPElement) itCells.next();

        Name errorName = sf.createName("Error", "", MDD_URI);
        Iterator errorElems = cellElement.getChildElements(errorName);
        if (errorElems.hasNext()) {
            handleCellErrors(errorElems);
        }/*from  w  w w.jav a2s .  c o m*/

        Name ordinalName = sf.createName("CellOrdinal");
        String cellOrdinal = cellElement.getAttributeValue(ordinalName);

        Object value = null;
        Iterator valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
        if (valueElements.hasNext()) {
            SOAPElement valueElement = (SOAPElement) valueElements.next();
            String valueType = valueElement.getAttribute("xsi:type");
            if (valueType.equals("xsd:int"))
                value = new Long(valueElement.getValue());
            else if (valueType.equals("xsd:double"))
                value = new Double(valueElement.getValue());
            else if (valueType.equals("xsd:decimal"))
                value = new Double(valueElement.getValue());
            else
                value = valueElement.getValue();
        }

        String fmtValue = "";
        Iterator fmtValueElements = cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
        if (fmtValueElements.hasNext()) {
            SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
            fmtValue = fmtValueElement.getValue();
        }

        int pos = Integer.parseInt(cellOrdinal);
        JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
        ((JRXmlaResult) xmlaResult).setCell(cell, pos);
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.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;
        }/*w ww  .  ja  va2  s. c  o m*/

        // LookUp for the Axis
        JRXmlaResultAxis axis = ((JRXmlaResult) 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:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.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   www. j  a v  a 2 s.c om

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

        // 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.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void handleCellErrors(Iterator errorElems) throws SOAPException {
    SOAPElement errorElem = (SOAPElement) errorElems.next();

    StringBuffer errorMsg = new StringBuffer();
    errorMsg.append("Cell error: ");

    Iterator descriptionElems = errorElem.getChildElements(sf.createName("Description", "", MDD_URI));
    if (descriptionElems.hasNext()) {
        SOAPElement descrElem = (SOAPElement) descriptionElems.next();
        errorMsg.append(descrElem.getValue());
        errorMsg.append("; ");
    }/*  ww  w . j ava 2  s . c o  m*/

    Iterator sourceElems = errorElem.getChildElements(sf.createName("Source", "", MDD_URI));
    if (sourceElems.hasNext()) {
        SOAPElement sourceElem = (SOAPElement) sourceElems.next();
        errorMsg.append("Source: ");
        errorMsg.append(sourceElem.getValue());
        errorMsg.append("; ");
    }

    Iterator codeElems = errorElem.getChildElements(sf.createName("ErrorCode", "", MDD_URI));
    if (codeElems.hasNext()) {
        SOAPElement codeElem = (SOAPElement) codeElems.next();
        errorMsg.append("Code: ");
        errorMsg.append(codeElem.getValue());
        errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
}

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

@Validated
@Test//from ww w. ja v a  2s .  c o m
public void testGetChildElementsByQName() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement a1 = element.addChildElement(new QName("urn:ns1", "a"));
    element.addChildElement(new QName("urn:ns2", "a"));
    SOAPElement a2 = element.addChildElement(new QName("urn:ns1", "a", "ns1"));
    element.addChildElement(new QName("urn:ns1", "b"));
    Iterator it = element.getChildElements(new QName("urn:ns1", "a"));
    assertTrue(it.hasNext());
    assertSame(a1, it.next());
    assertTrue(it.hasNext());
    assertSame(a2, it.next());
    assertFalse(it.hasNext());
}

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

@Validated
@Test/*  w ww  . j  av a  2s . c  o m*/
public void testGetChildElementsByName() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement a1 = element.addChildElement(new QName("urn:ns1", "a"));
    element.addChildElement(new QName("urn:ns2", "a"));
    SOAPElement a2 = element.addChildElement(new QName("urn:ns1", "a", "ns1"));
    element.addChildElement(new QName("urn:ns1", "b"));
    Iterator it = element.getChildElements(a1.getElementName());
    assertTrue(it.hasNext());
    assertSame(a1, it.next());
    assertTrue(it.hasNext());
    assertSame(a2, it.next());
    assertFalse(it.hasNext());
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.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();

        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);
            }/*from w w w. j av a2 s  .  c  om*/
        }

        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);
        tuple.setMember(memNum++, member);
    }

    axis.addTuple(tuple);
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void parseOLAPInfoElement(SOAPElement olapInfoElement) throws SOAPException {
    // CubeInfo-Element is not needed

    // Get the AxesInfo-Node
    Name axesInfoName = sf.createName("AxesInfo", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator axesInfoElements = olapInfoElement.getChildElements(axesInfoName);
    if (axesInfoElements.hasNext()) {
        Object axesObj = axesInfoElements.next();
        if (axesObj == null) {
            log.error("AxisInfo Element is null.");
            throw new JRRuntimeException("AxisInfo Element is null.");
        }/*  ww  w. j  a  va2 s  .  c o  m*/
        axesElement = (SOAPElement) axesObj;
    } else {
        log.error("Could not retrieve AxesInfo Element.");
        throw new JRRuntimeException("Could not retrieve AxesInfo Element.");
    }

    parseAxesInfoElement(axesElement);

    // CellInfo is not needed
}

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

/**
 * Parses the result-Message into this class's structure
 * /*from w  w w  .j a v  a 2 s  .  c om*/
 * @param reply
 *            The reply-Message from the Server
 */
protected void parseResult(SOAPMessage reply) throws SOAPException {
    SOAPPart soapPart = reply.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();
    SOAPElement eElement = null;

    if (log.isDebugEnabled()) {
        log.debug("XML/A result envelope: " + prettyPrintSOAP(soapEnvelope));
    }

    SOAPFault fault = soapBody.getFault();
    if (fault != null) {
        handleResultFault(fault);
    }

    Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI);

    // Get the ExecuteResponse-Node
    Iterator<?> responseElements = soapBody.getChildElements(eName);
    if (responseElements.hasNext()) {
        Object eObj = responseElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT,
                    new Object[] { "ExecuteResponse" });
        }
        eElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "ExecuteResponse" });
    }

    // Get the return-Node
    Name rName = soapEnvelope.createName("return", "", XMLA_URI);
    Iterator<?> returnElements = eElement.getChildElements(rName);
    SOAPElement returnElement = null;
    if (returnElements.hasNext()) {
        Object eObj = returnElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" });
        }
        returnElement = (SOAPElement) eObj;
    } else {
        // Should be old-Microsoft XMLA-SDK. Try without m-prefix
        Name rName2 = soapEnvelope.createName("return", "", "");
        returnElements = eElement.getChildElements(rName2);
        if (returnElements.hasNext()) {
            Object eObj = returnElements.next();
            if (eObj == null) {
                throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT,
                        new Object[] { "return" });
            }
            returnElement = (SOAPElement) eObj;
        } else {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                    new Object[] { "return" });
        }
    }

    // Get the root-Node
    Name rootName = soapEnvelope.createName("root", "", MDD_URI);
    SOAPElement rootElement = null;
    Iterator<?> rootElements = returnElement.getChildElements(rootName);
    if (rootElements.hasNext()) {
        Object eObj = rootElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "root" });
        }
        rootElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "root" });
    }
    // Get the OlapInfo-Node
    Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI);
    SOAPElement olapInfoElement = null;
    Iterator<?> olapInfoElements = rootElement.getChildElements(olapInfoName);
    if (olapInfoElements.hasNext()) {
        Object eObj = olapInfoElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "OlapInfo" });
        }
        olapInfoElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "OlapInfo" });
    }

    parseOLAPInfoElement(olapInfoElement);

    // Get the Axes Element
    Name axesName = soapEnvelope.createName("Axes", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator<?> axesElements = rootElement.getChildElements(axesName);
    if (axesElements.hasNext()) {
        Object eObj = axesElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "Axes" });
        }
        axesElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "Axes" });
    }

    parseAxesElement(axesElement);

    // Get the CellData Element
    Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI);
    SOAPElement cellDataElement = null;
    Iterator<?> cellDataElements = rootElement.getChildElements(cellDataName);
    if (cellDataElements.hasNext()) {
        Object eObj = cellDataElements.next();
        if (eObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "CellData" });
        }
        cellDataElement = (SOAPElement) eObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "CellData" });
    }
    parseCellDataElement(cellDataElement);
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

/**
 * Parses the result-Message into this class's structure
 *
 * @param reply/*from w ww  . j  a  v a 2  s .c o  m*/
 *            The reply-Message from the Server
 */
protected void parseResult(SOAPMessage reply) throws SOAPException, JRRuntimeException {
    SOAPPart soapPart = reply.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();
    SOAPElement eElement = null;

    if (log.isDebugEnabled()) {
        log.debug("XML/A result envelope: " + soapEnvelope.toString());
    }

    SOAPFault fault = soapBody.getFault();
    if (fault != null) {
        handleResultFault(fault);
    }

    Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI);

    // Get the ExecuteResponse-Node
    Iterator responseElements = soapBody.getChildElements(eName);
    if (responseElements.hasNext()) {
        Object eObj = responseElements.next();
        if (eObj == null) {
            log.error("ExecuteResponse Element is null.");
            throw new JRRuntimeException("ExecuteResponse Element is null.");
        }
        eElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve ExecuteResponse Element.");
        throw new JRRuntimeException("Could not retrieve ExecuteResponse Element.");
    }

    // Get the return-Node
    Name rName = soapEnvelope.createName("return", "", XMLA_URI);
    Iterator returnElements = eElement.getChildElements(rName);
    SOAPElement returnElement = null;
    if (returnElements.hasNext()) {
        Object eObj = returnElements.next();
        if (eObj == null) {
            log.error("return Element is null.");
            throw new JRRuntimeException("return Element is null.");
        }
        returnElement = (SOAPElement) eObj;
    } else {
        // Should be old-Microsoft XMLA-SDK. Try without m-prefix
        Name rName2 = soapEnvelope.createName("return", "", "");
        returnElements = eElement.getChildElements(rName2);
        if (returnElements.hasNext()) {
            Object eObj = returnElements.next();
            if (eObj == null) {
                log.error("return Element is null.");
                throw new JRRuntimeException("return Element is null.");
            }
            returnElement = (SOAPElement) eObj;
        } else {
            log.error("Could not retrieve return Element.");
            throw new JRRuntimeException("Could not retrieve return Element.");
        }
    }

    // Get the root-Node
    Name rootName = soapEnvelope.createName("root", "", MDD_URI);
    SOAPElement rootElement = null;
    Iterator rootElements = returnElement.getChildElements(rootName);
    if (rootElements.hasNext()) {
        Object eObj = rootElements.next();
        if (eObj == null) {
            log.error("root Element is null.");
            throw new JRRuntimeException("root Element is null.");
        }
        rootElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve root Element.");
        throw new JRRuntimeException("Could not retrieve root Element.");
    }
    // Get the OlapInfo-Node
    Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI);
    SOAPElement olapInfoElement = null;
    Iterator olapInfoElements = rootElement.getChildElements(olapInfoName);
    if (olapInfoElements.hasNext()) {
        Object eObj = olapInfoElements.next();
        if (eObj == null) {
            log.error("OlapInfo Element is null.");
            throw new JRRuntimeException("OlapInfo Element is null.");
        }
        olapInfoElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve OlapInfo Element.");
        throw new JRRuntimeException("Could not retrieve OlapInfo Element.");
    }

    parseOLAPInfoElement(olapInfoElement);

    // Get the Axes Element
    Name axesName = soapEnvelope.createName("Axes", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator axesElements = rootElement.getChildElements(axesName);
    if (axesElements.hasNext()) {
        Object eObj = axesElements.next();
        if (eObj == null) {
            log.error("Axes Element is null");
            throw new JRRuntimeException("Axes Element is null");
        }
        axesElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve Axes Element.");
        throw new JRRuntimeException("Could not retrieve Axes Element.");
    }

    parseAxesElement(axesElement);

    // Get the CellData Element
    Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI);
    SOAPElement cellDataElement = null;
    Iterator cellDataElements = rootElement.getChildElements(cellDataName);
    if (cellDataElements.hasNext()) {
        Object eObj = cellDataElements.next();
        if (eObj == null) {
            log.error("CellData element is null");
            throw new JRRuntimeException("CellData element is null");
        }
        cellDataElement = (SOAPElement) eObj;
    } else {
        log.error("Could not retrieve CellData Element.");
        throw new JRRuntimeException("Could not retrieve CellData Element.");
    }
    parseCellDataElement(cellDataElement);
}