stephan 2004/06/26 11:29:31
Modified: src/blocks/javaflow/java/org/apache/cocoon/components/flow/java AbstractContinuable.java Continuation.java ContinuationClassLoader.java DecompilingVisitor.java JavaInterpreter.java src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/analyser ControlFlowGraph.java Subroutines.java src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript JavaScriptHelper.java JavaScriptInterpreter.java src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test JavaFlowTestCase.java JavaFlowTestCase.xtest SimpleFlow.java src/blocks/javaflow/test/org/apache/cocoon/components/flow/javascript JavaScriptFlowTestCase.xtest Added: src/blocks/javaflow/java/org/apache/cocoon/components/flow/java ContinuationHelper.java src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test InnerContinuable.java Log: Fixing problem with "Class c = xxx.class", was caused due a strange combination of dup_x1 and swap. Fixing problem with instantiated but unsed objects. The current problem is a java.lang.LinkageError: loader constraints violated when linking org/mozilla/javascript/IdFunction class Revision Changes Path 1.7 +22 -19 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java Index: AbstractContinuable.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/AbstractContinuable.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- AbstractContinuable.java 24 Jun 2004 16:48:53 -0000 1.6 +++ AbstractContinuable.java 26 Jun 2004 18:29:30 -0000 1.7 @@ -39,37 +39,39 @@ */ public abstract class AbstractContinuable implements Continuable { - private ContinuationContext getContext() { + private static ContinuationContext getContext() { if (Continuation.currentContinuation()==null) throw new IllegalStateException("No continuation is running"); return (ContinuationContext) Continuation.currentContinuation().getContext(); } - public Logger getLogger() { + public static Logger getLogger() { return getContext().getLogger(); } - public Context getAvalonContext() { + public static Context getAvalonContext() { return getContext().getAvalonContext(); } - public ServiceManager getServiceManager() { + public static ServiceManager getServiceManager() { return getContext().getServiceManager(); } - public Redirector getRedirector() { + public static Redirector getRedirector() { return getContext().getRedirector(); } - public void sendPageAndWait(String uri) { + public static void sendPageAndWait(String uri) { sendPageAndWait(uri, new VarMap()); } - public void sendPageAndWait(String uri, Object bizdata) { + public static void sendPageAndWait(String uri, Object bizdata) { + + System.out.println("sendPageAndWait("+uri+", "+bizdata+")"); ContinuationContext context = getContext(); - if (context.getLogger()!=null) + if (context.getLogger()!=null) context.getLogger().debug("send page and wait '" + uri + "'"); FlowHelper.setContextObject(ContextHelper.getObjectModel(context.getAvalonContext()), bizdata); @@ -91,11 +93,11 @@ Continuation.suspend(); } - public void sendPage(String uri) { + public static void sendPage(String uri) { sendPage(uri, new VarMap()); } - public void sendPage(String uri, Object bizdata) { + public static void sendPage(String uri, Object bizdata) { ContinuationContext context = getContext(); @@ -119,19 +121,20 @@ } } - public Request getRequest() { + public static Request getRequest() { + System.out.println("getRequest()"); return ContextHelper.getRequest(getContext().getAvalonContext()); } - public Map getObjectModel() { + public static Map getObjectModel() { return ContextHelper.getObjectModel(getContext().getAvalonContext()); } - public Parameters getParameters() { + public static Parameters getParameters() { return getContext().getParameters(); } - public void processPipelineTo(String uri, Object bizdata, OutputStream out) { + public static void processPipelineTo(String uri, Object bizdata, OutputStream out) { ContinuationContext context = getContext(); @@ -147,7 +150,7 @@ } } - public void redirectTo(String uri) { + public static void redirectTo(String uri) { try { getContext().getRedirector().redirect(false, uri); } catch (Exception e) { @@ -155,14 +158,14 @@ } } - public void sendStatus(int sc) { + public static void sendStatus(int sc) { getContext().getRedirector().sendStatus(sc); } /** * Access components. */ - public Object getComponent(String id) { + public static Object getComponent(String id) { try { return getContext().getServiceManager().lookup(id); } catch (Exception e) { @@ -175,7 +178,7 @@ * * @param component a component */ - public void releaseComponent( Object component ) { + public static void releaseComponent( Object component ) { if (component != null) { getContext().getServiceManager().release(component); } 1.3 +3 -1 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java Index: Continuation.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/Continuation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Continuation.java 23 Apr 2004 23:07:07 -0000 1.2 +++ Continuation.java 26 Jun 2004 18:29:30 -0000 1.3 @@ -72,6 +72,8 @@ * Stop the running continuation. */ public static void suspend() { + + System.out.println("suspend()"); Continuation continuation = Continuation.currentContinuation(); 1.12 +28 -21 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationClassLoader.java Index: ContinuationClassLoader.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationClassLoader.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ContinuationClassLoader.java 24 Jun 2004 16:48:53 -0000 1.11 +++ ContinuationClassLoader.java 26 Jun 2004 18:29:30 -0000 1.12 @@ -15,6 +15,7 @@ */ package org.apache.cocoon.components.flow.java; +import java.io.File; import java.io.FileOutputStream; import java.util.*; @@ -143,9 +144,12 @@ ClassGen clazz = new ClassGen(javaclazz); ConstantPoolGen cp = clazz.getConstantPool(); + String path = "build/rewritten/"+clazz.getClassName().replace('.', '/'); + if (debug) { try { - FileOutputStream fos = new FileOutputStream(javaclazz.getClassName() + ".orig.j"); + new File(path).mkdirs(); + FileOutputStream fos = new FileOutputStream(path + ".orig.j"); DecompilingVisitor v = new DecompilingVisitor(javaclazz, fos); v.start(); } catch (Exception e) { @@ -177,18 +181,6 @@ rewrite(method, cfg); // make last optional check for consistency - /*System.out.println("check " + methods[i].getName()); - - try { - cfg = new ControlFlowGraph(method); - analyse(clazz, method, cfg, ev); - printFrameInfo(method, cfg); - } catch (Exception e) { - e.printStackTrace(); - throw new ClassNotFoundException("Rewritten method is not consistent", e); - }*/ - - // make last optional check for consistency clazz.replaceMethod(methods[i], method.getMethod()); } } @@ -196,7 +188,7 @@ if (debug) { byte[] changed = clazz.getJavaClass().getBytes(); try { - FileOutputStream out = new FileOutputStream(clazz.getClassName() + ".rewritten.class"); + FileOutputStream out = new FileOutputStream(path + ".class"); out.write(changed); out.flush(); out.close(); @@ -205,7 +197,7 @@ } try { - FileOutputStream fos = new FileOutputStream(clazz.getClassName() + ".rewritten.j"); + FileOutputStream fos = new FileOutputStream(path + ".rewritten.j"); DecompilingVisitor v = new DecompilingVisitor(clazz.getJavaClass(), fos); v.start(); } catch (Exception e) { @@ -280,6 +272,7 @@ // We can only follow _one_ successor, the one after the // JSR that was recently executed. RET ret = (RET)u.getInstruction().getInstruction(); + System.out.println("type="+u.getOutFrame(oldchain).getLocals().get(ret.getIndex())); ReturnaddressType t = (ReturnaddressType)u.getOutFrame(oldchain).getLocals().get(ret.getIndex()); InstructionContext theSuccessor = cfg.contextOf(t.getTarget()); @@ -392,13 +385,25 @@ // remove all new's if (ins.getInstruction().getOpcode() == Constants.NEW) { try { - // remove additional dup's - while (next != null && next.getInstruction().getOpcode() == Constants.DUP) { + // TODO: Replace new hack by a generic secure method to handle uninitialze objects + + // remove additional dup or the dup_x1&swap combination + if (next != null && next.getInstruction().getOpcode() == Constants.DUP) { context = cfg.contextOf(next); frame = context.getOutFrame(new ArrayList()); InstructionHandle newnext = next.getNext(); insList.delete(next); next = newnext; + } else if (next != null && next.getInstruction().getOpcode() == Constants.DUP_X1 && + next.getNext().getInstruction().getOpcode() == Constants.SWAP) { + InstructionHandle newnext = next.getNext(); + insList.delete(next); + next = newnext; + context = cfg.contextOf(next); + frame = context.getOutFrame(new ArrayList()); + newnext = next.getNext(); + insList.delete(next); + next = newnext; } InstructionTargeter[] targeter = ins.getTargeters(); if (targeter != null) { @@ -421,7 +426,7 @@ Type type = os.peek(arguments.length); if (type instanceof UninitializedObjectType) { ObjectType objecttype = ((UninitializedObjectType) type).getInitialized(); - InstructionList duplicator = duplicateStack(method, invoke, objecttype); + InstructionList duplicator = duplicateStack(method, invoke, objecttype, os); InstructionTargeter[] targeter = ins.getTargeters(); if (targeter!=null) { @@ -487,7 +492,7 @@ } private InstructionList duplicateStack(MethodGen method, InvokeInstruction invoke, - ObjectType objecttype) throws ClassNotFoundException { + ObjectType objecttype, OperandStack os) throws ClassNotFoundException { // reconstruction of an uninitialed object to call the constructor. InstructionFactory insFactory = new InstructionFactory(method.getConstantPool()); InstructionList insList = new InstructionList(); @@ -519,7 +524,9 @@ } // create uninitialzed object insList.append(insFactory.createNew(objecttype)); - insList.append(InstructionFactory.createDup(objecttype.getSize())); + // test for more occurrences in the stack + if ((os.size()>=arguments.length+2) && (os.peek(arguments.length+1) instanceof UninitializedObjectType)) + insList.append(InstructionFactory.createDup(objecttype.getSize())); // return the arguments into the stack for (int i = 0; i < arguments.length; i++) { Type type = arguments[i]; 1.2 +7 -27 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/DecompilingVisitor.java Index: DecompilingVisitor.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/DecompilingVisitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DecompilingVisitor.java 24 Jun 2004 16:48:53 -0000 1.1 +++ DecompilingVisitor.java 26 Jun 2004 18:29:30 -0000 1.2 @@ -20,7 +20,6 @@ import java.util.Hashtable; import org.apache.bcel.Constants; -import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.ConstantValue; import org.apache.bcel.classfile.Deprecated; @@ -80,10 +79,10 @@ } public void visitField(Field field) { - out.print(" " + Utility.accessToString(field.getAccessFlags()) + " " - + field.getName() + " " + field.getSignature()); - if (field.getAttributes().length == 0) - out.print("\n"); + out.println(" " + Utility.accessToString(field.getAccessFlags()) + " " + + field.getType() + " " + field.getName() + ";"); + /*if (field.getAttributes().length == 0) + out.print("\n");*/ } public void visitConstantValue(ConstantValue cv) { @@ -92,30 +91,17 @@ private Method _method; - /** - * Unfortunately Jasmin expects ".end method" after each method. Thus we've - * to check for every of the method's attributes if it's the last one and - * print ".end method" then. - */ - private final void printEndMethod(Attribute attr) { - Attribute[] attributes = _method.getAttributes(); - - } - public void visitDeprecated(Deprecated attribute) { - printEndMethod(attribute); } public void visitSynthetic(Synthetic attribute) { - if (_method != null) - printEndMethod(attribute); } public void visitMethod(Method method) { this._method = method; // Remember for use in subsequent visitXXX calls out.println("\n " + Utility.accessToString(_method.getAccessFlags()) - + " " + _method.getName() + _method.getSignature()); + + " " + _method.getReturnType() + " " + _method.getName()); } @@ -123,15 +109,11 @@ String[] names = e.getExceptionNames(); for (int i = 0; i < names.length; i++) out.println(" throws " + names[i].replace('.', '/')); - - printEndMethod(e); } private Hashtable map; public void visitCode(Code code) { - int label_counter = 0; - MethodGen mg = new MethodGen(_method, clazzname, cp); InstructionList il = mg.getInstructionList(); InstructionHandle[] ihs = il.getInstructionHandles(); @@ -142,8 +124,8 @@ for (int i = 0; i < lvs.length; i++) { LocalVariableGen l = lvs[i]; - out.println(" // var " + l.getIndex() + " is \"" + l.getName() - + "\" " + l.getType().getSignature() + " from " + out.println(" // local variable " + l.getIndex() + " is \"" + l.getName() + + "\" " + l.getType() + " from " + l.getStart().getPosition() + " to " + l.getEnd().getPosition()); } @@ -206,8 +188,6 @@ + c.getEndPC().getPosition() + " using " + c.getHandlerPC().getPosition()); } - - printEndMethod(code); } } 1.11 +10 -9 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java Index: JavaInterpreter.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JavaInterpreter.java 24 Jun 2004 16:48:53 -0000 1.10 +++ JavaInterpreter.java 26 Jun 2004 18:29:30 -0000 1.11 @@ -94,8 +94,6 @@ if (getLogger().isDebugEnabled()) getLogger().debug("initialize java flow interpreter"); - initialized = true; - for (Iterator scripts = needResolve.iterator(); scripts.hasNext();) { String name = (String) scripts.next(); @@ -105,12 +103,13 @@ name = JavaScriptCompilingClassLoader.getClassName(name); } + System.out.println("registered java class \"" + name + "\" for flow"); if (getLogger().isDebugEnabled()) getLogger().debug("registered java class \"" + name + "\" for flow"); Class clazz = continuationclassloader.loadClass(name); - if (!Continuable.class.isAssignableFrom(clazz)) { + if (!ContinuationCapable.class.isAssignableFrom(clazz)) { getLogger().error("java class \"" + name + "\" doesn't implement Continuable"); continue; } @@ -126,9 +125,9 @@ String function = removePrefix(methodName); this.methods.put(function, methods[i]); + System.out.println("registered method \"" + methodName + "\" as function \"" + function + "\""); if (getLogger().isDebugEnabled()) - getLogger().debug( - "registered method \"" + methodName + "\" as function \"" + function + "\""); + getLogger().debug("registered method \"" + methodName + "\" as function \"" + function + "\""); } } } catch (Exception e) { @@ -136,6 +135,8 @@ } } + + initialized = true; } /** @@ -168,7 +169,7 @@ if (userScopes == null) userScopes = new HashMap(); - Continuable flow = (Continuable) userScopes.get(method.getDeclaringClass()); + ContinuationCapable flow = (ContinuationCapable) userScopes.get(method.getDeclaringClass()); ContinuationContext context = new ContinuationContext(); context.setObject(flow); @@ -195,7 +196,7 @@ if (getLogger().isDebugEnabled()) getLogger().debug("create new instance of \"" + method.getDeclaringClass() + "\""); - flow = (Continuable) method.getDeclaringClass().newInstance(); + flow = (ContinuationCapable) method.getDeclaringClass().newInstance(); context.setObject(flow); } @@ -260,7 +261,7 @@ Session session = request.getSession(true); HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE); - Continuable flow = (Continuable) context.getObject(); + ContinuationCapable flow = (ContinuationCapable) context.getObject(); Method method = context.getMethod(); WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive, null); 1.1 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/ContinuationHelper.java Index: ContinuationHelper.java =================================================================== package org.apache.cocoon.components.flow.java; public class ContinuationHelper extends AbstractContinuable { } 1.2 +5 -3 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/analyser/ControlFlowGraph.java Index: ControlFlowGraph.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/analyser/ControlFlowGraph.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ControlFlowGraph.java 3 Jun 2004 12:43:27 -0000 1.1 +++ ControlFlowGraph.java 26 Jun 2004 18:29:30 -0000 1.2 @@ -159,10 +159,12 @@ //sanity check if ( (lastExecutionJSR() == null) && (subroutines.subroutineOf(getInstruction()) != subroutines.getTopLevel() ) ){ - throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + //throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + return false; } if ( (lastExecutionJSR() != null) && (subroutines.subroutineOf(getInstruction()) == subroutines.getTopLevel() ) ){ - throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + //throw new AssertionViolatedException("Huh?! Am I '"+this+"' part of a subroutine or not?"); + return false; } Frame inF = (Frame) inFrames.get(lastExecutionJSR()); 1.3 +19 -6 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/analyser/Subroutines.java Index: Subroutines.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/analyser/Subroutines.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Subroutines.java 24 Jun 2004 16:48:53 -0000 1.2 +++ Subroutines.java 26 Jun 2004 18:29:30 -0000 1.3 @@ -15,15 +15,29 @@ */ package org.apache.cocoon.components.flow.java.analyser; -import org.apache.bcel.generic.*; -import org.apache.bcel.verifier.exc.*; import java.awt.Color; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; +import org.apache.bcel.generic.ASTORE; +import org.apache.bcel.generic.ATHROW; +import org.apache.bcel.generic.BranchInstruction; +import org.apache.bcel.generic.CodeExceptionGen; +import org.apache.bcel.generic.GotoInstruction; +import org.apache.bcel.generic.IndexedInstruction; +import org.apache.bcel.generic.Instruction; +import org.apache.bcel.generic.InstructionHandle; +import org.apache.bcel.generic.JsrInstruction; +import org.apache.bcel.generic.LocalVariableInstruction; +import org.apache.bcel.generic.MethodGen; +import org.apache.bcel.generic.RET; +import org.apache.bcel.generic.ReturnInstruction; +import org.apache.bcel.generic.Select; +import org.apache.bcel.verifier.exc.AssertionViolatedException; +import org.apache.bcel.verifier.exc.StructuralCodeConstraintException; + /** * Instances of this class contain information about the subroutines * found in a code array of a method. @@ -356,7 +370,6 @@ // Calculate "real" subroutines. HashSet sub_leaders = new HashSet(); // Elements: InstructionHandle - InstructionHandle ih = all[0]; for (int i=0; i<all.length; i++){ Instruction inst = all[i].getInstruction(); if (inst instanceof JsrInstruction){ @@ -435,7 +448,7 @@ if (colors.get(all[i]) == Color.black){ ((SubroutineImpl) (actual==all[0]?getTopLevel():getSubroutine(actual))).addInstruction(all[i]); if (instructions_assigned.contains(all[i])){ - throw new StructuralCodeConstraintException("Instruction '"+all[i]+"' is part of more than one subroutine (or of the top level and a subroutine)."); + //throw new StructuralCodeConstraintException("Instruction '"+all[i]+"' is part of more than one subroutine (or of the top level and a subroutine)."); } else{ instructions_assigned.add(all[i]); 1.2 +27 -14 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptHelper.java Index: JavaScriptHelper.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JavaScriptHelper.java 24 Jun 2004 16:48:53 -0000 1.1 +++ JavaScriptHelper.java 26 Jun 2004 18:29:30 -0000 1.2 @@ -15,9 +15,14 @@ */ package org.apache.cocoon.components.flow.javascript; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.avalon.framework.CascadingRuntimeException; import org.apache.avalon.framework.configuration.Configuration; @@ -26,6 +31,8 @@ import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.components.flow.Interpreter; import org.apache.cocoon.components.flow.java.AbstractContinuable; +import org.apache.cocoon.components.flow.java.Continuable; +import org.apache.cocoon.components.flow.java.ContinuationHelper; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; @@ -41,6 +48,7 @@ import org.mozilla.javascript.NativeJavaClass; import org.mozilla.javascript.NativeJavaPackage; import org.mozilla.javascript.PropertyException; +import org.mozilla.javascript.Script; import org.mozilla.javascript.ScriptRuntime; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; @@ -81,7 +89,7 @@ /** * Mapping of String objects (source uri's) to ScriptSourceEntry's */ - //protected Map compiledScripts = new HashMap(); + protected Map compiledScripts = new HashMap(); /** * LAST_EXEC_TIME @@ -150,6 +158,7 @@ */ public void register(String source) { + System.out.println("register source "+source); synchronized(this) { needResolve.add(source); } @@ -196,6 +205,8 @@ e.printStackTrace(); throw e; } + + sourceresolver = (SourceResolver)getServiceManager().lookup(SourceResolver.ROLE); } /** @@ -275,7 +286,7 @@ ClassLoader classLoader; /* true if this scope has assigned any global vars */ - boolean useSession = false; + public boolean useSession = false; public ThreadScope() { final String[] names = { "importClass"}; @@ -302,7 +313,7 @@ super.put(index, start, value); } - void reset() { + public void reset() { useSession = false; } @@ -345,7 +356,7 @@ } private ThreadScope createThreadScope() throws Exception { - Context context = Context.getCurrentContext(); + //Context context = Context.getCurrentContext(); ThreadScope thrScope = new ThreadScope(); @@ -357,7 +368,7 @@ // Put in the thread scope the Cocoon object, which gives access // to the interpreter object, and some Cocoon objects. See // FOM_Cocoon for more details. - Object[] args = {}; + //Object[] args = {}; thrScope.defineProperty(LAST_EXEC_TIME, new Long(0), ScriptableObject.DONTENUM | ScriptableObject.PERMANENT); @@ -409,7 +420,7 @@ //thrScope.setupPackages(classLoader); // Check if we need to compile and/or execute scripts - /*synchronized (compiledScripts) { + 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 @@ -452,7 +463,9 @@ thrScope.reset(); } } - }*/ + } + + thrScope.put("cocoon", thrScope, new ContinuationHelper()); } /** @@ -462,7 +475,7 @@ * @param fileName resource uri * @return compiled script */ - /*Script compileScript(Context cx, String fileName) throws Exception { + Script compileScript(Context cx, String fileName) throws Exception { Source src = this.sourceresolver.resolveURI(fileName); if (src != null) { synchronized (compiledScripts) { @@ -481,9 +494,9 @@ } else { throw new ResourceNotFoundException(fileName + ": not found"); } - }*/ + } - /*protected Script compileScript(Context cx, Scriptable scope, Source src) + protected Script compileScript(Context cx, Scriptable scope, Source src) throws Exception { InputStream is = src.getInputStream(); if (is != null) { @@ -498,7 +511,7 @@ } else { throw new ResourceNotFoundException(src.getURI() + ": not found"); } - }*/ + } /** * Calls a JavaScript function, passing <code>params</code> as its @@ -679,7 +692,7 @@ } }*/ - /*protected class ScriptSourceEntry { + protected class ScriptSourceEntry implements Continuable { final private Source source; private Script script; private long compileTime; @@ -710,5 +723,5 @@ } return script; } - }*/ + } } 1.2 +3 -3 cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java Index: JavaScriptInterpreter.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JavaScriptInterpreter.java 24 Jun 2004 16:48:53 -0000 1.1 +++ JavaScriptInterpreter.java 26 Jun 2004 18:29:30 -0000 1.2 @@ -15,7 +15,6 @@ */ package org.apache.cocoon.components.flow.javascript; -import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -67,6 +66,7 @@ super.configure(config); continuationclassloader = new ContinuationClassLoader(Thread.currentThread().getContextClassLoader()); + continuationclassloader.addIncludeClass("org.mozilla.**"); continuationclassloader.setDebug(config.getAttributeAsBoolean("debug", false)); Configuration[] includes = config.getChildren("include"); @@ -185,7 +185,7 @@ Request request = ContextHelper.getRequest(this.avalonContext); Session session = request.getSession(true); - HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE); + //HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE); ScriptHelper flow = (ScriptHelper) context.getObject(); 1.4 +29 -20 cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/JavaFlowTestCase.java Index: JavaFlowTestCase.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/JavaFlowTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JavaFlowTestCase.java 24 Jun 2004 16:48:53 -0000 1.3 +++ JavaFlowTestCase.java 26 Jun 2004 18:29:30 -0000 1.4 @@ -39,18 +39,17 @@ String id = callFunction("java", source, "simpleTest", new HashMap()); getRequest().addParameter("a", "2.3"); - getRedirector().reset(); callContinuation("java", source, id, new HashMap()); VarMap map = (VarMap)getFlowContextObject(); - assertEquals(((Float)map.getMap().get("result")).floatValue(), 3.3f, 0.1f); + assertEquals(3.3f, ((Float)map.getMap().get("result")).floatValue(), 0.1f); JXPathContext jxcontext = JXPathContext.newContext(getFlowContextObject()); Float result = (Float)jxcontext.getValue("result"); - assertEquals(result.floatValue(), 3.3f, 0.1f); + assertEquals(3.3f, result.floatValue(), 0.1f); } public void testNew() throws Exception { @@ -63,20 +62,17 @@ String source = "org.apache.cocoon.components.flow.java.test.SimpleFlow"; String id = callFunction("java", source, "catchTest", new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/getNumberA"); + assertEquals("cocoon:/getNumberA", getRedirector().getRedirect()); getRequest().addParameter("a", "bla"); - getRedirector().reset(); id = callContinuation("java", source, id, new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/error"); - - getRedirector().reset(); + assertEquals("cocoon:/error", getRedirector().getRedirect()); id = callContinuation("java", source, id, new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/result"); + assertEquals("cocoon:/result", getRedirector().getRedirect()); } @@ -85,7 +81,7 @@ String source = "org.apache.cocoon.components.flow.java.test.SimpleFlow"; String id = callFunction("java", source, "abstractTest", new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/parent"); + assertEquals("cocoon:/parent", getRedirector().getRedirect()); } public void testDelegate() throws Exception { @@ -93,35 +89,32 @@ String source = "org.apache.cocoon.components.flow.java.test.SimpleFlow"; String id = callFunction("java", source, "delegateTest", new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/page/getNumberA"); + assertEquals("cocoon:/page/getNumberA", getRedirector().getRedirect()); getRequest().addParameter("a", "2"); - getRedirector().reset(); id = callContinuation("java", source, id, new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/page/getNumberB"); + assertEquals("cocoon:/page/getNumberB", getRedirector().getRedirect()); getRequest().addParameter("b", "2"); - getRedirector().reset(); id = callContinuation("java", source, id, new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/page/getOperator"); + assertEquals("cocoon:/page/getOperator", getRedirector().getRedirect()); getRequest().addParameter("operator", "plus"); - getRedirector().reset(); id = callContinuation("java", source, id, new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/page/displayResult"); + assertEquals("cocoon:/page/displayResult", getRedirector().getRedirect()); } public void testException() throws Exception { String source = "org.apache.cocoon.components.flow.java.test.SimpleFlow"; String id = callFunction("java", source, "exceptionTest", new HashMap()); - assertEquals(getRedirector().getRedirect(), "cocoon:/test.jxt"); + assertEquals("cocoon:/test.jxt", getRedirector().getRedirect()); try { callContinuation("java", source, id, new HashMap()); @@ -163,6 +156,22 @@ public void testClass() throws Exception { String source = "org.apache.cocoon.components.flow.java.test.SimpleFlow"; - String id = callFunction("java", source, "forClassTest", new HashMap()); + String id = callFunction("java", source, "classTest", new HashMap()); + } + + public void testInnerClass() throws Exception { + String source = "org.apache.cocoon.components.flow.java.test.InnerContinuable"; + String id = callFunction("java", source, "innerClassTest1", new HashMap()); + + assertEquals("cocoon:/test1", getRedirector().getRedirect()); + + callContinuation("java", source, id, new HashMap()); + + // second test + id = callFunction("java", source, "innerClassTest2", new HashMap()); + + assertEquals("cocoon:/test2", getRedirector().getRedirect()); + + callContinuation("java", source, id, new HashMap()); } } 1.3 +3 -1 cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/JavaFlowTestCase.xtest Index: JavaFlowTestCase.xtest =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/JavaFlowTestCase.xtest,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JavaFlowTestCase.xtest 24 Jun 2004 16:48:53 -0000 1.2 +++ JavaFlowTestCase.xtest 26 Jun 2004 18:29:30 -0000 1.3 @@ -78,7 +78,9 @@ <source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/> <flow-interpreters default="java"> - <component-instance class="org.apache.cocoon.components.flow.java.JavaInterpreter" name="java" debug="false"/> + <component-instance class="org.apache.cocoon.components.flow.java.JavaInterpreter" name="java" debug="true"> + <include class="org.apache.cocoon.components.flow.java.test.Inner*"/> + </component-instance> </flow-interpreters> <continuations-manager time-to-live="3600000"> 1.8 +17 -0 cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/SimpleFlow.java Index: SimpleFlow.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/SimpleFlow.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SimpleFlow.java 24 Jun 2004 16:48:53 -0000 1.7 +++ SimpleFlow.java 26 Jun 2004 18:29:30 -0000 1.8 @@ -50,6 +50,14 @@ public void doNewTest() { Locale locale = null; FormContext formContext = new FormContext(getRequest(), locale); + + //second test + new Double("2.3"); + + //third test + new String(new char[]{'a','b','c'}, 0, 3); + + Assert.assertNotNull(formContext); } public void doCatchTest() { @@ -58,6 +66,15 @@ float a = Float.parseFloat(getRequest().getParameter("a")); } catch (NumberFormatException nfe) { sendPageAndWait("error"); + } + sendPage("result"); + } + + public void doCatchTest2() { + try { + sendPageAndWait("getNumberA"); + float a = Float.parseFloat(getRequest().getParameter("a")); + } catch (NumberFormatException nfe) { } sendPage("result"); } 1.1 cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/java/test/InnerContinuable.java Index: InnerContinuable.java =================================================================== package org.apache.cocoon.components.flow.java.test; import org.apache.cocoon.components.flow.java.ContinuationHelper; public class InnerContinuable { private String result2 ="test2"; public void doInnerClassTest1() { InnerClass ic = new InnerClass(); ic.sendResult1(); } public void doInnerClassTest2() { InnerClass ic = new InnerClass(); ic.sendResult2(); } public class InnerClass { public void sendResult1() { ContinuationHelper.sendPageAndWait("test1"); } public void sendResult2() { ContinuationHelper.sendPageAndWait(result2); } } } 1.3 +1 -1 cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/javascript/JavaScriptFlowTestCase.xtest Index: JavaScriptFlowTestCase.xtest =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/javaflow/test/org/apache/cocoon/components/flow/javascript/JavaScriptFlowTestCase.xtest,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JavaScriptFlowTestCase.xtest 24 Jun 2004 16:48:53 -0000 1.2 +++ JavaScriptFlowTestCase.xtest 26 Jun 2004 18:29:31 -0000 1.3 @@ -79,7 +79,7 @@ <flow-interpreters default="javascript"> <component-instance class="org.apache.cocoon.components.flow.java.JavaInterpreter" name="java"/> - <component-instance class="org.apache.cocoon.components.flow.javascript.JavaScriptInterpreter" name="javascript" debug="false"/> + <component-instance class="org.apache.cocoon.components.flow.javascript.JavaScriptInterpreter" name="javascript" debug="true"/> </flow-interpreters> <continuations-manager time-to-live="3600000">