org.globus.wsrf.utils
Class FaultHelper

java.lang.Object
  extended byorg.globus.wsrf.utils.FaultHelper

public class FaultHelper
extends Object

This class provides convenience functions around BaseFault API. It also provides a common way of including stack traces with Faults. A stack trace of a Fault is added as a chained BaseFault with an error code dialect attribute set to STACK_TRACE. A regular Java exception is automatically converted into a BaseFault with an error code dialect attribute set to EXCEPTION.


Field Summary
static URI EXCEPTION
          Exception error code URI
static URI STACK_TRACE
          Stack trace error code URI
 
Constructor Summary
FaultHelper(BaseFaultType fault)
          Creates FaultHelper with a fault.
FaultHelper(BaseFaultType fault, boolean convertStackTrace)
          Creates FaultHelper with a fault.
 
Method Summary
 void addDescription(String description)
          Adds a description to the description list of the fault.
 void addFaultCause(Throwable exception)
          Adds a fault cause to the fault.
 String[] getDescription()
          Returns descriptions of the fault.
 String getDescriptionAsString()
          Returns all the descriptions of the fault as a simple string.
 BaseFaultType getFault()
          Gets the fault.
 String getMessage()
          Gets error message of the fault.
static String getMessage(Throwable exception)
          Gets the error message of the exception.
 String getStackTrace()
          Gets stack trace of the fault.
 void printStackTrace()
          Prints stack trace of the fault to System.err.
 void printStackTrace(PrintStream s)
          Writes stack trace of the fault to stream.
 void printStackTrace(PrintWriter s)
          Writes stack trace of the fault to writer.
static void printStackTrace(Throwable exception)
          Gets the stack trace of the exception.
 void setDescription(String description)
          Sets the description of the fault.
 void setDescription(String[] description)
          Sets the description of the fault.
static BaseFaultType toBaseFault(Throwable exception)
          Converts exception to a BaseFault.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STACK_TRACE

public static final URI STACK_TRACE
Stack trace error code URI


EXCEPTION

public static final URI EXCEPTION
Exception error code URI

Constructor Detail

FaultHelper

public FaultHelper(BaseFaultType fault)
Creates FaultHelper with a fault. If the fault contains a stack trace it will be automatically converted into a chained BaseFault with an error code dialect attribute set to set to STACK_TRACE.

Parameters:
fault - fault

FaultHelper

public FaultHelper(BaseFaultType fault,
                   boolean convertStackTrace)
Creates FaultHelper with a fault.

Parameters:
fault - fault
convertStackTrace - if true and if the fault contains a stack trace it will be automatically converted into a chained BaseFault with an error code dialect attribute set to set to STACK_TRACE.
Method Detail

getFault

public BaseFaultType getFault()
Gets the fault.


getDescriptionAsString

public String getDescriptionAsString()
Returns all the descriptions of the fault as a simple string.


getDescription

public String[] getDescription()
Returns descriptions of the fault.

Returns:
the descriptions. Might be null.

setDescription

public void setDescription(String description)
Sets the description of the fault.

Parameters:
description - the new description of the fault.

setDescription

public void setDescription(String[] description)
Sets the description of the fault.

Parameters:
description - the new descriptions of the fault.

addDescription

public void addDescription(String description)
Adds a description to the description list of the fault.

Parameters:
description - the description to add.

addFaultCause

public void addFaultCause(Throwable exception)
Adds a fault cause to the fault.

Parameters:
exception - the exception to add as a cause of this fault. If the exception is of BaseFault type then it is just added as is as a fault cause. Otherwise, the exception is converted into a new BaseFault and then added as a fault cause. The new BaseFault is created with an error code dialect attribute set to EXCEPTION.

toBaseFault

public static BaseFaultType toBaseFault(Throwable exception)
Converts exception to a BaseFault.

Parameters:
exception - the exception to convert.
Returns:
If the exception is of BaseFault type then it is returned as is. Otherwise, a new BaseFault with an error code dialect attribute set to EXCEPTION.

getMessage

public static String getMessage(Throwable exception)
Gets the error message of the exception.

Parameters:
exception - if exception is of type BaseFaultType getMessage() is called to get the error message. Otherwise, getMessage operation is called on the exception.

printStackTrace

public static void printStackTrace(Throwable exception)
Gets the stack trace of the exception.

Parameters:
exception - if exception is of type BaseFaultType printStackTrace() is called to get the error message. Otherwise, printStackTrace operation is called on the exception.

printStackTrace

public void printStackTrace()
Prints stack trace of the fault to System.err. See getStackTrace() for more information.


printStackTrace

public void printStackTrace(PrintStream s)
Writes stack trace of the fault to stream. See getStackTrace() for more information.


printStackTrace

public void printStackTrace(PrintWriter s)
Writes stack trace of the fault to writer. See getStackTrace() for more information.


getMessage

public String getMessage()
Gets error message of the fault.

Returns:
If the fault has error code dialect of STACK_TRACE null is returned. If the fault has error code dialect of EXCEPTION the exception error message is returned. Otherwise, the error message is composed of all descriptions of the fault and descriptions of the chained faults.

getStackTrace

public String getStackTrace()
Gets stack trace of the fault. Note, this stack trace only contains information sent from server. It does not contain client stack trace information.

Returns:
stack trace of the fault. It includes any chained faults.


Copyright ? 1999-2003 University of Chicago and The University of Southern California. All rights reserved.