in flow/src/java/org/apache/struts/flow/core/javascript/fom/FOM_JavaScriptInterpreter.java [620:695]
private void setupContext(WebContext webctx, Context context,
ThreadScope thrScope)
throws Exception {
// Try to retrieve the scope object from the session instance. If
// no scope is found, we create a new one, but don't place it in
// the session.
//
// When a user script "creates" a session using
// flow.createSession() in JavaScript, the thrScope is placed in
// the session object, where it's later retrieved from here. This
// behaviour allows multiple JavaScript functions to share the
// same global scope.
FOM_Flow flow = (FOM_Flow) thrScope.get("flow", thrScope);
long lastExecTime = ((Long) thrScope.get(LAST_EXEC_TIME,
thrScope)).longValue();
boolean needsRefresh = false;
if (reloadScripts) {
long now = System.currentTimeMillis();
if (now >= lastTimeCheck + checkTime) {
needsRefresh = true;
}
lastTimeCheck = now;
}
// We need to setup the FOM_Flow object according to the current
// request. Everything else remains the same.
ClassLoader contextClassloader = Thread.currentThread().getContextClassLoader();
thrScope.setupPackages(contextClassloader);
flow.pushCallContext(this, webctx, getLogger(), null);
// Check if we need to compile and/or execute scripts
synchronized (compiledScripts) {
List execList = new ArrayList();
// If we've never executed scripts in this scope or
// if reload-scripts is true and the check interval has expired
// or if new scripts have been specified in the sitemap,
// then create a list of scripts to compile/execute
if (lastExecTime == 0 || needsRefresh || needResolve.size() > 0) {
topLevelScripts.addAll(needResolve);
if (lastExecTime != 0 && !needsRefresh) {
execList.addAll(needResolve);
} else {
execList.addAll(topLevelScripts);
}
needResolve.clear();
}
// Compile all the scripts first. That way you can set breakpoints
// in the debugger before they execute.
for (int i = 0, size = execList.size(); i < size; i++) {
String sourceURI = (String)execList.get(i);
ScriptSourceEntry entry =
(ScriptSourceEntry)compiledScripts.get(sourceURI);
if (entry == null) {
Source src = this.sourceresolver.resolveURI(sourceURI);
entry = new ScriptSourceEntry(src);
compiledScripts.put(sourceURI, entry);
}
// Compile the script if necessary
entry.getScript(context, this.scope, needsRefresh, this);
}
// Execute the scripts if necessary
for (int i = 0, size = execList.size(); i < size; i++) {
String sourceURI = (String) execList.get(i);
ScriptSourceEntry entry =
(ScriptSourceEntry) compiledScripts.get(sourceURI);
long lastMod = entry.getSource().getLastModified();
Script script = entry.getScript(context, this.scope, false, this);
if (lastExecTime == 0 || lastMod > lastExecTime) {
script.exec(context, thrScope);
thrScope.onExec();
}
}
}
}