package com.cloudcc.core;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class BaseException extends Exception {
    private static final long serialVersionUID = -960185495264426709L;
    public static final long ERROR_PAGE = 1L;
    public static final long RETURN_PAGE = 2L;
    public static final long RETURN_BYPAGE = 3L;
    private Throwable rootCause = null;
    private List exceptions = new ArrayList();
    private List messageArgs = new ArrayList();
    private String messageKey = null;
    private long displayType = 1L;
    private String returnForward = null;

    protected BaseException() {
    }

    protected BaseException(String errmsg) {
        super(errmsg);
        this.messageArgs.add(errmsg);
    }

    protected BaseException(Throwable cause) {
        super(cause);
        this.rootCause = cause;
    }

    protected BaseException(String errmsg, Throwable cause) {
        super(errmsg, cause);
        this.messageArgs.add(errmsg);
        this.rootCause = cause;
    }

    protected BaseException(List args) {
        this.messageArgs = args;
    }

    protected BaseException(String msgKey, List args) {
        this.messageKey = msgKey;
        this.messageArgs = args;
    }

    public void printStackTrace(PrintWriter writer) {
        super.printStackTrace(writer);
        if (this.getRootCause() != null) {
            this.getRootCause().printStackTrace(writer);
        }

        writer.flush();
    }

    public void printStackTrace(PrintStream outStream) {
        this.printStackTrace(new PrintWriter(outStream));
    }

    public void printStackTrace() {
        this.printStackTrace(System.err);
    }

    public Throwable getRootCause() {
        return this.rootCause;
    }

    public String getMessageKey() {
        return this.messageKey;
    }

    public List getExceptions() {
        return this.exceptions;
    }

    public void addException(BaseException ex) {
        this.exceptions.add(ex);
    }

    public List getMessageArgs() {
        return this.messageArgs;
    }

    public long getDisplayType() {
        return this.displayType;
    }

    public void setDisplayType(long displayType) {
        this.displayType = displayType;
    }

    public String getReturnForward() {
        return this.returnForward;
    }

    public void setReturnForward(String returnForward) {
        this.returnForward = returnForward;
    }
}