001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.soap;
018    
019    import java.net.URI;
020    
021    import javax.xml.namespace.QName;
022    import javax.xml.transform.Source;
023    
024    import org.apache.servicemix.soap.marshalers.SoapMarshaler;
025    
026    /**
027     * Represents a SOAP fault which occurred while processing the
028     * message.
029     *
030     * @author Guillaume Nodet
031     * @version $Revision: 1.5 $
032     * @since 3.0
033     */
034    public class SoapFault extends Exception {
035            
036        private static final long serialVersionUID = 984561453557136677L;
037        
038        public static final QName SENDER = SoapMarshaler.SOAP_12_CODE_SENDER;
039            public static final QName RECEIVER = SoapMarshaler.SOAP_12_CODE_RECEIVER;
040            
041        private QName code;
042        private QName subcode;
043        private String reason;
044        private URI node;
045        private URI role;
046        private Source details;
047    
048        public SoapFault(Exception cause) {
049            super(cause);
050        }
051    
052        public SoapFault(QName code, String reason) {
053            super(reason);
054            this.code = code;
055            this.reason = reason;
056        }
057    
058        public SoapFault(QName code, QName subcode, String reason) {
059            super(reason);
060            this.code = code;
061            this.subcode = subcode;
062            this.reason = reason;
063        }
064    
065        public SoapFault(QName code, String reason, URI node, URI role) {
066            super(reason);
067            this.code = code;
068            this.reason = reason;
069            this.node = node;
070            this.role = role;
071        }
072    
073        public SoapFault(QName code, String reason, URI node, URI role, Source details) {
074            super(reason);
075            this.code = code;
076            this.reason = reason;
077            this.node = node;
078            this.role = role;
079            this.details = details;
080        }
081    
082        public SoapFault(QName code, QName subcode, String reason, URI node, URI role, Source details) {
083            super(reason);
084            this.code = code;
085            this.subcode = subcode;
086            this.reason = reason;
087            this.node = node;
088            this.role = role;
089            this.details = details;
090        }
091    
092        public QName getCode() {
093            return code;
094        }
095    
096        public QName getSubcode() {
097            return subcode;
098        }
099    
100        public String getReason() {
101            return reason;
102        }
103    
104        public URI getNode() {
105            return node;
106        }
107    
108        public URI getRole() {
109            return role;
110        }
111    
112            public Source getDetails() {
113                    return details;
114            }
115    
116        public void translateCodeTo11() {
117            if (code != null) {
118                if (subcode != null) {
119                    code = subcode;
120                    subcode = null;
121                } else if (SoapMarshaler.SOAP_12_CODE_DATAENCODINGUNKNOWN.equals(code)) {
122                    code = SoapMarshaler.SOAP_11_CODE_CLIENT;
123                } else if (SoapMarshaler.SOAP_12_CODE_MUSTUNDERSTAND.equals(code)) {
124                    code = SoapMarshaler.SOAP_11_CODE_MUSTUNDERSTAND;
125                } else if (SoapMarshaler.SOAP_12_CODE_RECEIVER.equals(code)) {
126                    code = SoapMarshaler.SOAP_11_CODE_SERVER;
127                } else if (SoapMarshaler.SOAP_12_CODE_SENDER.equals(code)) {
128                    code = SoapMarshaler.SOAP_11_CODE_CLIENT;
129                }
130            } else {
131                code = SoapMarshaler.SOAP_11_CODE_SERVER;
132            }
133        }
134    
135        public void translateCodeTo12() {
136            if (code != null && subcode == null) {
137                if (SoapMarshaler.SOAP_11_CODE_CLIENT.equals(code)) {
138                    code = SoapMarshaler.SOAP_12_CODE_SENDER;
139                } else if (SoapMarshaler.SOAP_11_CODE_MUSTUNDERSTAND.equals(code)) {
140                    code = SoapMarshaler.SOAP_12_CODE_MUSTUNDERSTAND;
141                } else if (SoapMarshaler.SOAP_11_CODE_SERVER.equals(code)) {
142                    code = SoapMarshaler.SOAP_12_CODE_RECEIVER;
143                } else if (SoapMarshaler.SOAP_11_CODE_VERSIONMISMATCH.equals(code)) {
144                    code = SoapMarshaler.SOAP_12_CODE_VERSIONMISMATCH;
145                } else {
146                    subcode = code;
147                    code = SoapMarshaler.SOAP_12_CODE_SENDER;
148                }
149            } else if (code == null) {
150                code = SoapMarshaler.SOAP_12_CODE_RECEIVER;
151            }
152        }
153    }