Save This Page
Home » cocoon-2.1.11-src » org.apache » cocoon » components » treeprocessor » sitemap » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.cocoon.components.treeprocessor.sitemap;
   18   
   19   import org.apache.avalon.framework.activity.Disposable;
   20   import org.apache.avalon.framework.component.ComponentManager;
   21   import org.apache.avalon.framework.component.Composable;
   22   import org.apache.avalon.framework.logger.Logger;
   23   
   24   import org.apache.cocoon.ConnectionResetException;
   25   import org.apache.cocoon.components.treeprocessor.InvokeContext;
   26   import org.apache.cocoon.components.treeprocessor.ProcessingNode;
   27   import org.apache.cocoon.components.treeprocessor.SimpleParentProcessingNode;
   28   import org.apache.cocoon.environment.Environment;
   29   
   30   /**
   31    * Handles <map:pipelines>
   32    *
   33    * @author <a href="mailto:juergen.seitz@basf-it-services.com">J&uuml;rgen Seitz</a>
   34    * @author <a href="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
   35    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   36    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   37    * @version $Id: PipelinesNode.java 433543 2006-08-22 06:22:54Z crossley $
   38    */
   39   public final class PipelinesNode extends SimpleParentProcessingNode
   40                                    implements Composable, Disposable {
   41   
   42       private ComponentManager manager;
   43   
   44       private ErrorHandlerHelper errorHandlerHelper;
   45   
   46   
   47       public PipelinesNode() {
   48           this.errorHandlerHelper = new ErrorHandlerHelper();
   49       }
   50   
   51       /**
   52        * Keep the component manager used everywhere in the tree so that we can
   53        * cleanly dispose it.
   54        */
   55       public void compose(ComponentManager manager) {
   56           this.manager = manager;
   57           this.errorHandlerHelper.compose(manager);
   58       }
   59   
   60       public void enableLogging(Logger logger) {
   61           super.enableLogging(logger);
   62           this.errorHandlerHelper.enableLogging(logger);
   63       }
   64   
   65       public void setErrorHandler(ProcessingNode node) {
   66           this.errorHandlerHelper.set500Handler(node);
   67       }
   68   
   69       public void setChildren(ProcessingNode[] nodes) {
   70           // Mark the last pipeline so that it can throw a ResourceNotFoundException
   71           ((PipelineNode) nodes[nodes.length - 1]).setLast(true);
   72           super.setChildren(nodes);
   73       }
   74   
   75       /**
   76        * Process the environment. Also adds a <code>SourceResolver</code>
   77        * and a <code>Redirector</code> in the object model. The previous resolver and
   78        * redirector, if any, are restored before return.
   79        */
   80       public final boolean invoke(Environment env, InvokeContext context)
   81       throws Exception {
   82   
   83           // Perform any common invoke functionality
   84           super.invoke(env, context);
   85   
   86           // Recompose context (and pipelines) to the local component manager
   87           context.recompose(this.manager);
   88   
   89           try {
   90               // FIXME: Is there any useful information that can be passed as top-level parameters,
   91               //        such as the URI of the mount point ?
   92   
   93               return invokeNodes(this.children, env, context);
   94   
   95           } catch (ConnectionResetException e) {
   96               // Will be reported by CocoonServlet, rethrowing
   97               throw e;
   98           } catch (Exception ex) {
   99               // Invoke pipelines handler
  100               return this.errorHandlerHelper.invokeErrorHandler(ex, env, context);
  101           }
  102       }
  103   
  104       /**
  105        * Dispose the component manager.
  106        */
  107       public void dispose() {
  108           if (this.manager instanceof Disposable) {
  109               ((Disposable) this.manager).dispose();
  110           }
  111           this.manager = null;
  112       }
  113   }

Save This Page
Home » cocoon-2.1.11-src » org.apache » cocoon » components » treeprocessor » sitemap » [javadoc | source]