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 <code>flow.xmap</code>. */ 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: * * <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> - * <map:call function="..."/> - * </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> + * <map:call function="..."/> + * </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/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 <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> - * @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 <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> - * @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 <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a> * @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 - * <code><map:flow></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><map:flow></code> * 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 + * <code><map:flow></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.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 <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; + } }