001: /**
002: * $Id: WebServiceDescriptorException.java,v 1.7 2003/08/13 12:23:01 sy131129 Exp $
003: * Copyright 2002-2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.providers.simplewebservice;
014:
015: import java.io.PrintWriter;
016: import java.io.StringWriter;
017:
018: /**
019: * The WebServiceDescriptorException is thrown from the WebServiceFactory
020: * Class if some problem occured while creating the WebServiceDescriptor.
021: *
022: */
023: public class WebServiceDescriptorException extends Exception {
024:
025: public static final String INVALID_URL = "INVALID_URL";
026: public static final String INVALID_WSDL = "INVALID_WSDL";
027: public static final String UNSUPPORTED_WSDL = "UNSUPPORTED_WSDL";
028: public static final String OTHER_ERROR = "OTHER_ERROR";
029:
030: private Throwable targetThrowable = null;
031: private String faultCode = null;
032:
033: /**
034: * Public Constructor.
035: *
036: * @param faultCode the WebServiceDescriptorException faultCode.
037: * @param message the WebServiceDescriptorException message.
038: * @param targetThrowable the target throwable for the WebServiceDescriptorException.
039: */
040: public WebServiceDescriptorException(String faultCode,
041: String message, Throwable targetThrowable) {
042: super (message);
043: this .faultCode = faultCode;
044: this .targetThrowable = targetThrowable;
045: }
046:
047: /**
048: * Public Constructor.
049: * @param faultCode the WebServiceDescriptorException faultCode.
050: * @param message the WebServiceDescriptorException message.
051: */
052: public WebServiceDescriptorException(String faultCode,
053: String message) {
054: this (faultCode, message, null);
055: }
056:
057: /**
058: * Gets the fault code associated with this Exception.
059: *
060: * @return the fault code.
061: */
062: public String getFaultCode() {
063: return faultCode;
064: }
065:
066: /**
067: * Gets the target Throwable associated with this Exception.
068: *
069: * @return the target Throwable.
070: */
071: public Throwable getTargetException() {
072: return targetThrowable;
073: }
074:
075: /**
076: * Gets the message associated with this Exception.
077: *
078: * @return the WebServiceDescriptorException message.
079: */
080: public String getMessage() {
081: StringBuffer strBuf = new StringBuffer();
082:
083: strBuf.append("WebServiceDescriptorException");
084:
085: String this Msg = super .getMessage();
086:
087: String targetMsg = (targetThrowable != null) ? targetThrowable
088: .getMessage() : null;
089:
090: if (this Msg != null
091: && (targetMsg == null || !this Msg.equals(targetMsg))) {
092: strBuf.append(": " + this Msg);
093: }
094:
095: if (targetMsg != null) {
096: strBuf.append(": " + targetMsg);
097: }
098:
099: if (faultCode != null) {
100: strBuf.append("faultCode: " + faultCode);
101: }
102:
103: return strBuf.toString();
104: }
105:
106: /**
107: * Gets the String representation for this Exception.
108: *
109: * @return the Exception String representation.
110: */
111: public String toString() {
112: StringWriter sw = new StringWriter();
113: PrintWriter pw = new PrintWriter(sw);
114:
115: pw.print(getMessage() + ": ");
116:
117: if (targetThrowable != null) {
118: targetThrowable.printStackTrace(pw);
119: }
120:
121: return sw.toString();
122: }
123: }
|