KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > sitemap > PipelinesNode


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.treeprocessor.sitemap;
17
18 import org.apache.avalon.framework.activity.Disposable;
19 import org.apache.avalon.framework.component.ComponentManager;
20 import org.apache.avalon.framework.component.Composable;
21 import org.apache.avalon.framework.logger.Logger;
22
23 import org.apache.cocoon.ConnectionResetException;
24 import org.apache.cocoon.components.treeprocessor.InvokeContext;
25 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
26 import org.apache.cocoon.components.treeprocessor.SimpleParentProcessingNode;
27 import org.apache.cocoon.environment.Environment;
28
29 /**
30  * Handles <map:pipelines>
31  *
32  * @author <a HREF="mailto:juergen.seitz@basf-it-services.com">J&uuml;rgen Seitz</a>
33  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
34  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
35  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
36  * @version $Id: PipelinesNode.java 157153 2005-03-11 20:47:16Z vgritsenko $
37  */

38 public final class PipelinesNode extends SimpleParentProcessingNode
39                                  implements Composable, Disposable {
40
41     private ComponentManager manager;
42
43     private ErrorHandlerHelper errorHandlerHelper;
44
45
46     public PipelinesNode() {
47         this.errorHandlerHelper = new ErrorHandlerHelper();
48     }
49
50     /**
51      * Keep the component manager used everywhere in the tree so that we can
52      * cleanly dispose it.
53      */

54     public void compose(ComponentManager manager) {
55         this.manager = manager;
56         this.errorHandlerHelper.compose(manager);
57     }
58
59     public void enableLogging(Logger logger) {
60         super.enableLogging(logger);
61         this.errorHandlerHelper.enableLogging(logger);
62     }
63
64     public void setErrorHandler(ProcessingNode node) {
65         this.errorHandlerHelper.set500Handler(node);
66     }
67
68     public void setChildren(ProcessingNode[] nodes) {
69         // Mark the last pipeline so that it can throw a ResourceNotFoundException
70
((PipelineNode) nodes[nodes.length - 1]).setLast(true);
71         super.setChildren(nodes);
72     }
73
74     /**
75      * Process the environment. Also adds a <code>SourceResolver</code>
76      * and a <code>Redirector</code> in the object model. The previous resolver and
77      * redirector, if any, are restored before return.
78      */

79     public final boolean invoke(Environment env, InvokeContext context)
80     throws Exception JavaDoc {
81
82         // Perform any common invoke functionality
83
super.invoke(env, context);
84
85         // Recompose context (and pipelines) to the local component manager
86
context.recompose(this.manager);
87
88         try {
89             // FIXME: Is there any useful information that can be passed as top-level parameters,
90
// such as the URI of the mount point ?
91

92             return invokeNodes(this.children, env, context);
93
94         } catch (ConnectionResetException e) {
95             // Will be reported by CocoonServlet, rethrowing
96
throw e;
97         } catch (Exception JavaDoc ex) {
98             // Invoke pipelines handler
99
return this.errorHandlerHelper.invokeErrorHandler(ex, env, context);
100         }
101     }
102
103     /**
104      * Dispose the component manager.
105      */

106     public void dispose() {
107         if (this.manager instanceof Disposable) {
108             ((Disposable) this.manager).dispose();
109         }
110         this.manager = null;
111     }
112 }
113
Popular Tags