001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.interceptor;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.w3c.dom.Document;
023: import org.w3c.dom.Element;
024:
025: import org.apache.cxf.common.i18n.Message;
026: import org.apache.cxf.common.i18n.UncheckedException;
027: import org.apache.cxf.helpers.DOMUtils;
028:
029: /**
030: * A Fault that occurs during invocation processing.
031: */
032: public class Fault extends UncheckedException {
033: public static final QName FAULT_CODE_CLIENT = new QName(
034: "http://cxf.apache.org/faultcode", "client");
035: public static final QName FAULT_CODE_SERVER = new QName(
036: "http://cxf.apache.org/faultcode", "server");
037:
038: public static final String STACKTRACE = "stackTrace";
039: private Element detail;
040: private String message;
041: private QName code;
042:
043: public Fault(Message message, Throwable throwable) {
044: super (message, throwable);
045: this .message = message.toString();
046: code = FAULT_CODE_SERVER;
047: }
048:
049: public Fault(Message message) {
050: super (message);
051: this .message = message.toString();
052: code = FAULT_CODE_SERVER;
053: }
054:
055: public Fault(Throwable t) {
056: super (t);
057: if (super .getMessage() != null) {
058: message = super .getMessage();
059: } else {
060: message = t == null ? null : t.getMessage();
061: }
062: code = FAULT_CODE_SERVER;
063: }
064:
065: public Fault(Message message, Throwable throwable, QName fc) {
066: super (message, throwable);
067: this .message = message.toString();
068: code = fc;
069: }
070:
071: public Fault(Message message, QName fc) {
072: super (message);
073: this .message = message.toString();
074: code = fc;
075: }
076:
077: public Fault(Throwable t, QName fc) {
078: super (t);
079: if (super .getMessage() != null) {
080: message = super .getMessage();
081: } else {
082: message = t == null ? null : t.getMessage();
083: }
084: code = fc;
085: }
086:
087: public String getMessage() {
088: return message;
089: }
090:
091: public void setMessage(String message) {
092: this .message = message;
093: }
094:
095: public QName getFaultCode() {
096: return code;
097: }
098:
099: public Fault setFaultCode(QName c) {
100: code = c;
101: return this ;
102: }
103:
104: /**
105: * Returns the detail node. If no detail node has been set, an empty
106: * <code><detail></code> is created.
107: *
108: * @return the detail node.
109: */
110: public Element getDetail() {
111: return detail;
112: }
113:
114: /**
115: * Sets a details <code>Node</code> on this fault.
116: *
117: * @param details the detail node.
118: */
119: public void setDetail(Element details) {
120: detail = details;
121: }
122:
123: /**
124: * Indicates whether this fault has a detail message.
125: *
126: * @return <code>true</code> if this fault has a detail message;
127: * <code>false</code> otherwise.
128: */
129: public boolean hasDetails() {
130: return this .detail != null;
131: }
132:
133: public Element getOrCreateDetail() {
134: Document d = DOMUtils.createDocument();
135: Element element = d.createElement("Fault");
136: this.detail = element;
137: return element;
138: }
139: }
|