Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 74584 invoked from network); 4 Oct 2004 20:45:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Oct 2004 20:45:44 -0000 Received: (qmail 51611 invoked by uid 500); 4 Oct 2004 20:45:41 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 51366 invoked by uid 500); 4 Oct 2004 20:45:39 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 51355 invoked by uid 99); 4 Oct 2004 20:45:38 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 04 Oct 2004 13:45:37 -0700 Received: (qmail 74468 invoked by uid 65534); 4 Oct 2004 20:45:36 -0000 Date: 4 Oct 2004 20:45:36 -0000 Message-ID: <20041004204536.74465.qmail@minotaur.apache.org> From: vgritsenko@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 53746 - in cocoon/trunk/src/java/org/apache/cocoon/components: flow treeprocessor treeprocessor/sitemap X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: vgritsenko Date: Mon Oct 4 13:45:35 2004 New Revision: 53746 Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java Log: Flow preserves global variables on sitemap reload. Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java Mon Oct 4 13:45:35 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; @@ -87,12 +85,16 @@ * through the "check-time" XML attribute in flow.xmap. */ 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/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/Interpreter.java Mon Oct 4 13:45:35 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: * *
    - * *
  • - * *

    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. * *

  • - * *

    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. * *

  • - * *

    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. - * *

* * @author Ovidiu Predescu * @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 - * - *
-   *   <map:call function="..."/>
-   * 
- * - * 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. - * - *

The params argument is a List object - * that contains Interpreter.Argument instances, - * representing the parameters to be passed to the called - * function. An Argument 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. - * - *

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. - * - *

The current implementation assumes the sitemap implementation - * is TreeProcessor. - * - * @param funName a String value, the name of the - * function to call - * @param params a List object whose components are - * CallFunctionNode.Argument instances. The interpretation of the - * parameters is left to the actual implementation of the - * interpreter. - * @param redirector a Redirector 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 + * + *

+     *   <map:call function="..."/>
+     * 
+ * + * 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. + * + *

The params argument is a List object + * that contains Interpreter.Argument instances, + * representing the parameters to be passed to the called + * function. An Argument 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. + * + *

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. + * + *

The current implementation assumes the sitemap implementation + * is TreeProcessor. + * + * @param funName a String value, the name of the + * function to call + * @param params a List object whose components are + * CallFunctionNode.Argument instances. The interpretation of the + * parameters is left to the actual implementation of the + * interpreter. + * @param redirector a Redirector used to call views + */ + void callFunction(String funName, List params, Redirector redirector) throws Exception; - /** - * Forward the request to a Cocoon pipeline. - * - * @param uri a String, the URI of the forwarded request - * @param bizData an Object, the business data object - * to be made available to the forwarded pipeline - * @param continuation a WebContinuation, the - * continuation to be called to resume the processing - * @param redirector a Redirector 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 String, the URI of the forwarded request + * @param bizData an Object, the business data object + * to be made available to the forwarded pipeline + * @param continuation a WebContinuation, the + * continuation to be called to resume the processing + * @param redirector a Redirector 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 - * continuationId string. - * - * @param continuationId a String value - * - * @param params a List value, containing the - * parameters to be passed when invoking the continuation. As - * opposed to the parameters passed by callFunction, - * these parameters will only become available in the language's - * environment, if at all. - * - * @param redirector a Redirector 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 + * continuationId string. + * + * @param continuationId a String value + * + * @param params a List value, containing the + * parameters to be passed when invoking the continuation. As + * opposed to the parameters passed by callFunction, + * these parameters will only become available in the language's + * environment, if at all. + * + * @param redirector a Redirector used to call views + * @exception Exception if an error occurs + */ + void handleContinuation(String continuationId, List params, + Redirector redirector) throws Exception; } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java Mon Oct 4 13:45:35 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 Sylvain Wallez - * @version CVS $Id: AbstractParentProcessingNodeBuilder.java,v 1.4 2004/06/09 09:41:15 cziegeler 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/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java Mon Oct 4 13:45:35 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. @@ -28,15 +28,13 @@ /** * * @author Sylvain Wallez - * @version CVS $Id: AbstractProcessingNodeBuilder.java,v 1.8 2004/07/17 10:51:15 joerg Exp $ + * @version CVS $Id$ */ - - public abstract class AbstractProcessingNodeBuilder extends AbstractLogEnabled - implements ProcessingNodeBuilder { + implements ProcessingNodeBuilder { protected TreeBuilder treeBuilder; - + protected ServiceManager manager; /* (non-Javadoc) @@ -96,8 +94,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/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNode.java Mon Oct 4 13:45:35 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. @@ -16,17 +16,14 @@ package org.apache.cocoon.components.treeprocessor.sitemap; import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.ServiceSelector; import org.apache.avalon.framework.service.Serviceable; -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; /** @@ -34,42 +31,21 @@ * * @author Ovidiu Predescu * @since September 13, 2002 - * @version CVS $Id: FlowNode.java,v 1.7 2004/07/17 10:51:15 joerg Exp $ + * @version CVS $Id$ */ public class FlowNode extends AbstractProcessingNode - implements Serviceable, Contextualizable, Disposable { + implements Serviceable, Disposable { - ServiceManager manager; - String language; - Context context; - Interpreter interpreter; - ServiceSelector interpreterSelector; + private ServiceManager manager; + private String language; + private Interpreter interpreter; + private ServiceSelector interpreterSelector; public FlowNode(String language) { this.language = language; } /** - * This method should never be called by the TreeProcessor, since a - * <map:flow> element should not be in an - * "executable" sitemap node. - * - * @param env an Environment value - * @param context an InvokeContext value - * @return a boolean 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 {@link org.apache.cocoon.components.flow.Interpreter} * instance to hold the scripts defined within the <map:flow> * in the sitemap. @@ -81,35 +57,51 @@ this.manager = manager; try { - this.interpreterSelector = (ServiceSelector)manager.lookup(Interpreter.ROLE); + this.interpreterSelector = (ServiceSelector) manager.lookup(Interpreter.ROLE); // Obtain the Interpreter instance for this language - this.interpreter = (Interpreter)this.interpreterSelector.select(language); - } catch (ServiceException ce) { - throw ce; - } 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 (ServiceException e) { + throw e; + } catch (Exception e) { throw new ServiceException(language, - "ScriptNode: Couldn't obtain a flow interpreter for " + language + - " at " + getLocation(), ex); + "FlowNode: Couldn't obtain a flow interpreter for '" + language + + "' at " + getLocation(), e); } } + /** + * This method should never be called by the TreeProcessor, since a + * <map:flow> element should not be in an + * "executable" sitemap node. + * + * @param env an Environment value + * @param context an InvokeContext value + * @return a boolean 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.interpreterSelector != null ) { - this.interpreterSelector.release(this.interpreter ); + if (this.manager != null) { + if (this.interpreterSelector != null) { + this.interpreterSelector.release(this.interpreter); this.interpreter = null; - this.manager.release( this.interpreterSelector ); + + this.manager.release(this.interpreterSelector); this.interpreterSelector = null; } this.manager = null; } - - } - - public Interpreter getInterpreter() { - return interpreter; } } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/FlowNodeBuilder.java Mon Oct 4 13:45:35 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 Ovidiu Predescu * @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; + } }