/*
 * This file is part of DebGen Biobank Software developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 * Copyright ASTRID Research Inc., Hungary, 2009-2011.
 *
 * ASTRID Research
 * Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
 * Phone: +36-52-533-173        Fax: +36-52-533-174
 * Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DebGen Biobank Software project.
 * URLS:
 * Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
 */
package hu.astrid.debgen.exception;

import hu.astrid.debgen.localization.service.LocalizationService;
import java.util.Date;

/**
 * Exception to nest other exceptions into this special type
 * @author inagy
 */
public class ServerSideException extends DebGenException {

    /**
     * The date when the exception was thrown
     */
    private Date threw;
    /**
     * The message of the exception
     */
    private String message;
    /**
     * Te original exception, which is nested
     */
    private Throwable nestedException;

    /**
     * Default constructor (sets only the date)
     */
    public ServerSideException() {
        this.threw = new Date();
    }

    /**
     * Constructor to set the message
     * @param message The message of the exception.
     */
    public ServerSideException(String message) {
        this(message, new DebGenException(message));
    }

    /**
     * Constructor to set the nested exception too. (And the default message.)
     * @param exception The nested exception.
     */
    public ServerSideException(Throwable exception) {
        this(exception.getLocalizedMessage(), exception);
    }

    /**
     * Constructor to set the nested exception and a custom message too.
     * @param message
     * @param nestedException
     */
    public ServerSideException(String message, Throwable nestedException) {
        this();
        this.message = message;
        this.nestedException = nestedException;
    }

    /**
     * @return the message
     */
    @Override
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @return the nestedException
     */
    public Throwable getNestedException() {
        return nestedException;
    }

    /**
     * @param nestedException the nestedException to set
     */
    public void setNestedException(Throwable nestedException) {
        this.nestedException = nestedException;
    }

    /**
     * Returns the errors unique ID
     * @return The unique ID of the error
     */
    public String getErrorNumber() {
        return Long.toHexString(threw.getTime());
    }

}
