//==========================================================================
//
//  Copyright  [2006] Oracle Corporation.  All rights reserved.
//
//==========================================================================
package oracle.e1.bssvfoundation.exception;

import java.io.Serializable;

import oracle.e1.bssvfoundation.base.IContext;
import oracle.e1.bssvfoundation.impl.base.Context;
import oracle.e1.bssvfoundation.util.E1Message;

/**
 *  The base Exception class for Published Business Services. 
 *  All Published Business Service exceptions must extend from this class.
 */
 
 
public class BusinessServiceException extends Exception implements Serializable
{
  private String requestID;
  private String message;

  /**
   * Required default constructor is required for use in a web service, but this constructor should
   * not be called by Published Business Services. 
   */
  public BusinessServiceException()
  {}
  
  /**
   * Two argument constructor required for WLS
   * @param requestID
   * @param message
   */
  public BusinessServiceException(String requestID, String message)
  {
    super();
    this.requestID = requestID;
    this.message = message;
  }
  
  /**
   * Constructor for Published Business Service Exception.
   * Use this constructor when an exception needs to be created with a single
   * message.
   * @param message  Exception message text.
   * @param context   The context class, which holds a reference to the default transaction as well
   * as a unique identifier for the request.
   */
  public BusinessServiceException(String message, IContext context)
  {
    super();
    this.message = message;
    
    this.requestID = context.getRequestID();
    
    ((Context)context).cancelDefaultConnection();

    context.getBSSVLogger().app(context, "BusinessServiceException: \n" + message, null, null, this);
  }
    
  /**
   * Overrides getMessage from super class. Returns the exception message.
   * @return String
   */
  public String getMessage()
  {
    return E1Message.sLineSeparator + message;
  }

    /**
     * Public accessor methods are necessary for Web Services calls, but this method should not be 
     * used by application development.
     */
    public void setRequestID(String mRequestID) {
        this.requestID = mRequestID;
    }

    /**
     * Public accessor methods are necessary for Web Services calls, but this method should not be 
     * used by application development.
     */
    public String getRequestID() {
        return requestID;
    }

    /**
     * Public accessor methods are necessary for Web Services calls, but this method should not be 
     * used by application development.
     */
    public void setMessage(String mMessage) {
        this.message = mMessage;
    }
	
	/**
	* Method used by WAS to get the error information
	*/
	public String getFaultInfo() 
	{ 
		return E1Message.sLineSeparator + message;
	}
}
