sylvain     2003/11/11 13:57:18

  Modified:    src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        CallFunctionNode.java CallNodeBuilder.java
  Log:
  Consider as an error calls not sending a response + some code cleanup
  
  Revision  Changes    Path
  1.5       +31 -43    
cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallFunctionNode.java
  
  Index: CallFunctionNode.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallFunctionNode.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CallFunctionNode.java     24 Oct 2003 13:36:40 -0000      1.4
  +++ CallFunctionNode.java     11 Nov 2003 21:57:18 -0000      1.5
  @@ -54,6 +54,7 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.flow.Interpreter;
   import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
   import org.apache.cocoon.components.treeprocessor.InvokeContext;
  @@ -72,11 +73,9 @@
    * @version CVS $Id$
    */
   public class CallFunctionNode extends AbstractProcessingNode implements 
Configurable, Composable {
  -    protected String functionName;
  -    protected String continuationId;
       protected List parameters;
  -    protected VariableResolver functionNameResolver;
  -    protected VariableResolver continuationResolver;
  +    protected VariableResolver functionName;
  +    protected VariableResolver continuationId;
       protected ComponentManager manager;
       protected Interpreter interpreter;
   
  @@ -97,9 +96,9 @@
           return result;
       }
   
  -    public CallFunctionNode(String funName, String contId) {
  -        functionName = funName;
  -        continuationId = contId;
  +    public CallFunctionNode(VariableResolver functionName, VariableResolver 
continuationId) {
  +        this.functionName = functionName;
  +        this.continuationId = continuationId;
       }
   
       public void setInterpreter(Interpreter interp) throws Exception {
  @@ -114,6 +113,11 @@
        * @exception ConfigurationException if an error occurs
        */
       public void configure(Configuration config) throws 
ConfigurationException {
  +        //TODO (SW): Deprecate this in the future.
  +        // It has be found to be bad practice to pass sitemap parameters
  +        // as function arguments, as these are name-value pairs in the 
sitemap
  +        // and positional arguments in the flowscript. If the user doesn't 
respect
  +        // the argument order, this leads to difficult to solve bugs.
           parameters = new ArrayList();
   
           Configuration[] params = config.getChildren("parameter");
  @@ -123,18 +127,6 @@
               String value = param.getAttribute("value", null);
               parameters.add(new Interpreter.Argument(name, value));
           }
  -
  -        try {
  -            // Check to see if we need to resolve the function name or the
  -            // continuation id at runtime
  -            if (functionName != null && 
VariableResolverFactory.needsResolve(functionName))
  -                functionNameResolver = 
VariableResolverFactory.getResolver(functionName, manager);
  -
  -            if (continuationId != null && 
VariableResolverFactory.needsResolve(continuationId))
  -                continuationResolver = 
VariableResolverFactory.getResolver(continuationId, manager);
  -        } catch (PatternException ex) {
  -            throw new ConfigurationException(ex.toString());
  -        }
       }
   
       public void compose(ComponentManager manager) {
  @@ -151,40 +143,36 @@
               params = resolveList(parameters, manager, context, 
env.getObjectModel());
           }
   
  -        String continuation;
  -        if (continuationResolver != null) {
  -            // Need to resolve the function name at runtime
  -            continuation = continuationResolver.resolve(context, 
env.getObjectModel());
  -        } else {
  -            continuation = continuationId;
  -        }
  +        String continuation = continuationId.resolve(context, 
env.getObjectModel());
   
           // If the continuation id is not null, it takes precedence over
           // the function call, so we invoke it here.
  -        if (continuation != null) {
  +        if (continuation != null && continuation.length() > 0) {
               interpreter.handleContinuation(continuation, params, env);
  -            // FIXME (SW) : is a flow allowed not to redirect ?
  -            // If not, we should throw a RNFE here.
  -            return redirector.hasRedirected();
  +            if (!redirector.hasRedirected()) {
  +                throw new ProcessingException("<map:call continuation> did 
not send a response, at " + getLocation());
  +            }
  +            
  +            // Success
  +            return true;
           }
   
           // We don't have a continuation id passed in <map:call>, so invoke
           // the specified function
   
  -        String name;
  -        if (functionNameResolver != null) {
  -            // Need to resolve the function name at runtime
  -            name = functionNameResolver.resolve(context, 
env.getObjectModel());
  -        } else {
  -            name = functionName;
  -        }
  +        String name = functionName.resolve(context, env.getObjectModel());
   
  -        if (name != null) {
  +        if (name != null && name.length() > 0) {
               interpreter.callFunction(name, params, env);
  -            // FIXME (SW) : is a flow allowed not to redirect ?
  -            return redirector.hasRedirected();
  +            if (!redirector.hasRedirected()) {
  +                throw new ProcessingException("<map:call function='" + name 
+ "'> did not send a response, at " + getLocation());
  +            }
  +            
  +            // Success
  +            return true;
           }
  -
  -        return false;
  +        
  +        // Found neither continuation nor function to call
  +        throw new ProcessingException("No function nor continuation given in 
<map:call function> at " + getLocation());
       }
   }
  
  
  
  1.2       +23 -10    
cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNodeBuilder.java
  
  Index: CallNodeBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNodeBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CallNodeBuilder.java      9 Mar 2003 00:09:21 -0000       1.1
  +++ CallNodeBuilder.java      11 Nov 2003 21:57:18 -0000      1.2
  @@ -59,6 +59,7 @@
   import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
   import 
org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
   import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  +import 
org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
   
   /**
    *
  @@ -83,19 +84,31 @@
           continuationId = config.getAttribute("continuation", null);
   
           if (resourceName == null) {
  -          if (functionName == null && continuationId == null)
  -            throw new ConfigurationException("<map:call> must have either a 
'resource', a 'function' or a 'continuation' attribute!");
  -
  -          node = new CallFunctionNode(functionName, continuationId);
  -        }
  -        else {
  -            if (functionName != null || continuationId != null)
  -              throw new ConfigurationException("<map:call> can be used to 
call either a resource, or a function/continuation in the control flow! Please 
specify either <map:call resource=\"...\"/> or <map:call function=\"...\" 
continuation=\"...\"/>.");
  +            // Building a CallFunction node
  +            if (functionName == null && continuationId == null) {
  +                throw new ConfigurationException(
  +                    "<map:call> must have either a 'resource', 'function' or 
'continuation' attribute, at " +
  +                    config.getLocation());
  +            }
  +
  +            node = new CallFunctionNode(
  +                VariableResolverFactory.getResolver(functionName, 
this.manager),
  +                VariableResolverFactory.getResolver(continuationId, 
this.manager)
  +            );
  +            
  +        } else {
  +            // Building a Call(Resource)Node
  +            if (functionName != null || continuationId != null) {
  +                throw new ConfigurationException(
  +                    "<map:call> cannot have both a 'resource' and a 
'function' or 'continuation' attribute, at "
  +                    + config.getLocation()
  +                );
  +            }
               node = new CallNode();
           }
   
           this.treeBuilder.setupNode(this.node, config);
  -        if (node instanceof Configurable)
  +        if (node instanceof Configurable) 
               ((Configurable)this.node).configure(config);
   
           return this.node;
  
  
  

Reply via email to