in flow/src/java/org/apache/struts/flow/core/javascript/fom/FOM_JavaScriptInterpreter.java [793:889]
public Object callController(String constName, String funName, List params, WebContext webctx)
throws Exception {
Context context = Context.enter();
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
context.setGeneratingDebug(true);
context.setCompileFunctionsWithDynamicScope(true);
context.setErrorReporter(new JSErrorReporter(getLogger()));
if (wrapFactory != null) {
context.setWrapFactory(wrapFactory);
}
LocationTrackingDebugger locationTracker = new LocationTrackingDebugger();
if (!enableDebugger) {
//FIXME: add a "tee" debugger that allows both to be used simultaneously
context.setDebugger(locationTracker, null);
}
Object ret = null;
ThreadScope thrScope = getSessionScope(webctx);
synchronized (thrScope) {
ClassLoader savedClassLoader =
Thread.currentThread().getContextClassLoader();
FOM_Flow flow = null;
Scriptable controller = null;
try {
try {
setupContext(webctx, context, thrScope);
flow = (FOM_Flow) thrScope.get("flow", thrScope);
// Register the current scope for scripts indirectly called from this function
//FOM_JavaScriptFlowHelper.setFOM_FlowScope(flow.getObjectModel(), thrScope);
if (enableDebugger) {
if (!getDebugger().isVisible()) {
// only raise the debugger window if it isn't already visible
getDebugger().setVisible(true);
}
}
int size = (params != null ? params.size() : 0);
Scriptable parameters = context.newObject(thrScope);
for (int i = 0; i < size; i++) {
Interpreter.Argument arg = (Interpreter.Argument)params.get(i);
if (arg.name == null) {
arg.name = "";
}
parameters.put(arg.name, parameters, arg.value);
}
flow.setParameters(parameters);
controller = thrScope;
if (constName != null) {
controller = context.newObject(thrScope, constName);
// We store the new controller as a variable in order to access it
// later in handleContinuation
thrScope.putInternal("controller", thrScope, controller);
}
Object fun = ScriptableObject.getProperty(controller, funName);
if (fun == Scriptable.NOT_FOUND) {
getLogger().info("Function \"javascript:" + funName + "()\" not found");
fun = ScriptableObject.getProperty(controller, MISSING_FUNCTION_NAME);
if (fun == Scriptable.NOT_FOUND) {
throw new FlowException("Unable to find either the " + funName +
" or " + MISSING_FUNCTION_NAME + " function.");
}
}
useFlash(webctx, controller);
initFlowVariables(thrScope.getFlowVariables(), webctx);
thrScope.setLock(true);
ret = ScriptRuntime.call(context, fun, controller, new Object[0], controller);
if (constName != null) {
Map map = ConversionHelper.jsobjectToMap((Scriptable)controller);
webctx.getRequestScope().putAll(map);
}
} catch (JavaScriptException ex) {
throw locationTracker.getException("Error calling flowscript function " + funName, ex);
} catch (EcmaError ee) {
throw locationTracker.getException("Error calling function " + funName, ee);
} catch (WrappedException ee) {
throw locationTracker.getException("Error calling function " + funName, ee);
}
} finally {
thrScope.setLock(false);
setSessionScope(thrScope, webctx);
if (flow != null) {
flow.popCallContext();
}
cleanupFlowVariables(thrScope.getFlowVariables());
setFlash(webctx, controller, thrScope.getFlash());
Context.exit();
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
}
return ret;
}