001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.treeprocessor.sitemap;
018:
019: import org.apache.avalon.framework.activity.Disposable;
020: import org.apache.avalon.framework.component.Component;
021: import org.apache.avalon.framework.component.ComponentException;
022: import org.apache.avalon.framework.component.ComponentManager;
023: import org.apache.avalon.framework.component.ComponentSelector;
024: import org.apache.avalon.framework.component.Composable;
025:
026: import org.apache.cocoon.components.flow.Interpreter;
027: import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
028: import org.apache.cocoon.components.treeprocessor.InvokeContext;
029: import org.apache.cocoon.environment.Environment;
030:
031: /**
032: * Handler for <map:flow> element in the sitemap.
033: *
034: * @author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
035: * @since September 13, 2002
036: * @version CVS $Id: FlowNode.java 433543 2006-08-22 06:22:54Z crossley $
037: */
038: public class FlowNode extends AbstractProcessingNode implements
039: Composable, Disposable {
040:
041: private ComponentManager manager;
042: private String language;
043: private Interpreter interpreter;
044: private ComponentSelector interpreterSelector;
045:
046: public FlowNode(String language) {
047: this .language = language;
048: }
049:
050: /**
051: * Lookup an flow {@link org.apache.cocoon.components.flow.Interpreter}
052: * instance to hold the scripts defined within the <code><map:flow></code>
053: * in the sitemap.
054: *
055: * @param manager a <code>ComponentManager</code> value
056: * @exception ComponentException if no flow interpreter could be obtained
057: */
058: public void compose(ComponentManager manager)
059: throws ComponentException {
060: this .manager = manager;
061:
062: try {
063: this .interpreterSelector = (ComponentSelector) manager
064: .lookup(Interpreter.ROLE);
065: // Obtain the Interpreter instance for this language
066: this .interpreter = (Interpreter) this .interpreterSelector
067: .select(language);
068: // Set interpreter ID as URI of the flow node (full sitemap file path)
069: this .interpreter.setInterpreterID(this .location.getURI());
070: } catch (ComponentException e) {
071: throw e;
072: } catch (Exception e) {
073: throw new ComponentException(language,
074: "FlowNode: Couldn't obtain a flow interpreter for '"
075: + language + "' at " + getLocation(), e);
076: }
077: }
078:
079: /**
080: * This method should never be called by the TreeProcessor, since a
081: * <code><map:flow></code> element should not be in an
082: * "executable" sitemap node.
083: *
084: * @param env an <code>Environment</code> value
085: * @param context an <code>InvokeContext</code> value
086: * @return a <code>boolean</code> value
087: * @exception Exception if an error occurs
088: */
089: public boolean invoke(Environment env, InvokeContext context)
090: throws Exception {
091: return true;
092: }
093:
094: public Interpreter getInterpreter() {
095: return interpreter;
096: }
097:
098: /* (non-Javadoc)
099: * @see org.apache.avalon.framework.activity.Disposable#dispose()
100: */
101: public void dispose() {
102: if (this .manager != null) {
103: if (this .interpreterSelector != null) {
104: this .interpreterSelector
105: .release((Component) this.interpreter);
106: this.interpreter = null;
107:
108: this.manager.release(this.interpreterSelector);
109: this.interpreterSelector = null;
110: }
111: this.manager = null;
112: }
113: }
114: }
|