package usda.weru.util;

import javolution.context.Context;

/**
 * Context to track when files are loaded for reports.  We don't want to show warnings or change the data on the fly.
 * @author Joseph Levin <joelevin@weru.ksu.edu>
 */
public class ReportContext extends Context {

    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @Override
    protected void enterAction() {

    }

    /**
     *
     */
    @Override
    protected void exitAction() {

    }

    /**
     *
     */
    public static void enter() {
        Context.enter(ReportContext.class);
    }

    /**
     *
     */
    public static void exit() {
        Context.exit(ReportContext.class);
    }

    /**
     *
     * @return
     */
    public static ReportContext getCurrent() {
        for (Context ctx = Context.getCurrent(); ctx != null; ctx = ctx.getOuter()) {
            if (ctx instanceof ReportContext) {
                return (ReportContext) ctx;
            }
        }
        //TODO: add a default context
        return null;
    }

    /**
     *
     * @return
     */
    public static boolean isInReport() {
        return getCurrent() != null;
    }

}
