soapfaultimpl.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 809 行 · 第 1/3 页

JAVA
809
字号
                        if (lang.indexOf("_") != -1) {
                            String language = lang.substring(0, lang.indexOf("_"));
                            String country = lang.substring(lang.indexOf("_") + 1);
                            faultReasonLocales.add(new Locale(language, country));
                        } else {
                            faultReasonLocales.add(new Locale(lang));
                        }
                    }
                }
            }
            return faultReasonLocales.iterator();
        }
    }

    /**
     * Returns the Reason Text associated with the given Locale. If more than one such Reason Text
     * exists the first matching Text is returned
     *
     * @param locale - the Locale for which a localized Reason Text is desired
     * @return the Reason Text associated with locale
     * @throws SOAPException - if there was an error in retrieving the fault Reason text for the
     *                       specified locale. java.lang.UnsupportedOperationException - if this
     *                       message does not support the SOAP 1.2 concept of Fault Reason.
     * @since SAAJ 1.3
     */
    public String getFaultReasonText(Locale locale) throws SOAPException {
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException("Message does not support the " +
                    "SOAP 1.2 concept of Fault Reason");
        } else {
            Iterator soapTextsItr = null;
            SOAPFaultReason soapFaultReason = this.fault.getReason();
            if (soapFaultReason != null) {
                List soapTexts = soapFaultReason.getAllSoapTexts();
                if (soapTexts != null) {
                    soapTextsItr = soapTexts.iterator();
                    while (soapTextsItr.hasNext()) {
                        SOAPFaultText soapFaultText = (SOAPFaultText)soapTextsItr.next();
                        if (soapFaultText.getLang().equals(locale.toString())) {
                            return soapFaultText.getText();
                        }
                    }
                }
            }
        }
        return null;
    }

    /**
     * Returns an Iterator over a sequence of String objects containing all of the Reason Text items
     * for this SOAPFault.
     *
     * @throws SOAPException if there is an error in retrieving texts for Reason objects
     *                       java.lang.UnsupportedOperationException - if this message does not
     *                       support the SOAP 1.2 concept of Fault Reason.
     */

    public Iterator getFaultReasonTexts() throws SOAPException {
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException();
        }

        Iterator soapTextsItr = this.fault.getReason().getAllSoapTexts().iterator();
        ArrayList reasonTexts = new ArrayList();
        while (soapTextsItr.hasNext()) {
            SOAPFaultText soapFaultText = (SOAPFaultText)soapTextsItr.next();
            reasonTexts.add(soapFaultText.getText());
        }
        return reasonTexts.iterator();
    }

    /**
     * Returns the optional Role element value for this SOAPFault object. The Role element is
     * optional in SOAP 1.2.
     *
     * @return Content of the env:Fault/env:Role element as a String or null if none
     * @throws UnsupportedOperationException
     *          - if this message does not support the SOAP 1.2 concept of Fault Role.
     * @since SAAJ 1.3
     */
    public String getFaultRole() {
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException("Message does not support the " +
                    "SOAP 1.2 concept of Fault Reason");
        } else {
            if (this.fault.getRole() != null) {
                return this.fault.getRole().getText();
            } else {
                return null;
            }
        }
    }

    /**
     * Gets the Subcodes for this SOAPFault as an iterator over QNames.
     *
     * @return an Iterator that accesses a sequence of QNames. This Iterator should not support the
     *         optional remove method. The order in which the Subcodes are returned reflects the
     *         hierarchy of Subcodes present in the fault from top to bottom.
     * @throws UnsupportedOperationException
     *          - if this message does not support the SOAP 1.2 concept of Subcode.
     */
    public Iterator getFaultSubcodes() {
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException();
        }
        ArrayList faultSubcodes = new ArrayList();
        SOAPFaultSubCode subCodeElement = this.fault.getCode().getSubCode();
        while (subCodeElement != null) {
            QName qname = subCodeElement.getValue().getTextAsQName();
            faultSubcodes.add(qname);
            subCodeElement = subCodeElement.getSubCode();
        }
        return faultSubcodes.iterator();
    }

    /** Returns true if this SOAPFault has a Detail subelement and false otherwise. */
    public boolean hasDetail() {
        if (this.fault.getDetail() != null) {
            return true;
        } else {
            return false;
        }

    }

    /**
     * Removes any Subcodes that may be contained by this SOAPFault. Subsequent calls to
     * getFaultSubcodes will return an empty iterator until a call to appendFaultSubcode is made.
     *
     * @throws UnsupportedOperationException
     *          - if this message does not support the SOAP 1.2 concept of Subcode.
     */
    public void removeAllFaultSubcodes() {
        if (factory instanceof SOAP11Factory) {
            throw new UnsupportedOperationException();
        } else {
            fault.getCode().getSubCode().detach();
        }
    }


    /**
     * Sets this SOAPFault object with the given fault code. It is preferable to use this method
     * over setFaultCode(Name)
     *
     * @param faultCodeQName - a QName object giving the fault code to be set. It must be namespace
     *                       qualified.
     * @throws SOAPException - if there was an error in adding the faultcode element to the
     *                       underlying XML tree.
     * @see getFaultCodeAsQName(), setFaultCode(Name), getFaultCodeAsQName()
     * @since SAAJ 1.3
     */
    public void setFaultCode(QName qname) throws SOAPException {
        if (qname.getNamespaceURI() == null
                || qname.getNamespaceURI().trim().length() == 0) {
            throw new SOAPException("Unqualified QName object : " + qname);
        }

        org.apache.axiom.soap.SOAPFactory soapFactory = null;
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            soapFactory = (SOAPFactory)this.element.getOMFactory();
        } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
            if (!(qname.getNamespaceURI()
                    .equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE))) {
                throw new SOAPException("Incorrect URI"
                        + qname.getNamespaceURI());
            }
            soapFactory = (SOAPFactory)this.element.getOMFactory();
        } else {
            throw new SOAPException("Invalid SOAP version");
        }
        SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode(this.fault);

        String prefix = ((qname.getPrefix() != null) && !qname.getPrefix()
                .equals("")) ? qname.getPrefix() : this.fault.getQName()
                .getPrefix();

        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            soapFaultCode.setText(prefix + ":" + qname.getLocalPart());
            OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
                                                          qname.getPrefix());
            soapFaultCode.declareNamespace(omNamespace);
        } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
            SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
            // don't just use the default prefix, use the passed one or the parent's
            soapFaultValue.setText(prefix + ":" + qname.getLocalPart());
            OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
                                                          qname.getPrefix());
            soapFaultValue.declareNamespace(omNamespace);
            soapFaultCode.setValue(soapFaultValue);
        }
        
        this.fault.setCode(soapFaultCode);
    }

    /**
     * Creates or replaces any existing Node element value for this SOAPFault object. The Node
     * element is optional in SOAP 1.2.
     *
     * @throws SOAPException - if there was an error in setting the Node for this SOAPFault object.
     *                       java.lang.UnsupportedOperationException - if this message does not
     *                       support the SOAP 1.2 concept of Fault Node.
     * @since SAAJ 1.3
     */

    public void setFaultNode(String s) throws SOAPException {
        org.apache.axiom.soap.SOAPFactory soapFactory = null;
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException("message does not support " +
                    "the SOAP 1.2 concept of Fault Node");
        } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
            soapFactory = DOOMAbstractFactory.getSOAP12Factory();
        }
        SOAPFaultNode soapFaultNode = soapFactory.createSOAPFaultNode(this.fault);
        soapFaultNode.setText(s);
        this.fault.setNode(soapFaultNode);
    }

    /**
     * Creates or replaces any existing Role element value for this SOAPFault object. The Role
     * element is optional in SOAP 1.2.
     *
     * @param uri - the URI of the Role
     * @throws SOAPException - if there was an error in setting the Role for this SOAPFault object
     *                       java.lang.UnsupportedOperationException - if this message does not
     *                       support the SOAP 1.2 concept of Fault Role.
     */
    public void setFaultRole(String uri) throws SOAPException {
        org.apache.axiom.soap.SOAPFactory soapFactory = null;
        if (this.element.getOMFactory() instanceof SOAP11Factory) {
            throw new UnsupportedOperationException("message does not support the " +
                    "SOAP 1.2 concept of Fault Role");
        } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
            soapFactory = DOOMAbstractFactory.getSOAP12Factory();
        }
        SOAPFaultRole soapFaultRole = soapFactory.createSOAPFaultRole(this.fault);
        soapFaultRole.setRoleValue(uri);
        this.fault.setRole(soapFaultRole);
    }

    public Iterator getChildElements(Name name) {
        QName qName = new QName(name.getURI(), name.getLocalName());
        return getChildren(element.getChildrenWithName(qName));
    }

    public Iterator getChildElements() {
        return getChildren(element.getChildren());
    }

    private Iterator getChildren(Iterator childIter) {
        Collection childElements = new ArrayList();
        while (childIter.hasNext()) {
            org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next();
            Node saajNode = toSAAJNode(domNode);
            if (!(saajNode instanceof SOAPFaultElement)) {
                // silently replace node, as per saaj 1.2 spec
                SOAPFaultElement bodyEle = new SOAPFaultElementImpl((ElementImpl)domNode);
                ((NodeImpl)domNode).setUserData(SAAJ_NODE, bodyEle, null);
                childElements.add(bodyEle);
            } else {
                childElements.add(saajNode);
            }
        }
        return childElements.iterator();
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?