001: /*
002: * Copyright 2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.saaj;
018:
019: import java.util.Locale;
020: import javax.xml.namespace.QName;
021: import javax.xml.soap.SOAPBody;
022: import javax.xml.soap.SOAPException;
023: import javax.xml.soap.SOAPFault;
024:
025: import org.springframework.util.Assert;
026: import org.springframework.ws.soap.SoapFault;
027: import org.springframework.ws.soap.SoapVersion;
028: import org.springframework.ws.soap.soap12.Soap12Body;
029: import org.springframework.ws.soap.soap12.Soap12Fault;
030:
031: /**
032: * SAAJ-specific implementation of the <code>Soap12Body</code> interface. Wraps a {@link javax.xml.soap.SOAPBody}.
033: *
034: * @author Arjen Poutsma
035: * @since 1.0.0
036: */
037: class SaajSoap12Body extends SaajSoapBody implements Soap12Body {
038:
039: public SaajSoap12Body(SOAPBody body) {
040: super (body);
041: }
042:
043: public SoapFault getFault() {
044: SOAPFault fault = getImplementation().getFault(getSaajBody());
045: return new SaajSoap12Fault(fault);
046: }
047:
048: public SoapFault addClientOrSenderFault(String faultString,
049: Locale locale) {
050: return addFault(SoapVersion.SOAP_12
051: .getClientOrSenderFaultName(), faultString, locale);
052: }
053:
054: public SoapFault addMustUnderstandFault(String faultString,
055: Locale locale) {
056: return addFault(SoapVersion.SOAP_12
057: .getMustUnderstandFaultName(), faultString, locale);
058: }
059:
060: public SoapFault addServerOrReceiverFault(String faultString,
061: Locale locale) {
062: return addFault(SoapVersion.SOAP_12
063: .getServerOrReceiverFaultName(), faultString, locale);
064: }
065:
066: public SoapFault addVersionMismatchFault(String faultString,
067: Locale locale) {
068: return addFault(SoapVersion.SOAP_12
069: .getVersionMismatchFaultName(), faultString, locale);
070: }
071:
072: public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes,
073: String reason, Locale locale) {
074: QName name = new QName(SoapVersion.SOAP_12
075: .getEnvelopeNamespaceUri(), "DataEncodingUnknown");
076: Soap12Fault fault = addFault(name, reason, locale);
077: for (int i = 0; i < subcodes.length; i++) {
078: fault.addFaultSubcode(subcodes[i]);
079: }
080: return fault;
081: }
082:
083: protected Soap12Fault addFault(QName faultCode, String faultString,
084: Locale faultStringLocale) {
085: Assert.notNull(faultCode, "No faultCode given");
086: Assert.hasLength(faultString, "faultString cannot be empty");
087: Assert.hasLength(faultCode.getLocalPart(),
088: "faultCode's localPart cannot be empty");
089: Assert.hasLength(faultCode.getNamespaceURI(),
090: "faultCode's namespaceUri cannot be empty");
091: try {
092: getImplementation().removeContents(getSaajBody());
093: SOAPFault saajFault = getImplementation().addFault(
094: getSaajBody(), faultCode, faultString,
095: faultStringLocale);
096: return new SaajSoap12Fault(saajFault);
097: } catch (SOAPException ex) {
098: throw new SaajSoapFaultException(ex);
099: }
100: }
101:
102: }
|