Example usage for java.util EmptyStackException getLocalizedMessage

List of usage examples for java.util EmptyStackException getLocalizedMessage

Introduction

In this page you can find the example usage for java.util EmptyStackException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.dspace.core.Context.java

/**
 * Restore the previous Authorisation System State. If the state was not
 * changed by the current caller a warning will be displayed in log. Use:
 * <code>// w  w w  . jav a  2s  . c  o m
 *     mycontext.turnOffAuthorisationSystem();
 *     some java code that require no authorisation check
 *     mycontext.restoreAuthSystemState(); 
 * </code> If Context debug is enabled, the correct sequence calling will be
 * checked and a warning will be displayed if not.
 */
public void restoreAuthSystemState() {
    Boolean previousState;
    try {
        previousState = authStateChangeHistory.pop();
    } catch (EmptyStackException ex) {
        log.warn(LogManager.getHeader(this, "restore_auth_sys_state",
                "not previous state info available " + ex.getLocalizedMessage()));
        previousState = Boolean.FALSE;
    }
    if (log.isDebugEnabled()) {
        Thread currThread = Thread.currentThread();
        StackTraceElement[] stackTrace = currThread.getStackTrace();
        String caller = stackTrace[stackTrace.length - 1].getClassName();

        String previousCaller = (String) authStateClassCallHistory.pop();

        // if previousCaller is not the current caller *only* log a warning
        if (!previousCaller.equals(caller)) {
            log.warn(LogManager.getHeader(this, "restore_auth_sys_state",
                    "Class: " + caller + " call restore but previous state change made by " + previousCaller));
        }
    }
    ignoreAuth = previousState.booleanValue();
}