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;
18:
19: import javax.xml.transform.Result;
20: import javax.xml.transform.Source;
21:
22: import org.springframework.ws.mime.AbstractMimeMessage;
23:
24: /**
25: * Abstract implementation of the {@link SoapMessage} interface. Contains convenient default implementations.
26: *
27: * @author Arjen Poutsma
28: * @since 1.0.0
29: */
30: public abstract class AbstractSoapMessage extends AbstractMimeMessage
31: implements SoapMessage {
32:
33: private SoapVersion version;
34:
35: /** Returns <code>getEnvelope().getBody()</code>. */
36: public final SoapBody getSoapBody() {
37: return getEnvelope().getBody();
38: }
39:
40: /** Returns <code>getEnvelope().getHeader()</code>. */
41: public final SoapHeader getSoapHeader() {
42: return getEnvelope().getHeader();
43: }
44:
45: /** Returns <code>getSoapBody().getPayloadSource()</code>. */
46: public final Source getPayloadSource() {
47: return getSoapBody().getPayloadSource();
48: }
49:
50: /** Returns <code>getSoapBody().getPayloadResult()</code>. */
51: public final Result getPayloadResult() {
52: return getSoapBody().getPayloadResult();
53: }
54:
55: /** Returns <code>getSoapBody().hasFault()</code>. */
56: public final boolean hasFault() {
57: return getSoapBody().hasFault();
58: }
59:
60: /** Returns <code>getSoapBody().getFault().getFaultStringOrReason()</code>. */
61: public final String getFaultReason() {
62: if (hasFault()) {
63: return getSoapBody().getFault().getFaultStringOrReason();
64: } else {
65: return null;
66: }
67: }
68:
69: public SoapVersion getVersion() {
70: if (version == null) {
71: String envelopeNamespace = getEnvelope().getName()
72: .getNamespaceURI();
73: if (SoapVersion.SOAP_11.getEnvelopeNamespaceUri().equals(
74: envelopeNamespace)) {
75: version = SoapVersion.SOAP_11;
76: } else if (SoapVersion.SOAP_12.getEnvelopeNamespaceUri()
77: .equals(envelopeNamespace)) {
78: version = SoapVersion.SOAP_12;
79: } else {
80: throw new IllegalStateException(
81: "Unknown Envelope namespace uri '"
82: + envelopeNamespace + "'. "
83: + "Cannot deduce SoapVersion.");
84: }
85: }
86: return version;
87: }
88:
89: }
|