ovidiu      2002/09/24 01:23:00

  Modified:    src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        CallFunctionNode.java
  Log:
  Changed to handle resuming continuation objects as well as invoking
  control flow functions.
  
  Revision  Changes    Path
  1.5       +56 -44    
xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallFunctionNode.java
  
  Index: CallFunctionNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/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     8 Sep 2002 00:27:06 -0000       1.4
  +++ CallFunctionNode.java     24 Sep 2002 08:23:00 -0000      1.5
  @@ -69,22 +69,25 @@
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.Redirector;
   import org.apache.cocoon.sitemap.PatternException;
  +import org.apache.cocoon.components.flow.Interpreter;
   
   /**
  - * Node handler for calling functions in the control flow layer.
  + * Node handler for calling functions and resuming continuations in
  + * the control flow layer.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
    * @since March 13, 2002
    */
   public class CallFunctionNode extends AbstractProcessingNode
  -  implements Configurable, Composable, Initializable
  +  implements Configurable, Composable
   {
     protected String functionName;
  +  protected String continuationId;
     protected List parameters;
  -  protected VariableResolver resourceResolver;
  +  protected VariableResolver functionNameResolver;
  +  protected VariableResolver continuationResolver;
     protected ComponentManager manager;
  -  protected CategoryNode resources;
  -  protected String language;
  +  protected Interpreter interpreter;
   
     public static List resolveList(List expressions, ComponentManager manager, List 
mapStack, Map objectModel)
       throws PatternException 
  @@ -104,15 +107,16 @@
       return result;
     }
   
  -  public CallFunctionNode(String funName)
  +  public CallFunctionNode(String funName, String contId)
     {
       functionName = funName;
  +    continuationId = contId;
     }
   
  -  public void setResources(CategoryNode resources)
  +  public void setInterpreter(Interpreter interp)
       throws Exception
     {
  -    this.resources = resources;
  +    this.interpreter = interp;
     }
   
     /**
  @@ -125,8 +129,6 @@
     public void configure(Configuration config)
       throws ConfigurationException
     {
  -    language = config.getAttribute("language", null);
  -
       parameters = new ArrayList();
   
       Configuration[] params = config.getChildren("parameter");
  @@ -138,10 +140,17 @@
       }
   
       try {
  -      if (VariableResolverFactory.needsResolve(functionName)) {
  -        // Will always be resolved at invoke time
  -        this.resourceResolver = VariableResolverFactory.getResolver(functionName, 
this.manager);
  -      }
  +      // 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());
  @@ -150,16 +159,7 @@
   
     public void compose(ComponentManager manager)
     {
  -    this.manager = manager;
  -  }
  -
  -  public void initialize()
  -    throws Exception
  -  {
  -    InterpreterSelector selector
  -      = (InterpreterSelector)manager.lookup(Interpreter.ROLE);
  -    if (language == null)
  -      language = selector.getDefaultLanguage();
  +    manager = manager;
     }
   
     public boolean invoke(Environment env, InvokeContext context)
  @@ -167,34 +167,46 @@
     {
       List params = null;
   
  +    env.setComponentManager(manager);
  +
       // Resolve parameters
  -    if (this.parameters != null)
  -      params = resolveList(this.parameters, this.manager, context.getMapStack(), 
env.getObjectModel());
  +    if (parameters != null)
  +      params = resolveList(parameters, manager, context.getMapStack(),
  +                           env.getObjectModel());
   
  -    String name = functionName;
  -    if (resourceResolver != null) {
  +    String continuation;
  +    if (continuationResolver != null) {
         // Need to resolve the function name at runtime
  -      name = resourceResolver.resolve(context.getMapStack(), env.getObjectModel());
  +      continuation = continuationResolver.resolve(context.getMapStack(),
  +                                                  env.getObjectModel());
       }
  +    else
  +      continuation = continuationId;
   
  -    InterpreterSelector selector
  -      = (InterpreterSelector)manager.lookup(Interpreter.ROLE);
  -    if (language == null)
  -      language = selector.getDefaultLanguage();
  -    
  -    // Obtain the Interpreter instance for this language
  -    Interpreter interpreter = (Interpreter)selector.select(language);
  +    // If the continuation id is not null, it takes precedence over
  +    // the function call, so we invoke it here.
  +    if (continuation != null) {
  +      interpreter.handleContinuation(continuation, params, env);
  +      return true;
  +    }
   
  -    // Obtain the redirector
  -    Redirector redirector = PipelinesNode.getRedirector(env);
  +    // We don't have a continuation id passed in <map:call>, so invoke
  +    // the specified function
   
  -    env.setComponentManager(this.manager);
  -    try {
  -      interpreter.callFunction(name, params, env /*, redirector*/);
  +    String name;
  +    if (functionNameResolver != null) {
  +      // Need to resolve the function name at runtime
  +      name = functionNameResolver.resolve(context.getMapStack(),
  +                                          env.getObjectModel());
       }
  -    finally {
  -      selector.release((Component)interpreter);
  +    else
  +      name = functionName;
  +
  +    if (name != null) {
  +      interpreter.callFunction(name, params, env);
  +      return true;
       }
  -    return true;
  +
  +    return false;
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to