soappartimpl.java

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

JAVA
1,226
字号
    /**
     * Obtain the SOAPMessage
     *
     * @return the related SOAPMessage
     */
    public SOAPMessage getSoapMessage() {
        return soapMessage;
    }

    /**
     * Gets the <CODE>SOAPEnvelope</CODE> object associated with this <CODE>SOAPPart</CODE> object.
     * Once the SOAP envelope is obtained, it can be used to get its contents.
     *
     * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE> SOAPPart</CODE> object
     * @throws SOAPException if there is a SOAP error
     */
    public SOAPEnvelope getEnvelope() throws SOAPException {
        return envelope;
    }

    /**
     * Removes all MIME headers that match the given name.
     *
     * @param header a <CODE>String</CODE> giving the name of the MIME header(s) to be removed
     */
    public void removeMimeHeader(String header) {
        mimeHeaders.removeHeader(header);
    }

    /** Removes all the <CODE>MimeHeader</CODE> objects for this <CODE>SOAPEnvelope</CODE> object. */
    public void removeAllMimeHeaders() {
        mimeHeaders.removeAllHeaders();
    }

    /**
     * Gets all the values of the <CODE>MimeHeader</CODE> object in this <CODE>SOAPPart</CODE>
     * object that is identified by the given <CODE>String</CODE>.
     *
     * @param name the name of the header; example: "Content-Type"
     * @return a <CODE>String</CODE> array giving all the values for the specified header
     * @see #setMimeHeader(String, String) setMimeHeader(java.lang.String,
     *      java.lang.String)
     */
    public String[] getMimeHeader(String name) {
        return mimeHeaders.getHeader(name);
    }

    /**
     * Changes the first header entry that matches the given header name so that its value is the
     * given value, adding a new header with the given name and value if no existing header is a
     * match. If there is a match, this method clears all existing values for the first header that
     * matches and sets the given value instead. If more than one header has the given name, this
     * method removes all of the matching headers after the first one.
     * <p/>
     * <P>Note that RFC822 headers can contain only US-ASCII characters.</P>
     *
     * @param name  a <CODE>String</CODE> giving the header name for which to search
     * @param value a <CODE>String</CODE> giving the value to be set. This value will be substituted
     *              for the current value(s) of the first header that is a match if there is one. If
     *              there is no match, this value will be the value for a new
     *              <CODE>MimeHeader</CODE> object.
     * @throws IllegalArgumentException
     *          if there was a problem with the specified mime header name or value
     * @throws IllegalArgumentException
     *          if there was a problem with the specified mime header name or value
     * @see #getMimeHeader(String) getMimeHeader(java.lang.String)
     */
    public void setMimeHeader(String name, String value) {
        mimeHeaders.setHeader(name, value);
    }

    /**
     * Creates a <CODE>MimeHeader</CODE> object with the specified name and value and adds it to
     * this <CODE>SOAPPart</CODE> object. If a <CODE>MimeHeader</CODE> with the specified name
     * already exists, this method adds the specified value to the already existing value(s).
     * <p/>
     * <P>Note that RFC822 headers can contain only US-ASCII characters.</P>
     *
     * @param header a <CODE>String</CODE> giving the header name
     * @param value  a <CODE>String</CODE> giving the value to be set or added
     * @throws IllegalArgumentException if there was a problem with the specified mime header name
     *                                  or value
     */
    public void addMimeHeader(String header, String value) {
        mimeHeaders.addHeader(header, value);
    }

    /**
     * Retrieves all the headers for this <CODE>SOAPPart</CODE> object as an iterator over the
     * <CODE>MimeHeader</CODE> objects.
     *
     * @return an <CODE>Iterator</CODE> object with all of the Mime headers for this
     *         <CODE>SOAPPart</CODE> object
     */
    public Iterator getAllMimeHeaders() {
        return mimeHeaders.getAllHeaders();
    }

    /**
     * Retrieves all <CODE>MimeHeader</CODE> objects that match a name in the given array.
     *
     * @param names a <CODE>String</CODE> array with the name(s) of the MIME headers to be returned
     * @return all of the MIME headers that match one of the names in the given array, returned as
     *         an <CODE>Iterator</CODE> object
     */
    public Iterator getMatchingMimeHeaders(String[] names) {
        return mimeHeaders.getMatchingHeaders(names);
    }

    /**
     * Retrieves all <CODE>MimeHeader</CODE> objects whose name does not match a name in the given
     * array.
     *
     * @param names a <CODE>String</CODE> array with the name(s) of the MIME headers not to be
     *              returned
     * @return all of the MIME headers in this <CODE>SOAPPart</CODE> object except those that match
     *         one of the names in the given array. The nonmatching MIME headers are returned as an
     *         <CODE>Iterator</CODE> object.
     */
    public Iterator getNonMatchingMimeHeaders(String[] names) {
        return mimeHeaders.getNonMatchingHeaders(names);
    }

    public void setContent(Source source) throws SOAPException {
        this.source = source;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            XMLStreamReader reader;

            if (source instanceof StreamSource) {
                reader = inputFactory.createXMLStreamReader(source);
            } else {
                Result result = new StreamResult(baos);
                Transformer xformer = TransformerFactory.newInstance().newTransformer();
                xformer.transform(source, result);
                InputStream is = new ByteArrayInputStream(baos.toByteArray());
                reader = inputFactory.createXMLStreamReader(is);
            }

            StAXSOAPModelBuilder builder1 = null;
            if (this.envelope.element.getOMFactory() instanceof SOAP11Factory) {
                builder1 = new StAXSOAPModelBuilder(reader,
                                                    (SOAP11Factory)this.envelope.element
                                                            .getOMFactory(), null);
            } else if (this.envelope.element.getOMFactory() instanceof SOAP12Factory) {
                builder1 = new StAXSOAPModelBuilder(reader,
                                                    (SOAP12Factory)this.envelope.element
                                                            .getOMFactory(), null);
            }

            org.apache.axiom.soap.SOAPEnvelope soapEnvelope = builder1.getSOAPEnvelope();
            envelope = new SOAPEnvelopeImpl(
                    (org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl)soapEnvelope);
            envelope.element.build();
            this.document = envelope.getOwnerDocument();
        } catch (TransformerFactoryConfigurationError e) {
            log.error(e);
            throw new SOAPException(e);
        } catch (Exception e) {
            log.error(e);
            throw new SOAPException(e);
        }
    }

    /**
     * Returns the content of the SOAPEnvelope as a JAXP <CODE> Source</CODE> object.
     *
     * @return the content as a <CODE> javax.xml.transform.Source</CODE> object
     * @throws SOAPException if the implementation cannot convert the specified <CODE>Source</CODE>
     *                       object
     * @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)
     */
    public Source getContent() throws SOAPException {
        DOMSource domSource = new DOMSource(this.document);
        this.source = domSource;
        return source;
    }

    /**
     * The Document Type Declaration (see <code>DocumentType</code>) associated with this document.
     * For HTML documents as well as XML documents without a document type declaration this returns
     * <code>null</code>. The DOM Level 2 does not support editing the Document Type Declaration.
     * <code>docType</code> cannot be altered in any way, including through the use of methods
     * inherited from the <code>Node</code> interface, such as <code>insertNode</code> or
     * <code>removeNode</code>.
     */
    public DocumentType getDoctype() {
        return document.getDoctype();
    }

    /**
     * The <code>DOMImplementation</code> object that handles this document. A DOM application may
     * use objects from multiple implementations.
     */
    public DOMImplementation getImplementation() {
        return document.getImplementation();
    }

    /**
     * This is a convenience attribute that allows direct access to the child node that is the root
     * element of the document. For HTML documents, this is the element with the tagName "HTML".
     */
    public Element getDocumentElement() {
        return document.getDocumentElement();
    }

    /**
     * Creates an element of the type specified. Note that the instance returned implements the
     * <code>Element</code> interface, so attributes can be specified directly on the returned
     * object. <br>In addition, if there are known attributes with default values, <code>Attr</code>
     * nodes representing them are automatically created and attached to the element. <br>To create
     * an element with a qualified name and namespace URI, use the <code>createElementNS</code>
     * method.
     *
     * @param tagName The name of the element type to instantiate. For XML, this is case-sensitive.
     *                For HTML, the <code>tagName</code> parameter may be provided in any case, but
     *                it must be mapped to the canonical uppercase form by the DOM implementation.
     * @return A new <code>Element</code> object with the <code>nodeName</code> attribute set to
     *         <code>tagName</code>, and <code>localName</code>, <code>prefix</code>, and
     *         <code>namespaceURI</code> set to <code>null</code>.
     * @throws DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal
     *                      character.
     */
    public Element createElement(String tagName) throws DOMException {
        return document.createElement(tagName);
    }

    /**
     * Creates an empty <code>DocumentFragment</code> object.
     *
     * @return A new <code>DocumentFragment</code>.
     */
    public DocumentFragment createDocumentFragment() {
        return document.createDocumentFragment();
    }

    /**
     * Creates a <code>Text</code> node given the specified string.
     *
     * @param data The data for the node.
     * @return The new <code>Text</code> object.
     */
    public Text createTextNode(String data) {
        return document.createTextNode(data);

⌨️ 快捷键说明

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