View Javadoc
1   /*
2    * Copyright 2002-2009 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 org.apache.axiom.om.OMException;
20  import org.apache.axiom.soap.SOAP11Constants;
21  import org.apache.axiom.soap.SOAP12Constants;
22  import org.apache.axiom.soap.SOAPBody;
23  import org.apache.axiom.soap.SOAPEnvelope;
24  import org.apache.axiom.soap.SOAPFactory;
25  import org.apache.axiom.soap.SOAPHeader;
26  
27  import org.springframework.ws.soap.SoapBody;
28  import org.springframework.ws.soap.SoapEnvelope;
29  import org.springframework.ws.soap.SoapHeader;
30  
31  /**
32   * Axiom-Specific version of <code>org.springframework.ws.soap.SoapEnvelope</code>.
33   *
34   * @author Arjen Poutsma
35   * @since 1.0.0
36   */
37  class AxiomSoapEnvelope extends AxiomSoapElement implements SoapEnvelope {
38  
39      boolean payloadCaching;
40  
41      private AxiomSoapBody body;
42  
43      private final boolean langAttributeOnSoap11FaultString;
44  
45      AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope,
46                        SOAPFactory axiomFactory,
47                        boolean payloadCaching,
48                        boolean langAttributeOnSoap11FaultString) {
49          super(axiomEnvelope, axiomFactory);
50          this.payloadCaching = payloadCaching;
51          this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
52      }
53  
54      public SoapHeader getHeader() {
55          try {
56              if (getAxiomEnvelope().getHeader() == null) {
57                  return null;
58              }
59              else {
60                  SOAPHeader axiomHeader = getAxiomEnvelope().getHeader();
61                  String namespaceURI = getAxiomEnvelope().getNamespace().getNamespaceURI();
62                  if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
63                      return new AxiomSoap11Header(axiomHeader, getAxiomFactory());
64                  }
65                  else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
66                      return new AxiomSoap12Header(axiomHeader, getAxiomFactory());
67                  }
68                  else {
69                      throw new AxiomSoapEnvelopeException("Unknown SOAP namespace \"" + namespaceURI + "\"");
70                  }
71              }
72          }
73          catch (OMException ex) {
74              throw new AxiomSoapHeaderException(ex);
75          }
76      }
77  
78      public SoapBody getBody() {
79          if (body == null) {
80              try {
81                  SOAPBody axiomBody = getAxiomEnvelope().getBody();
82                  String namespaceURI = getAxiomEnvelope().getNamespace().getNamespaceURI();
83                  if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
84                      body = new AxiomSoap11Body(axiomBody, getAxiomFactory(), payloadCaching,
85                              langAttributeOnSoap11FaultString);
86                  }
87                  else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
88                      body = new AxiomSoap12Body(axiomBody, getAxiomFactory(), payloadCaching);
89                  }
90                  else {
91                      throw new AxiomSoapEnvelopeException("Unknown SOAP namespace \"" + namespaceURI + "\"");
92                  }
93              }
94              catch (OMException ex) {
95                  throw new AxiomSoapBodyException(ex);
96              }
97          }
98          return body;
99      }
100 
101     protected SOAPEnvelope getAxiomEnvelope() {
102         return (SOAPEnvelope) getAxiomElement();
103     }
104 
105 }