01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.SOAPEnvelope;
21: import javax.xml.soap.SOAPException;
22: import javax.xml.soap.SOAPHeader;
23:
24: import org.springframework.ws.soap.SoapBody;
25: import org.springframework.ws.soap.SoapEnvelope;
26: import org.springframework.ws.soap.SoapHeader;
27: import org.springframework.ws.soap.SoapVersion;
28:
29: /**
30: * SAAJ-specific implementation of the <code>SoapEnvelope</code> interface. Wraps a {@link
31: * javax.xml.soap.SOAPEnvelope}.
32: *
33: * @author Arjen Poutsma
34: * @since 1.0.0
35: */
36: class SaajSoapEnvelope extends SaajSoapElement implements SoapEnvelope {
37:
38: private SaajSoapBody body;
39:
40: private SaajSoapHeader header;
41:
42: public SaajSoapEnvelope(SOAPEnvelope envelope) {
43: super (envelope);
44: }
45:
46: public SoapBody getBody() {
47: if (body == null) {
48: try {
49: SOAPBody saajBody = getImplementation().getBody(
50: getSaajEnvelope());
51: if (getImplementation().getName(saajBody)
52: .getNamespaceURI().equals(
53: SoapVersion.SOAP_11
54: .getEnvelopeNamespaceUri())) {
55: body = new SaajSoap11Body(saajBody);
56: } else {
57: body = new SaajSoap12Body(saajBody);
58: }
59: } catch (SOAPException ex) {
60: throw new SaajSoapBodyException(ex);
61: }
62: }
63: return body;
64: }
65:
66: public SoapHeader getHeader() {
67: if (header == null) {
68: try {
69: SOAPHeader saajHeader = getImplementation().getHeader(
70: getSaajEnvelope());
71: if (saajHeader != null) {
72: if (getImplementation().getName(saajHeader)
73: .getNamespaceURI().equals(
74: SoapVersion.SOAP_11
75: .getEnvelopeNamespaceUri())) {
76: header = new SaajSoap11Header(saajHeader);
77: } else {
78: header = new SaajSoap12Header(saajHeader);
79: }
80: } else {
81: header = null;
82: }
83: } catch (SOAPException ex) {
84: throw new SaajSoapHeaderException(ex);
85: }
86: }
87: return header;
88: }
89:
90: protected SOAPEnvelope getSaajEnvelope() {
91: return (SOAPEnvelope) getSaajElement();
92: }
93:
94: }
|