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.saaj;
18  
19  import javax.xml.soap.SOAPBody;
20  import javax.xml.soap.SOAPElement;
21  import javax.xml.soap.SOAPEnvelope;
22  import javax.xml.soap.SOAPException;
23  import javax.xml.soap.SOAPHeader;
24  
25  import org.springframework.ws.soap.SoapBody;
26  import org.springframework.ws.soap.SoapEnvelope;
27  import org.springframework.ws.soap.SoapHeader;
28  import org.springframework.ws.soap.SoapVersion;
29  
30  /**
31   * SAAJ-specific implementation of the <code>SoapEnvelope</code> interface. Wraps a {@link
32   * javax.xml.soap.SOAPEnvelope}.
33   *
34   * @author Arjen Poutsma
35   * @since 1.0.0
36   */
37  class SaajSoapEnvelope extends SaajSoapElement implements SoapEnvelope {
38  
39      private SaajSoapBody body;
40  
41      private SaajSoapHeader header;
42  
43      private final boolean langAttributeOnSoap11FaultString;
44  
45      SaajSoapEnvelope(SOAPElement element, boolean langAttributeOnSoap11FaultString) {
46          super(element);
47          this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
48      }
49  
50      public SoapBody getBody() {
51          if (body == null) {
52              try {
53                  SOAPBody saajBody = getImplementation().getBody(getSaajEnvelope());
54                  if (getImplementation().getName(saajBody).getNamespaceURI()
55                          .equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
56                      body = new SaajSoap11Body(saajBody, langAttributeOnSoap11FaultString);
57                  }
58                  else {
59                      body = new SaajSoap12Body(saajBody);
60                  }
61              }
62              catch (SOAPException ex) {
63                  throw new SaajSoapBodyException(ex);
64              }
65          }
66          return body;
67      }
68  
69      public SoapHeader getHeader() {
70          if (header == null) {
71              try {
72                  SOAPHeader saajHeader = getImplementation().getHeader(getSaajEnvelope());
73                  if (saajHeader != null) {
74                      if (getImplementation().getName(saajHeader).getNamespaceURI()
75                              .equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
76                          header = new SaajSoap11Header(saajHeader);
77                      }
78                      else {
79                          header = new SaajSoap12Header(saajHeader);
80                      }
81                  }
82                  else {
83                      header = null;
84                  }
85              }
86              catch (SOAPException ex) {
87                  throw new SaajSoapHeaderException(ex);
88              }
89          }
90          return header;
91      }
92  
93      protected SOAPEnvelope getSaajEnvelope() {
94          return (SOAPEnvelope) getSaajElement();
95      }
96  
97  }