001: /*
002: * Created on 29.07.2005
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package de.schlund.pfixcore.webservice.fault;
008:
009: import org.apache.log4j.Logger;
010:
011: import de.schlund.pfixcore.webservice.ServiceRequest;
012: import de.schlund.pfixcore.webservice.ServiceResponse;
013: import de.schlund.pfixcore.workflow.Context;
014:
015: public class Fault {
016:
017: Logger LOG = Logger.getLogger(getClass().getName());
018:
019: String serviceName;
020: ServiceRequest srvReq;
021: ServiceResponse srvRes;
022: String reqMsg;
023: Context context;
024: Throwable throwable;
025: String faultString;
026:
027: public Fault(String serviceName, ServiceRequest srvReq,
028: ServiceResponse srvRes, String reqMsg, Context context) {
029: this .serviceName = serviceName;
030: this .srvReq = srvReq;
031: this .srvRes = srvRes;
032: this .reqMsg = reqMsg;
033: this .context = context;
034: }
035:
036: public ServiceRequest getRequest() {
037: return srvReq;
038: }
039:
040: public ServiceResponse getResponse() {
041: return srvRes;
042: }
043:
044: public Throwable getThrowable() {
045: return throwable;
046: }
047:
048: public void setThrowable(Throwable throwable) {
049: this .throwable = throwable;
050: faultString = null;
051: }
052:
053: public String getStackTrace() {
054: if (throwable == null)
055: return null;
056: StringBuffer sb = new StringBuffer();
057: int maxDepth = 10;
058: int depth = 0;
059: Throwable cause = throwable;
060: while (depth < maxDepth && cause != null) {
061: if (depth > 0)
062: sb.append("Caused by ");
063: sb.append(cause.toString());
064: sb.append("\n");
065: StackTraceElement[] elems = cause.getStackTrace();
066: int maxLen = elems.length;
067: if (depth > 0 && elems.length > 10)
068: maxLen = 10;
069: for (int i = 0; i < maxLen; i++) {
070: sb.append("\tat ");
071: sb.append(elems[i].toString());
072: sb.append("\n");
073: }
074: if (maxLen < elems.length)
075: sb.append("\t... " + (elems.length - maxLen)
076: + " more\n");
077: cause = cause.getCause();
078: depth++;
079: }
080: return sb.toString();
081: }
082:
083: public String getName() {
084: if (throwable != null)
085: return throwable.getClass().getName();
086: return null;
087: }
088:
089: public String getMessage() {
090: if (throwable != null)
091: return throwable.getMessage();
092: return null;
093: }
094:
095: public String getFaultString() {
096: if (faultString != null)
097: return faultString;
098: return getName() + ": " + getMessage();
099: }
100:
101: public void setName(String name) {
102: String msg = getMessage();
103: faultString = name + ": " + msg;
104: }
105:
106: public void setMessage(String msg) {
107: String name = getName();
108: faultString = name + ": " + msg;
109: }
110:
111: public String getRequestMessage() {
112: return reqMsg;
113: }
114:
115: public String getServiceName() {
116: return serviceName;
117: }
118:
119: public Context getContext() {
120: return context;
121: }
122:
123: }
|