View Javadoc
1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.axiom;
18  
19  import javax.xml.transform.Result;
20  import javax.xml.transform.Source;
21  
22  import org.springframework.util.Assert;
23  import org.springframework.ws.soap.SoapBody;
24  import org.springframework.ws.soap.axiom.support.AxiomUtils;
25  import org.springframework.ws.stream.StreamingPayload;
26  
27  import org.apache.axiom.om.OMDataSource;
28  import org.apache.axiom.om.OMElement;
29  import org.apache.axiom.soap.SOAPBody;
30  import org.apache.axiom.soap.SOAPFactory;
31  
32  /**
33   * Axiom-specific version of <code>org.springframework.ws.soap.Soap11Body</code>.
34   *
35   * @author Arjen Poutsma
36   * @since 1.0.0
37   */
38  abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
39  
40      private final Payload payload;
41  
42      protected AxiomSoapBody(SOAPBody axiomBody, SOAPFactory axiomFactory, boolean payloadCaching) {
43          super(axiomBody, axiomFactory);
44          if (payloadCaching) {
45              payload = new CachingPayload(axiomBody, axiomFactory);
46          }
47          else {
48              payload = new NonCachingPayload(axiomBody, axiomFactory);
49          }
50      }
51  
52      public Source getPayloadSource() {
53          return payload.getSource();
54      }
55  
56      public Result getPayloadResult() {
57          return payload.getResult();
58      }
59  
60      public boolean hasFault() {
61          return getAxiomBody().hasFault();
62      }
63  
64      protected final SOAPBody getAxiomBody() {
65          return (SOAPBody) getAxiomElement();
66      }
67  
68      public void setStreamingPayload(StreamingPayload payload) {
69          Assert.notNull(payload, "'payload' must not be null");
70          OMDataSource dataSource = new StreamingOMDataSource(payload);
71          OMElement payloadElement = getAxiomFactory().createOMElement(dataSource, payload.getName());
72  
73          SOAPBody soapBody = getAxiomBody();
74          AxiomUtils.removeContents(soapBody);
75          soapBody.addChild(payloadElement);
76      }
77  }