001    package org.apache.turbine.pipeline;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import java.io.IOException;
025    
026    import org.apache.turbine.util.RunData;
027    import org.apache.turbine.util.TurbineException;
028    
029    /**
030     * Valve that can be used as the basis of Valve implementations.
031     *
032     * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
033     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
034     * @version $Id: AbstractValve.java 757213 2009-03-22 16:43:31Z tv $
035     */
036    public abstract class AbstractValve
037        implements Valve
038    {
039        /**
040         * Initialize this valve for use in a pipeline.
041         *
042         * @throws Exception
043         */
044        public void initialize()
045            throws Exception
046        {
047            // empty
048        }
049    
050        /**
051         * @see org.apache.turbine.Valve#invoke(PipelineData, ValveContext)
052         */
053        public abstract void invoke(PipelineData data, ValveContext context)
054            throws IOException, TurbineException;
055    
056    
057        /**
058         * utility for getting RunData out of the pielineData object.
059         * @param pipelineData
060         * @return
061         */
062        public final RunData getRunData(PipelineData pipelineData)
063        {
064            if(!(pipelineData instanceof RunData)){
065                throw new RuntimeException("Can't cast pipelineData to rundata");
066            }
067            return (RunData)pipelineData;
068        }
069    
070    }