001: /*
002: * Copyright 2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.axiom;
018:
019: import java.util.Iterator;
020: import javax.xml.transform.Result;
021: import javax.xml.transform.Source;
022: import javax.xml.transform.sax.SAXResult;
023:
024: import org.apache.axiom.om.OMElement;
025: import org.apache.axiom.om.OMException;
026: import org.apache.axiom.soap.SOAPBody;
027: import org.apache.axiom.soap.SOAPFactory;
028: import org.apache.axiom.soap.SOAPFault;
029: import org.springframework.ws.soap.SoapBody;
030: import org.springframework.ws.soap.SoapFault;
031: import org.springframework.xml.transform.StaxSource;
032:
033: /**
034: * Axiom-specific version of <code>org.springframework.ws.soap.Soap11Body</code>.
035: *
036: * @author Arjen Poutsma
037: * @since 1.0.0
038: */
039: abstract class AxiomSoapBody extends AxiomSoapElement implements
040: SoapBody {
041:
042: private boolean payloadCaching;
043:
044: protected AxiomSoapBody(SOAPBody axiomBody,
045: SOAPFactory axiomFactory, boolean payloadCaching) {
046: super (axiomBody, axiomFactory);
047: this .payloadCaching = payloadCaching;
048: }
049:
050: public Source getPayloadSource() {
051: try {
052: OMElement payloadElement = getPayloadElement();
053: if (payloadElement == null) {
054: return null;
055: } else if (payloadCaching) {
056: return new StaxSource(payloadElement
057: .getXMLStreamReader());
058: } else {
059: return new StaxSource(payloadElement
060: .getXMLStreamReaderWithoutCaching());
061: }
062: } catch (OMException ex) {
063: throw new AxiomSoapBodyException(ex);
064: }
065: }
066:
067: public Result getPayloadResult() {
068: return new SAXResult(new AxiomContentHandler(getAxiomBody()));
069: }
070:
071: public boolean hasFault() {
072: return getAxiomBody().hasFault();
073: }
074:
075: public SoapFault getFault() {
076: SOAPFault axiomFault = getAxiomBody().getFault();
077: return axiomFault != null ? new AxiomSoap11Fault(axiomFault,
078: getAxiomFactory()) : null;
079: }
080:
081: private OMElement getPayloadElement() throws OMException {
082: return getAxiomBody().getFirstElement();
083: }
084:
085: protected void detachAllBodyChildren() {
086: try {
087: for (Iterator iterator = getAxiomBody().getChildElements(); iterator
088: .hasNext();) {
089: OMElement child = (OMElement) iterator.next();
090: child.detach();
091: }
092: } catch (OMException ex) {
093: throw new AxiomSoapBodyException(ex);
094: }
095:
096: }
097:
098: protected final SOAPBody getAxiomBody() {
099: return (SOAPBody) getAxiomElement();
100: }
101: }
|