coliver 2003/07/17 10:12:52
Modified: src/java/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java FOM_JavaScriptInterpreter.java
Log:
Only use session if JS global variables are written
Revision Changes Path
1.4 +2 -1
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
Index: FOM_Cocoon.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FOM_Cocoon.java 10 Jul 2003 11:40:57 -0000 1.3
+++ FOM_Cocoon.java 17 Jul 2003 17:12:52 -0000 1.4
@@ -869,4 +869,5 @@
result.getClassName()));
return result;
}
+
}
1.3 +53 -12
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
Index: FOM_JavaScriptInterpreter.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FOM_JavaScriptInterpreter.java 14 Jul 2003 09:54:13 -0000 1.2
+++ FOM_JavaScriptInterpreter.java 17 Jul 2003 17:12:52 -0000 1.3
@@ -127,6 +127,7 @@
*/
Global scope;
+
/**
* List of <code>String</code> objects that represent files to be
* read in by the JavaScript interpreter.
@@ -272,11 +273,18 @@
scope = (Scriptable)userScopes.get(uriPrefix);
}
if (scope == null) {
- return setSessionScope(environment, createThreadScope());
+ scope = createThreadScope();
}
return scope;
}
+ void updateSession(Environment env, Scriptable scope) throws Exception {
+ ThreadScope thrScope = (ThreadScope)scope;
+ if (thrScope.useSession) {
+ setSessionScope(env, scope);
+ }
+ }
+
/**
* Associates a JavaScript scope, a Scriptable object, with the URI
* prefix of the current sitemap, as returned by the [EMAIL PROTECTED]
@@ -296,18 +304,47 @@
userScopes = new HashMap();
session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
}
-
String uriPrefix = environment.getURIPrefix();
+ System.out.println("Session: setting :" + uriPrefix + ": " +
System.identityHashCode(scope));
userScopes.put(uriPrefix, scope);
return scope;
}
+ public static class ThreadScope extends ScriptableObject {
+
+ /* true if this scope has assigned any global vars */
+ boolean useSession = false;
+
+ public ThreadScope() {
+ }
+
+ public String getClassName() {
+ return "ThreadScope";
+ }
+
+ public void put(String name, Scriptable start,
+ Object value) {
+ useSession = true;
+ super.put(name, start, value);
+ }
+
+ public void put(int index, Scriptable start,
+ Object value) {
+ useSession = true;
+ super.put(index, start, value);
+ }
+
+ void reset() {
+ useSession = false;
+ }
+ }
+
private Scriptable createThreadScope()
throws Exception {
org.mozilla.javascript.Context context =
org.mozilla.javascript.Context.getCurrentContext();
- Scriptable thrScope = context.newObject(scope);
+ Scriptable thrScope = new ThreadScope();
thrScope.setPrototype(scope);
// We want 'thrScope' to be a new top-level scope, so set its
@@ -392,8 +429,6 @@
}
needResolve.clear();
}
- thrScope.put(LAST_EXEC_TIME, thrScope,
- new Long(System.currentTimeMillis()));
// 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++) {
@@ -417,6 +452,9 @@
Script script = entry.getScript(context, this.scope, false);
if (lastExecTime == 0 || lastMod > lastExecTime) {
script.exec(context, thrScope);
+ thrScope.put(LAST_EXEC_TIME, thrScope,
+ new Long(System.currentTimeMillis()));
+ ((ThreadScope)thrScope).reset();
}
}
}
@@ -497,7 +535,7 @@
}
int size = (params != null ? params.size() : 0);
Object[] funArgs = new Object[size];
- Scriptable parameters = context.newObject(thrScope);
+ Scriptable parameters = context.newObject(thrScope);
if (size != 0) {
for (int i = 0; i < size; i++) {
Interpreter.Argument arg =
(Interpreter.Argument)params.get(i);
@@ -536,6 +574,7 @@
}
throw new CascadingRuntimeException(ee.getMessage(), ee);
} finally {
+ updateSession(environment, thrScope);
cocoon.invalidate();
Context.exit();
}
@@ -576,11 +615,11 @@
int size = (params != null ? params.size() : 0);
Scriptable parameters = context.newObject(kScope);
if (size != 0) {
- for (int i = 0; i < size; i++) {
- Interpreter.Argument arg =
(Interpreter.Argument)params.get(i);
- parameters.put(arg.name, parameters, arg.value);
- }
- }
+ for (int i = 0; i < size; i++) {
+ Interpreter.Argument arg =
(Interpreter.Argument)params.get(i);
+ parameters.put(arg.name, parameters, arg.value);
+ }
+ }
cocoon.setParameters(parameters);
Object[] args = new Object[] {k,
cocoon.makeWebContinuation(wk)};
@@ -611,6 +650,7 @@
}
throw new CascadingRuntimeException(ee.getMessage(), ee);
} finally {
+ updateSession(environment, kScope);
cocoon.invalidate();
Context.exit();
}
@@ -673,4 +713,5 @@
kont);
}
}
+
}