Author: lgawron
Date: Sun Nov 21 05:26:02 2004
New Revision: 106089

Modified:
   
cocoon/branches/BRANCH_2_1_X/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
   
cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java
   
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/Interpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Fix: Continuation can only be invoked for the interpreter it was originally 
created for
- o.a.c.components.flow.ContinuationsManager interface change. Interpreter id 
has to be passed
  to create a continuation and lookup one. 
- o.a.c.components.flow.ContinuationManagerImpl returns null if interpreter 
does not match during lookup.
- o.a.c.components.flow.Interpreter interface extended with setInterpreterID 
method. 
- all current interpreters updated to match new contracts

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
   (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/apples/java/org/apache/cocoon/components/flow/apples/ApplesProcessor.java
   Sun Nov 21 05:26:02 2004
@@ -53,7 +53,8 @@
 
         WebContinuation wk = null;
         if (!(app instanceof StatelessAppleController)) {
-            wk = this.continuationsMgr.createWebContinuation(app, null, 0, 
this);
+            wk = this.continuationsMgr.createWebContinuation(app, null, 0,
+                    getInterpreterID(), this);
             if (getLogger().isDebugEnabled())
                 getLogger().debug("Instantiated a stateful apple, 
continuationid = " + wk.getId());
         }
@@ -79,7 +80,7 @@
         throws Exception {
 
         WebContinuation wk =
-            this.continuationsMgr.lookupWebContinuation(continuationId);
+            this.continuationsMgr.lookupWebContinuation(continuationId, 
getInterpreterID());
         if (wk == null) {
             // Throw an InvalidContinuationException to be handled inside the
             // <map:handle-errors> sitemap element.

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
   (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java
   Sun Nov 21 05:26:02 2004
@@ -144,14 +144,15 @@
         context.setRedirector(redirector);
         Parameters parameters = new Parameters();
         for(Iterator i=params.iterator(); i.hasNext();) {
-               Argument argument = (Argument)i.next();
-               parameters.setParameter(argument.name, argument.value);
+            Argument argument = (Argument)i.next();
+            parameters.setParameter(argument.name, argument.value);
         }
         context.setParameters(parameters);
 
         Continuation continuation = new Continuation(context);
 
-        WebContinuation wk = 
continuationsMgr.createWebContinuation(continuation, null, timeToLive, null);
+        WebContinuation wk = continuationsMgr.createWebContinuation(
+                continuation, null, timeToLive, getInterpreterID(), null);
         
FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), 
wk);
 
         continuation.registerThread();
@@ -195,7 +196,7 @@
         if (!initialized)
             initialize();
 
-        WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id);
+        WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, 
getInterpreterID());
 
         if (parentwk == null) {
             /*
@@ -216,8 +217,8 @@
         context.setRedirector(redirector);
         Parameters parameters = new Parameters();
         for(Iterator i=params.iterator(); i.hasNext();) {
-               Argument argument = (Argument)i.next();
-               parameters.setParameter(argument.name, argument.value);
+            Argument argument = (Argument)i.next();
+            parameters.setParameter(argument.name, argument.value);
         }
         context.setParameters(parameters);
 
@@ -230,8 +231,8 @@
         Continuable flow = (Continuable) context.getObject();
         Method method = context.getMethod();
 
-        WebContinuation wk =
-                continuationsMgr.createWebContinuation(continuation, parentwk, 
timeToLive, null);
+        WebContinuation wk = continuationsMgr.createWebContinuation(
+                continuation, parentwk, timeToLive, getInterpreterID(), null);
         
FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), 
wk);
 
         continuation.registerThread();

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_Cocoon.java
 Sun Nov 21 05:26:02 2004
@@ -124,6 +124,7 @@
                 contMgr.createWebContinuation(continuation,
                                               lastContinuation,
                                               0,
+                                              interpreter.getInterpreterID(),
                                               null);
         }
         
@@ -248,7 +249,7 @@
         public FOM_Request(Object request) {
             this.request = (Request)unwrap(request);
         }
-               
+        
         public String getClassName() {
             return "FOM_Request";
         }
@@ -675,7 +676,7 @@
         
         /* TODO: Vote on the inclusion of this method
         public String jsFunction_getRealPath(String path) {
-               return context.getRealPath(path);
+            return context.getRealPath(path);
         }
         */
     }
@@ -926,6 +927,7 @@
         wk = contMgr.createWebContinuation(unwrap(k),
                                            (parent == null ? null : 
parent.getWebContinuation()),
                                            timeToLive,
+                                           interpreter.getInterpreterID(),
                                            null);
         FOM_WebContinuation result = new FOM_WebContinuation(wk);
         result.setParentScope(getParentScope());

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
  (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/components/flow/javascript/fom/AO_FOM_JavaScriptInterpreter.java
  Sun Nov 21 05:26:02 2004
@@ -652,7 +652,7 @@
                                    Redirector redirector)
         throws Exception
     {
-        WebContinuation wk = continuationsMgr.lookupWebContinuation(id);
+        WebContinuation wk = continuationsMgr.lookupWebContinuation(id, 
getInterpreterID());
 
         if (wk == null) {
 

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
    (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
    Sun Nov 21 05:26:02 2004
@@ -103,7 +103,7 @@
      *
      * @return a unique ID for this interpreter
      */
-    protected String getInterpreterID() {
+    public String getInterpreterID() {
         return this.instanceID;
     }
 

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
   (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
   Sun Nov 21 05:26:02 2004
@@ -31,7 +31,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
  * @since March 19, 2002
  * @see WebContinuation
- * @version CVS $Id: ContinuationsManager.java,v 1.6 2004/03/05 13:02:46 
bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public interface ContinuationsManager {
     public final String ROLE = ContinuationsManager.class.getName();
@@ -47,6 +47,7 @@
      * @param timeToLive an <code>int</code> value indicating how long
      * in seconds this continuation will live in the server if not
      * accessed
+     * @param interpreterId id of interpreter invoking continuation creation
      * @param disposer a <code>ContinuationsDisposer</code> instance to called 
when 
      * the continuation gets cleaned up.
      * @return a <code>WebContinuation</code> value
@@ -55,6 +56,7 @@
     public WebContinuation createWebContinuation(Object kont,
                                                  WebContinuation parentKont,
                                                  int timeToLive,
+                                                 String interpreterId,
                                                  ContinuationsDisposer 
disposer);
 
     /**
@@ -71,12 +73,16 @@
     /**
      * Given a <code>WebContinuation</code> id, retrieve the associated
      * <code>WebContinuation</code> object.
-     *
      * @param id a <code>String</code> value
-     * @return a <code>WebContinuation</code> object, or null if no such
-     * <code>WebContinuation</code> could be found.
+     * @param interpreterId Id of an interpreter that queries for 
+     * the continuation
+     *
+     * @return a <code>WebContinuation</code> object, null if no such
+     * <code>WebContinuation</code> could be found. Also null if 
+     * <code>WebContinuation</code> was found but interpreter id does 
+     * not match the one that the continuation was initialy created for.
      */
-    public WebContinuation lookupWebContinuation(String id);
+    public WebContinuation lookupWebContinuation(String id, String 
interpreterId);
 
     /**
      * Prints debug information about all web continuations into the log file.

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
       (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
       Sun Nov 21 05:26:02 2004
@@ -168,10 +168,11 @@
     public WebContinuation createWebContinuation(Object kont,
                                                  WebContinuation parent,
                                                  int timeToLive,
+                                                 String interpreterId, 
                                                  ContinuationsDisposer 
disposer) {
         int ttl = (timeToLive == 0 ? defaultTimeToLive : timeToLive);
 
-        WebContinuation wk = generateContinuation(kont, parent, ttl, disposer);
+        WebContinuation wk = generateContinuation(kont, parent, ttl, 
interpreterId, disposer);
         wk.enableLogging(getLogger());
 
         if (parent == null) {
@@ -198,10 +199,11 @@
         return wk;
     }
 
-    public WebContinuation lookupWebContinuation(String id) {
+    public WebContinuation lookupWebContinuation(String id, String 
interpreterId) {
         // REVISIT: Is the following check needed to avoid threading issues:
         // return wk only if !(wk.hasExpired) ?
-        return (WebContinuation) idToWebCont.get(id);
+        WebContinuation kont = (WebContinuation) idToWebCont.get(id);
+        return (kont.interpreterMatches(interpreterId)) ? kont : null;
     }
 
     /**
@@ -215,6 +217,7 @@
      * @param kont an <code>Object</code> value representing continuation
      * @param parent value representing parent <code>WebContinuation</code>
      * @param ttl <code>WebContinuation</code> time to live
+     * @param interpreterId id of interpreter invoking continuation creation
      * @param disposer <code>ContinuationsDisposer</code> instance to use for
      * cleanup of the continuation.
      * @return the generated <code>WebContinuation</code> with unique 
identifier
@@ -222,7 +225,8 @@
     private WebContinuation generateContinuation(Object kont,
                                                  WebContinuation parent,
                                                  int ttl,
-                                                 ContinuationsDisposer 
disposer) {
+                                                 String interpreterId,
+                                                 ContinuationsDisposer 
disposer ) {
 
         char[] result = new char[bytes.length * 2];
         WebContinuation wk = null;
@@ -239,7 +243,7 @@
             final String id = new String(result);
             synchronized (idToWebCont) {
                 if (!idToWebCont.containsKey(id)) {
-                    wk = new WebContinuation(id, kont, parent, ttl, disposer);
+                    wk = new WebContinuation(id, kont, parent, ttl, 
interpreterId, disposer);
                     idToWebCont.put(id, wk);
                     continuationsCount.setValue(idToWebCont.size());
                     break;

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/Interpreter.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/Interpreter.java
    (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/Interpreter.java
    Sun Nov 21 05:26:02 2004
@@ -93,7 +93,12 @@
 
     public static final String ROLE = Interpreter.class.getName();
 
-    /**
+       /**
+        * @return the unique ID for this interpreter.
+        */
+       String getInterpreterID();
+       
+       /**
      * Set the unique ID for this interpreter.
      */
     void setInterpreterID(String interpreterID);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
        (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
        Sun Nov 21 05:26:02 2004
@@ -19,6 +19,7 @@
 import java.util.List;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * Representation of continuations in a Web environment.
@@ -34,7 +35,7 @@
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
  * @since March 19, 2002
- * @version CVS $Id: WebContinuation.java,v 1.9 2004/05/17 18:50:53 vgritsenko 
Exp $
+ * @version CVS $Id$
  */
 public class WebContinuation extends AbstractLogEnabled
                              implements Comparable {
@@ -67,6 +68,11 @@
      * The continuation id used to represent this instance in Web pages.
      */
     protected String id;
+    
+    /**
+     * Interpreter id that this continuation is bound to
+     */
+    protected String interpreterId;
 
     /**
      * A user definable object. This is present for convenience, to
@@ -113,12 +119,14 @@
                     Object continuation,
                     WebContinuation parentContinuation,
                     int timeToLive,
+                    String interpreterId,
                     ContinuationsDisposer disposer) {
         this.id = id;
         this.continuation = continuation;
         this.parentContinuation = parentContinuation;
         this.updateLastAccessTime();
         this.timeToLive = timeToLive;
+        this.interpreterId = interpreterId;
         this.disposer = disposer;
 
         if (parentContinuation != null) {
@@ -363,5 +371,9 @@
      */
     public boolean disposed() {
         return this.continuation == null;
+    }
+    
+    public boolean interpreterMatches( String interpreterId ) {
+        return StringUtils.equals( this.interpreterId, interpreterId );
     }
 }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
      (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
      Sun Nov 21 05:26:02 2004
@@ -1237,7 +1237,7 @@
 
         /* TODO: Vote on the inclusion of this method
         public String jsFunction_getRealPath(String path) {
-               return context.getRealPath(path);
+            return context.getRealPath(path);
         }
         */
 
@@ -1470,6 +1470,14 @@
     }
 
     /**
+     * Required by FOM_WebContinuation. This way we do not make whole 
Interpreter public
+     * @return interpreter Id associated with this FOM.
+     */
+    public String getInterpreterId() {
+        return getInterpreter().getInterpreterID();
+    }
+    
+    /**
      * Call the Cocoon Sitemap to process a page
      * @param uri Uri to match
      * @param bean Input to page
@@ -1572,6 +1580,7 @@
         wk = contMgr.createWebContinuation(unwrap(k),
                                            (parent == null ? null : 
parent.getWebContinuation()),
                                            timeToLive,
+                                           getInterpreter().getInterpreterID(),
                                            null);
         FOM_WebContinuation result = new FOM_WebContinuation(wk);
         result.setParentScope(getParentScope());

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
       (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
       Sun Nov 21 05:26:02 2004
@@ -758,7 +758,7 @@
     public void handleContinuation(String id, List params,
                                    Redirector redirector) throws Exception
     {
-        WebContinuation wk = continuationsMgr.lookupWebContinuation(id);
+        WebContinuation wk = continuationsMgr.lookupWebContinuation(id, 
getInterpreterID());
 
         if (wk == null) {
             /*

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
     (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
     Sun Nov 21 05:26:02 2004
@@ -90,6 +90,7 @@
         wk = contMgr.createWebContinuation(c,
                                            (parent == null ? null : 
parent.getWebContinuation()),
                                            timeToLive,
+                                           cocoon.getInterpreterId(), 
                                            null);
         result = new FOM_WebContinuation(wk);
         result.setParentScope(getTopLevelScope(scope));

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml     (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml     Sun Nov 21 05:26:02 2004
@@ -78,6 +78,7 @@
   <person name="Gerhard Froehlich" email="[EMAIL PROTECTED]" id="GF"/>
   <person name="Pierpaolo Fumagalli" email="[EMAIL PROTECTED]" id="PF"/>
   <person name="Antonio Gallardo" email="[EMAIL PROTECTED]" id="AG"/>
+  <person name="Leszek Gawron" email="[EMAIL PROTECTED]" id="LG"/>
   <person name="Ralph Goers" email="[EMAIL PROTECTED]" id="RG"/>
   <person name="Vadim Gritsenko" email="[EMAIL PROTECTED]" id="VG"/>
   <person name="Christian Haul" email="[EMAIL PROTECTED]" id="CH"/>
@@ -203,6 +204,9 @@
  <release version="@version@" date="@date@">
   <action dev="NN" type="add">
     Dummy
+  </action>
+  <action dev="LG" type="fix">
+    Fix: Continuation can only be invoked for the interpreter it was 
originally created for.
   </action>
  </release>
  <release version="2.1.6" date="November 19 2004">

Reply via email to