Author: vgritsenko
Date: Mon Oct  4 15:06:25 2004
New Revision: 53751

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/Interpreter.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
   
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Flow preserves global variables on sitemap reload.


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
    Mon Oct  4 15:06:25 2004
@@ -55,12 +55,10 @@
  * @since March 15, 2002
  * @version CVS $Id$
  */
-public abstract class AbstractInterpreter extends AbstractLogEnabled
-  implements Component, Serviceable, Contextualizable, Interpreter,
-             SingleThreaded, Configurable, Disposable
-{
-    // The instance counters, used to produce unique IDs
-    private static int instanceCounter = 0;
+public abstract class AbstractInterpreter
+        extends AbstractLogEnabled
+        implements Component, Serviceable, Contextualizable, Interpreter,
+                   SingleThreaded, Configurable, Disposable {
 
     // The instance ID of this interpreter, used to identify user scopes
     private String instanceID;
@@ -89,10 +87,14 @@
     protected long checkTime;
 
     public AbstractInterpreter() {
-        synchronized(AbstractInterpreter.class) {
-            instanceCounter++;
-            this.instanceID = String.valueOf(instanceCounter);
-        }
+    }
+
+    /**
+     * Set the unique ID for this interpreter, which can be used to 
distinguish user value scopes
+     * attached to the session.
+     */
+    public void setInterpreterID(String interpreterID) {
+        this.instanceID = interpreterID;
     }
 
     /**

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
    Mon Oct  4 15:06:25 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -43,9 +43,7 @@
  * situations:
  *
  * <ul>
- *
  *  <li>
- *
  *    <p>From the sitemap, to invoke a top level function defined in a
  *    * given implementation language of the flow. This is done from
  *    the * sitemap using the construction:
@@ -58,7 +56,6 @@
  *    default language is used.
  *
  *  <li>
- *
  *    <p>From the sitemap, to continue a previously started
  *    computation. A previously started computation is saved in the
  *    form of a continuation inside the flow implementation language.
@@ -69,116 +66,114 @@
  *    information on the function name and the arguments it receives.
  *
  *  <li>
- *
  *    <p>From a program in the flow layer. This is done to invoke a
  *    pipeline defined in the sitemap, to generate the response of the
  *    request.
- *
  * </ul>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
  * @since March 11, 2002
  * @see InterpreterSelector
- * @version CVS $Id: Interpreter.java,v 1.7 2004/03/05 13:02:46 bdelacretaz 
Exp $
+ * @version CVS $Id$
  */
-public interface Interpreter
-{
-
-
-  public static class Argument
-  {
-    public String name;
-    public String value;
-
-    public Argument(String name, String value)
-    {
-      this.name = name;
-      this.value = value;
-    }
+public interface Interpreter {
 
-    public String toString()
-    {
-      return name + ": " + value;
+    public static class Argument {
+        public String name;
+        public String value;
+
+        public Argument(String name, String value) {
+            this.name = name;
+            this.value = value;
+        }
+
+        public String toString() {
+            return name + ": " + value;
+        }
     }
-  }
 
-  public static String ROLE = Interpreter.class.getName();
+    public static final String ROLE = Interpreter.class.getName();
 
-  /**
-   * This method is called from the sitemap, using the syntax
-   *
-   * <pre>
-   *   &lt;map:call function="..."/&gt;
-   * </pre>
-   *
-   * The method will execute the named function, which must be defined
-   * in the given language. There is no assumption made on how various
-   * arguments are passed to the function.
-   *
-   * <p>The <code>params</code> argument is a <code>List</code> object
-   * that contains <code>Interpreter.Argument</code> instances,
-   * representing the parameters to be passed to the called
-   * function. An <code>Argument</code> instance is a key-value pair,
-   * where the key is the name of the parameter, and the value is its
-   * desired value. Most languages will ignore the name value and
-   * simply pass to the function, in a positional order, the values of
-   * the argument. Some languages however can pass the arguments in a
-   * different order than the original prototype of the function. For
-   * these languages the ability to associate the actual argument with
-   * a formal parameter using its name is essential.
-   *
-   * <p>A particular language implementation may decide to put the
-   * environment, request, response etc. objects in the dynamic scope
-   * available to the function at the time of the call. Other
-   * implementations may decide to pass these as arguments to the
-   * called function.
-   *
-   * <p>The current implementation assumes the sitemap implementation
-   * is TreeProcessor.
-   *
-   * @param funName a <code>String</code> value, the name of the
-   * function to call
-   * @param params a <code>List</code> object whose components are
-   * CallFunctionNode.Argument instances. The interpretation of the
-   * parameters is left to the actual implementation of the
-   * interpreter.
-   * @param redirector a <code>Redirector</code> used to call views
-   */
-  void callFunction(String funName, List params, Redirector redirector)
+    /**
+     * Set the unique ID for this interpreter.
+     */
+    void setInterpreterID(String interpreterID);
+
+    /**
+     * This method is called from the sitemap, using the syntax
+     *
+     * <pre>
+     *   &lt;map:call function="..."/&gt;
+     * </pre>
+     *
+     * The method will execute the named function, which must be defined
+     * in the given language. There is no assumption made on how various
+     * arguments are passed to the function.
+     *
+     * <p>The <code>params</code> argument is a <code>List</code> object
+     * that contains <code>Interpreter.Argument</code> instances,
+     * representing the parameters to be passed to the called
+     * function. An <code>Argument</code> instance is a key-value pair,
+     * where the key is the name of the parameter, and the value is its
+     * desired value. Most languages will ignore the name value and
+     * simply pass to the function, in a positional order, the values of
+     * the argument. Some languages however can pass the arguments in a
+     * different order than the original prototype of the function. For
+     * these languages the ability to associate the actual argument with
+     * a formal parameter using its name is essential.
+     *
+     * <p>A particular language implementation may decide to put the
+     * environment, request, response etc. objects in the dynamic scope
+     * available to the function at the time of the call. Other
+     * implementations may decide to pass these as arguments to the
+     * called function.
+     *
+     * <p>The current implementation assumes the sitemap implementation
+     * is TreeProcessor.
+     *
+     * @param funName a <code>String</code> value, the name of the
+     * function to call
+     * @param params a <code>List</code> object whose components are
+     * CallFunctionNode.Argument instances. The interpretation of the
+     * parameters is left to the actual implementation of the
+     * interpreter.
+     * @param redirector a <code>Redirector</code> used to call views
+     */
+    void callFunction(String funName, List params, Redirector redirector)
     throws Exception;
 
-  /**
-   * Forward the request to a Cocoon pipeline.
-   *
-   * @param uri a <code>String</code>, the URI of the forwarded request
-   * @param bizData an <code>Object</code>, the business data object
-   * to be made available to the forwarded pipeline
-   * @param continuation a <code>WebContinuation</code>, the
-   * continuation to be called to resume the processing
-   * @param redirector a <code>Redirector</code> used to call views
-   * @exception Exception if an error occurs
-   */
-  void forwardTo(String uri, Object bizData, WebContinuation continuation,
-                 Redirector redirector)
+    /**
+     * Forward the request to a Cocoon pipeline.
+     *
+     * @param uri a <code>String</code>, the URI of the forwarded request
+     * @param bizData an <code>Object</code>, the business data object
+     * to be made available to the forwarded pipeline
+     * @param continuation a <code>WebContinuation</code>, the
+     * continuation to be called to resume the processing
+     * @param redirector a <code>Redirector</code> used to call views
+     * @exception Exception if an error occurs
+     */
+    void forwardTo(String uri, Object bizData, WebContinuation continuation,
+                   Redirector redirector)
     throws Exception;
 
-  /**
-   * Continues a previously started processing. The continuation
-   * object where the processing should start from is indicated by the
-   * <code>continuationId</code> string.
-   *
-   * @param continuationId a <code>String</code> value
-   *
-   * @param params a <code>List</code> value, containing the
-   * parameters to be passed when invoking the continuation. As
-   * opposed to the parameters passed by <code>callFunction</code>,
-   * these parameters will only become available in the language's
-   * environment, if at all.
-   *
-   * @param redirector a <code>Redirector</code> used to call views
-   * @exception Exception if an error occurs
-   */
-  void handleContinuation(String continuationId, List params,
-                          Redirector redirector)
+    /**
+     * Continues a previously started processing. The continuation
+     * object where the processing should start from is indicated by the
+     * <code>continuationId</code> string.
+     *
+     * @param continuationId a <code>String</code> value
+     *
+     * @param params a <code>List</code> value, containing the
+     * parameters to be passed when invoking the continuation. As
+     * opposed to the parameters passed by <code>callFunction</code>,
+     * these parameters will only become available in the language's
+     * environment, if at all.
+     *
+     * @param redirector a <code>Redirector</code> used to call views
+     * @exception Exception if an error occurs
+     */
+    void handleContinuation(String continuationId, List params,
+                            Redirector redirector)
     throws Exception;
 }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
   (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
   Mon Oct  4 15:06:25 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,10 +30,10 @@
  * children nodes.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Id: AbstractParentProcessingNodeBuilder.java,v 1.3 2004/03/05 
13:02:51 bdelacretaz Exp $
+ * @version CVS $Id$
  */
-
-public abstract class AbstractParentProcessingNodeBuilder extends 
AbstractProcessingNodeBuilder implements Configurable {
+public abstract class AbstractParentProcessingNodeBuilder extends 
AbstractProcessingNodeBuilder
+                                                          implements 
Configurable {
 
     protected Collection allowedChildren;
 

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
 Mon Oct  4 15:06:25 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,13 +32,11 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
  * @version CVS $Id$
  */
-
-
 public abstract class AbstractProcessingNodeBuilder extends AbstractLogEnabled
-  implements ProcessingNodeBuilder, Recomposable {
+                                                    implements 
ProcessingNodeBuilder, Recomposable {
 
     protected TreeBuilder treeBuilder;
-    
+
     protected ComponentManager manager;
 
     public void compose(ComponentManager manager) throws ComponentException {
@@ -102,8 +100,7 @@
      * one given by the builder.
      */
     protected void checkNamespace(Configuration config) throws 
ConfigurationException {
-        if (!this.treeBuilder.getNamespace().equals(config.getNamespace()))
-        {
+        if (!this.treeBuilder.getNamespace().equals(config.getNamespace())) {
             String msg = "Invalid namespace '" + config.getNamespace() + "' at 
" + config.getLocation();
             throw new ConfigurationException(msg);
         }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
      (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java
      Mon Oct  4 15:06:25 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,13 +21,10 @@
 import org.apache.avalon.framework.component.ComponentManager;
 import org.apache.avalon.framework.component.ComponentSelector;
 import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.cocoon.Constants;
+
 import org.apache.cocoon.components.flow.Interpreter;
 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
 import org.apache.cocoon.components.treeprocessor.InvokeContext;
-import org.apache.cocoon.environment.Context;
 import org.apache.cocoon.environment.Environment;
 
 /**
@@ -38,39 +35,18 @@
  * @version CVS $Id$
  */
 public class FlowNode extends AbstractProcessingNode
-        implements Composable, Contextualizable, Disposable {
+                      implements Composable, Disposable {
+
+    private ComponentManager manager;
+    private String language;
+    private Interpreter interpreter;
+    private ComponentSelector interpreterSelector;
 
-    ComponentManager manager;
-    String language;
-    Context context;
-    Interpreter interpreter;
-    ComponentSelector selector;
-    
     public FlowNode(String language) {
         this.language = language;
     }
 
     /**
-     * This method should never be called by the TreeProcessor, since a
-     * <code>&lt;map:flow&gt;</code> element should not be in an
-     * "executable" sitemap node.
-     *
-     * @param env an <code>Environment</code> value
-     * @param context an <code>InvokeContext</code> value
-     * @return a <code>boolean</code> value
-     * @exception Exception if an error occurs
-     */
-    public boolean invoke(Environment env, InvokeContext context) throws 
Exception {
-        return true;
-    }
-
-    public void contextualize(org.apache.avalon.framework.context.Context 
context)
-        throws ContextException {
-        this.context = 
(Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
-    }
-
-    /**
-     *
      * Lookup an flow [EMAIL PROTECTED] 
org.apache.cocoon.components.flow.Interpreter}
      * instance to hold the scripts defined within the 
<code>&lt;map:flow&gt;</code>
      * in the sitemap.
@@ -82,31 +58,50 @@
         this.manager = manager;
 
         try {
-            this.selector = 
(ComponentSelector)manager.lookup(Interpreter.ROLE);
+            this.interpreterSelector = (ComponentSelector) 
manager.lookup(Interpreter.ROLE);
             // Obtain the Interpreter instance for this language
-            this.interpreter = (Interpreter)selector.select(language);
-        } catch (Exception ex) {
+            this.interpreter = (Interpreter) 
this.interpreterSelector.select(language);
+            // Set interpreter ID as location of the flow node (which includes 
full sitemap file path)
+            this.interpreter.setInterpreterID(this.location);
+        } catch (ComponentException e) {
+            throw e;
+        } catch (Exception e) {
             throw new ComponentException(language,
-                "ScriptNode: Couldn't obtain a flow interpreter for " + 
language + ": " + ex);
+                                         "FlowNode: Couldn't obtain a flow 
interpreter for '" + language +
+                                         "' at " + getLocation(), e);
         }
     }
 
+    /**
+     * This method should never be called by the TreeProcessor, since a
+     * <code>&lt;map:flow&gt;</code> element should not be in an
+     * "executable" sitemap node.
+     *
+     * @param env an <code>Environment</code> value
+     * @param context an <code>InvokeContext</code> value
+     * @return a <code>boolean</code> value
+     * @exception Exception if an error occurs
+     */
+    public boolean invoke(Environment env, InvokeContext context) throws 
Exception {
+        return true;
+    }
+
     public Interpreter getInterpreter() {
         return interpreter;
     }
-    
-    
+
     /* (non-Javadoc)
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
-        if ( this.manager != null ) {
-            if ( this.selector != null ) {
-                this.selector.release( (Component)this.interpreter );
+        if (this.manager != null) {
+            if (this.interpreterSelector != null) {
+                this.interpreterSelector.release((Component) this.interpreter);
                 this.interpreter = null;
+
+                this.manager.release(this.interpreterSelector);
+                this.interpreterSelector = null;
             }
-            this.manager.release( this.selector );
-            this.selector = null;
             this.manager = null;
         }
     }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
       (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java
       Mon Oct  4 15:06:25 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,22 +25,20 @@
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
  * @since September 13, 2002
- * @version CVS $Id: FlowNodeBuilder.java,v 1.3 2004/03/05 13:02:52 
bdelacretaz Exp $
+ * @version CVS $Id$
  */
-public class FlowNodeBuilder
-  extends AbstractParentProcessingNodeBuilder
-{
-  public ProcessingNode buildNode(Configuration config)
-    throws Exception
-  {
-    String language = config.getAttribute("language", "JavaScript");
-    FlowNode node = new FlowNode(language);
+public class FlowNodeBuilder extends AbstractParentProcessingNodeBuilder {
+
+    public ProcessingNode buildNode(Configuration config)
+    throws Exception {
+        String language = config.getAttribute("language", "JavaScript");
+        FlowNode node = new FlowNode(language);
 
-    this.treeBuilder.registerNode("flow", node);
-    this.treeBuilder.setupNode(node, config);
+        this.treeBuilder.registerNode("flow", node);
+        this.treeBuilder.setupNode(node, config);
 
-    this.buildChildNodesList(config);
+        buildChildNodesList(config);
 
-    return node;
-  }
+        return node;
+    }
 }

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     Mon Oct  4 15:06:25 2004
@@ -205,6 +205,9 @@
 
   <changes>
  <release version="@version@" date="@date@">
+   <action dev="VG" type="fix">
+     Flow preserves global variables on sitemap reload.
+   </action>
    <action dev="SW" type="add">
      CForms block: Implementation of the CForm template language using JX 
macros,
      allowing smart page layout that depends on the widgets state and value.

Reply via email to