/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.utils;

import java.util.Date;

/**
 * HL7Exception is the super class of all HL7 exceptions those can be thrown
 * during the execution of the method. 
 */
public class HL7Exception extends RuntimeException 
{
	private static final long serialVersionUID = 1L;
	private EnumErrorCode enumErrorCode;
	
	/**
	 * Constructs a new HL7 Exception with null as its detail message
	 */
	public HL7Exception()
	{
	}

	/**
	 * Constructs a new HL7 Exception with the specified detail message and cause
	 * @param strMessage -  the detail message 
	 * @param cause - the cause 
	 */
	public HL7Exception(String strMessage, Throwable cause)
	{
		super(strMessage,cause);
	}

	/**
	 * Constructs a new HL7 Exception with the specified cause.
	 * This constructor is useful for runtime exceptions that are little more than wrappers for other throwables. 
	 * @param cause - the cause (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
	 */
	public HL7Exception(Throwable cause)
	{
		super(cause);
	}

	/**
	 * Constructs a new HL7 Exception with the specified detail message. 
	 * @param strMessage - the detail message.
	 */
	public HL7Exception(String strMessage)
	{
		super(strMessage);
	}

	/**
	 * Sets Error Code corresponding to exception occured. 
	 * @param enumErrorCode contains errror codes raised by SDK.
	 */
	public void setErrorCode(EnumErrorCode enumErrorCode)
	{
		this.enumErrorCode = enumErrorCode;
	}

	/**
	 * Retrieves Error Code.
	 * @return EnumErrorCode - undelying Error Code
	 */
	public EnumErrorCode getErrorCode()
	{
		return this.enumErrorCode;
	}
	
	/**
	 * Returns the detail message string of this throwable. 
	 * @return String - the detail message string of this Throwable instance (which may be null).
	 */
	public String getMessage()
	{
		return new Date().toString() +":"+super.getMessage();
	}
}
