001: /*
002: * Copyright 2006 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.axiom;
018:
019: import java.util.Locale;
020: import javax.xml.namespace.QName;
021:
022: import org.apache.axiom.soap.SOAP12Constants;
023: import org.apache.axiom.soap.SOAPBody;
024: import org.apache.axiom.soap.SOAPFactory;
025: import org.apache.axiom.soap.SOAPFault;
026: import org.apache.axiom.soap.SOAPFaultCode;
027: import org.apache.axiom.soap.SOAPFaultReason;
028: import org.apache.axiom.soap.SOAPFaultText;
029: import org.apache.axiom.soap.SOAPFaultValue;
030: import org.apache.axiom.soap.SOAPProcessingException;
031: import org.springframework.util.Assert;
032: import org.springframework.ws.soap.SoapFault;
033: import org.springframework.ws.soap.axiom.support.AxiomUtils;
034: import org.springframework.ws.soap.soap12.Soap12Body;
035: import org.springframework.ws.soap.soap12.Soap12Fault;
036:
037: /**
038: * Axiom-specific version of <code>org.springframework.ws.soap.Soap12Body</code>.
039: *
040: * @author Arjen Poutsma
041: * @since 1.0.0
042: */
043: class AxiomSoap12Body extends AxiomSoapBody implements Soap12Body {
044:
045: AxiomSoap12Body(SOAPBody axiomBody, SOAPFactory axiomFactory,
046: boolean payloadCaching) {
047: super (axiomBody, axiomFactory, payloadCaching);
048: }
049:
050: public SoapFault addMustUnderstandFault(String reason, Locale locale) {
051: Assert.notNull(locale, "No locale given");
052: SOAPFault fault = addStandardFault(
053: SOAP12Constants.FAULT_CODE_MUST_UNDERSTAND, reason,
054: locale);
055: return new AxiomSoap12Fault(fault, getAxiomFactory());
056: }
057:
058: public SoapFault addClientOrSenderFault(String reason, Locale locale) {
059: Assert.notNull(locale, "No locale given");
060: SOAPFault fault = addStandardFault(
061: SOAP12Constants.FAULT_CODE_SENDER, reason, locale);
062: return new AxiomSoap12Fault(fault, getAxiomFactory());
063: }
064:
065: public SoapFault addServerOrReceiverFault(String reason,
066: Locale locale) {
067: Assert.notNull(locale, "No locale given");
068: SOAPFault fault = addStandardFault(
069: SOAP12Constants.FAULT_CODE_RECEIVER, reason, locale);
070: return new AxiomSoap12Fault(fault, getAxiomFactory());
071: }
072:
073: public SoapFault addVersionMismatchFault(String reason,
074: Locale locale) {
075: Assert.notNull(locale, "No locale given");
076: SOAPFault fault = addStandardFault(
077: SOAP12Constants.FAULT_CODE_VERSION_MISMATCH, reason,
078: locale);
079: return new AxiomSoap12Fault(fault, getAxiomFactory());
080: }
081:
082: public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes,
083: String reason, Locale locale) {
084: Assert.notNull(locale, "No locale given");
085: SOAPFault fault = addStandardFault(
086: SOAP12Constants.FAULT_CODE_DATA_ENCODING_UNKNOWN,
087: reason, locale);
088: return new AxiomSoap12Fault(fault, getAxiomFactory());
089: }
090:
091: private SOAPFault addStandardFault(String localName,
092: String faultStringOrReason, Locale locale) {
093: Assert.notNull(faultStringOrReason,
094: "No faultStringOrReason given");
095: try {
096: detachAllBodyChildren();
097: SOAPFault fault = getAxiomFactory().createSOAPFault(
098: getAxiomBody());
099: SOAPFaultCode code = getAxiomFactory().createSOAPFaultCode(
100: fault);
101: SOAPFaultValue value = getAxiomFactory()
102: .createSOAPFaultValue(code);
103: value.setText(fault.getNamespace().getPrefix() + ":"
104: + localName);
105: SOAPFaultReason reason = getAxiomFactory()
106: .createSOAPFaultReason(fault);
107: SOAPFaultText text = getAxiomFactory().createSOAPFaultText(
108: reason);
109: if (locale != null) {
110: text.setLang(AxiomUtils.toLanguage(locale));
111: }
112: text.setText(faultStringOrReason);
113: return fault;
114: } catch (SOAPProcessingException ex) {
115: throw new AxiomSoapFaultException(ex);
116: }
117: }
118:
119: }
|