KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component;
20 import org.apache.avalon.framework.component.ComponentException;
21 import org.apache.avalon.framework.component.ComponentManager;
22 import org.apache.avalon.framework.component.ComponentSelector;
23 import org.apache.avalon.framework.component.Composable;
24
25 import org.apache.cocoon.components.flow.Interpreter;
26 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
27 import org.apache.cocoon.components.treeprocessor.InvokeContext;
28 import org.apache.cocoon.environment.Environment;
29
30 /**
31  * Handler for <map:flow> element in the sitemap.
32  *
33  * @author <a HREF="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
34  * @since September 13, 2002
35  * @version CVS $Id: FlowNode.java 232400 2005-08-12 22:14:26Z sylvain $
36  */

37 public class FlowNode extends AbstractProcessingNode
38                       implements Composable, Disposable {
39
40     private ComponentManager manager;
41     private String JavaDoc language;
42     private Interpreter interpreter;
43     private ComponentSelector interpreterSelector;
44
45     public FlowNode(String JavaDoc language) {
46         this.language = language;
47     }
48
49     /**
50      * Lookup an flow {@link org.apache.cocoon.components.flow.Interpreter}
51      * instance to hold the scripts defined within the <code>&lt;map:flow&gt;</code>
52      * in the sitemap.
53      *
54      * @param manager a <code>ComponentManager</code> value
55      * @exception ComponentException if no flow interpreter could be obtained
56      */

57     public void compose(ComponentManager manager) throws ComponentException {
58         this.manager = manager;
59
60         try {
61             this.interpreterSelector = (ComponentSelector) manager.lookup(Interpreter.ROLE);
62             // Obtain the Interpreter instance for this language
63
this.interpreter = (Interpreter) this.interpreterSelector.select(language);
64             // Set interpreter ID as URI of the flow node (full sitemap file path)
65
this.interpreter.setInterpreterID(this.location.getURI());
66         } catch (ComponentException e) {
67             throw e;
68         } catch (Exception JavaDoc e) {
69             throw new ComponentException(language,
70                                          "FlowNode: Couldn't obtain a flow interpreter for '" + language +
71                                          "' at " + getLocation(), e);
72         }
73     }
74
75     /**
76      * This method should never be called by the TreeProcessor, since a
77      * <code>&lt;map:flow&gt;</code> element should not be in an
78      * "executable" sitemap node.
79      *
80      * @param env an <code>Environment</code> value
81      * @param context an <code>InvokeContext</code> value
82      * @return a <code>boolean</code> value
83      * @exception Exception if an error occurs
84      */

85     public boolean invoke(Environment env, InvokeContext context) throws Exception JavaDoc {
86         return true;
87     }
88
89     public Interpreter getInterpreter() {
90         return interpreter;
91     }
92
93     /* (non-Javadoc)
94      * @see org.apache.avalon.framework.activity.Disposable#dispose()
95      */

96     public void dispose() {
97         if (this.manager != null) {
98             if (this.interpreterSelector != null) {
99                 this.interpreterSelector.release((Component) this.interpreter);
100                 this.interpreter = null;
101
102                 this.manager.release(this.interpreterSelector);
103                 this.interpreterSelector = null;
104             }
105             this.manager = null;
106         }
107     }
108 }
109
Popular Tags