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 java.util.Locale;
20: import javax.xml.namespace.QName;
21: import javax.xml.soap.SOAPBody;
22: import javax.xml.soap.SOAPException;
23: import javax.xml.soap.SOAPFault;
24:
25: import org.springframework.util.Assert;
26: import org.springframework.ws.soap.SoapFault;
27: import org.springframework.ws.soap.SoapVersion;
28: import org.springframework.ws.soap.soap11.Soap11Body;
29: import org.springframework.ws.soap.soap11.Soap11Fault;
30:
31: /**
32: * SAAJ-specific implementation of the <code>Soap11Body</code> interface. Wraps a {@link javax.xml.soap.SOAPBody}.
33: *
34: * @author Arjen Poutsma
35: * @since 1.0.0
36: */
37: class SaajSoap11Body extends SaajSoapBody implements Soap11Body {
38:
39: public SaajSoap11Body(SOAPBody body) {
40: super (body);
41: }
42:
43: public SoapFault getFault() {
44: SOAPFault fault = getImplementation().getFault(getSaajBody());
45: return new SaajSoap11Fault(fault);
46: }
47:
48: public Soap11Fault addFault(QName faultCode, String faultString,
49: Locale faultStringLocale) {
50: Assert.notNull(faultCode, "No faultCode given");
51: Assert.hasLength(faultString, "faultString cannot be empty");
52: Assert.hasLength(faultCode.getLocalPart(),
53: "faultCode's localPart cannot be empty");
54: Assert.hasLength(faultCode.getNamespaceURI(),
55: "faultCode's namespaceUri cannot be empty");
56: try {
57: getImplementation().removeContents(getSaajBody());
58: SOAPFault saajFault = getImplementation().addFault(
59: getSaajBody(), faultCode, faultString,
60: faultStringLocale);
61: return new SaajSoap11Fault(saajFault);
62: } catch (SOAPException ex) {
63: throw new SaajSoapFaultException(ex);
64: }
65: }
66:
67: public SoapFault addClientOrSenderFault(String faultString,
68: Locale locale) {
69: return addFault(SoapVersion.SOAP_11
70: .getClientOrSenderFaultName(), faultString, locale);
71: }
72:
73: public SoapFault addMustUnderstandFault(String faultString,
74: Locale locale) {
75: return addFault(SoapVersion.SOAP_11
76: .getMustUnderstandFaultName(), faultString, locale);
77: }
78:
79: public SoapFault addServerOrReceiverFault(String faultString,
80: Locale locale) {
81: return addFault(SoapVersion.SOAP_11
82: .getServerOrReceiverFaultName(), faultString, locale);
83: }
84:
85: public SoapFault addVersionMismatchFault(String faultString,
86: Locale locale) {
87: return addFault(SoapVersion.SOAP_11
88: .getVersionMismatchFaultName(), faultString, locale);
89: }
90:
91: }
|