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;
}
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;
}
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;
}
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;
}
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");
}
}
Aggregations