Search in sources :

Example 16 with EmptyStackException

use of java.util.EmptyStackException in project narayana by jbosstm.

the class ContextManager method addControlImpleHierarchy.

/*
     * Given a ControlWrapper we can create the hierarchy quickly, since
     * we have the implementation information to hand.
     */
public final boolean addControlImpleHierarchy(ControlImple which) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addControlImpleHierarchy ()");
    }
    boolean isError = false;
    try {
        ControlImple curr = which.getParentImple();
        Stack hier = new Stack();
        while (curr != null) {
            hier.push(new ControlWrapper(curr));
            curr = curr.getParentImple();
        }
        try {
            ControlWrapper wrapper = (ControlWrapper) hier.pop();
            while (wrapper != null) {
                pushAction(wrapper);
                wrapper = null;
                wrapper = (ControlWrapper) hier.pop();
            }
        } catch (EmptyStackException e) {
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager.addActionControlImple", e);
        isError = true;
    }
    return isError;
}
Also used : EmptyStackException(java.util.EmptyStackException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 17 with EmptyStackException

use of java.util.EmptyStackException in project narayana by jbosstm.

the class ContextManager method current.

/**
 * Get the transaction for the invoking thread. If there isn't one in
 * the normal thread associated data then look in the PI implementation.
 *
 * @return the current transaction for the invoking thread.
 */
public ControlWrapper current() throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::current ()");
    }
    Object arg = otsCurrent.get(ThreadUtil.getThreadId());
    ControlWrapper wrapper = null;
    if (arg != null) {
        try {
            Stack hier = (Stack) arg;
            wrapper = (ControlWrapper) hier.peek();
        } catch (EmptyStackException e) {
            e.printStackTrace();
        }
    }
    if (wrapper == null) {
        wrapper = currentPIContext();
        try {
            if (wrapper != null) {
                pushAction(wrapper);
            }
        } catch (Throwable ex) {
            jtsLogger.i18NLogger.warn_context_genfail("ContextManager.current", ex);
            throw new BAD_OPERATION();
        }
    }
    return wrapper;
}
Also used : EmptyStackException(java.util.EmptyStackException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) Stack(java.util.Stack)

Example 18 with EmptyStackException

use of java.util.EmptyStackException in project narayana by jbosstm.

the class ContextManager method current.

/**
 * Get the current transaction associated with the invoking thread. Do
 * not look in the PI thread data.
 *
 * Does not need to be synchronized since it is implicitly single-threaded.
 *
 * @return the context.
 */
public ControlWrapper current(String threadId) throws SystemException {
    Object arg = otsCurrent.get(threadId);
    ControlWrapper wrapper = null;
    if (arg != null) {
        try {
            Stack hier = (Stack) arg;
            return (ControlWrapper) hier.peek();
        } catch (EmptyStackException e) {
        }
    }
    return null;
}
Also used : EmptyStackException(java.util.EmptyStackException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Stack(java.util.Stack)

Example 19 with EmptyStackException

use of java.util.EmptyStackException in project narayana by jbosstm.

the class ContextManager method addActionControlHierarchy.

/*
     * All OTSArjuna controls have a method for getting their parent.
     */
public final boolean addActionControlHierarchy(ActionControl cont) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addActionControlHierarchy ()");
    }
    boolean isError = false;
    try {
        ActionControl actControl = cont;
        Control parentControl = actControl.getParentControl();
        Stack hier = new Stack();
        while (parentControl != null) {
            hier.push(new ControlWrapper(parentControl));
            actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(parentControl);
            if (actControl != null)
                parentControl = actControl.getParentControl();
            else
                parentControl = null;
        }
        actControl = null;
        try {
            ControlWrapper wrapper = (ControlWrapper) hier.pop();
            while (wrapper != null) {
                pushAction(wrapper);
                wrapper = null;
                wrapper = (ControlWrapper) hier.pop();
            }
        } catch (EmptyStackException e) {
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager.addActionControlHierarchy", e);
        isError = true;
    }
    return isError;
}
Also used : EmptyStackException(java.util.EmptyStackException) ActionControl(com.arjuna.ArjunaOTS.ActionControl) Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 20 with EmptyStackException

use of java.util.EmptyStackException in project DPP by pankajmore.

the class RPN method eval.

public static int eval(String rpnExpression) throws Exception {
    String delimiter = ",";
    String[] rpnList = rpnExpression.split(delimiter);
    Stack<Integer> stack = new Stack<>();
    for (String s : rpnList) {
        try {
            int x = Integer.parseInt(s);
            stack.push(x);
        } catch (NumberFormatException e) {
            int y = stack.pop();
            int x = stack.pop();
            int res;
            switch(s) {
                case "+":
                    res = x + y;
                    break;
                case "-":
                    res = x - y;
                    break;
                case "*":
                    res = x * y;
                    break;
                case "/":
                    res = x / y;
                    break;
                default:
                    throw new Exception(String.format("Unknown operator encountered : %s", s));
            }
            stack.push(res);
        }
    }
    try {
        int res = stack.pop();
        if (!stack.isEmpty())
            throw new Exception("Extra input");
        return res;
    } catch (EmptyStackException e) {
        throw new Exception("Incomplete input");
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Aggregations

EmptyStackException (java.util.EmptyStackException)47 Stack (java.util.Stack)13 Test (org.junit.Test)6 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)5 Callable (java.util.concurrent.Callable)5 NamespaceSupport (org.xml.sax.helpers.NamespaceSupport)5 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)3 IOException (java.io.IOException)3 ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)2 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)2 ArrayList (java.util.ArrayList)2 SystemException (org.omg.CORBA.SystemException)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ActionControl (com.arjuna.ArjunaOTS.ActionControl)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 FileOptions (com.laytonsmith.core.compiler.FileOptions)1 KeywordList (com.laytonsmith.core.compiler.KeywordList)1 CDecimal (com.laytonsmith.core.constructs.CDecimal)1