    001package 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
    024import java.io.IOException;
    025
    026import org.apache.turbine.util.RunData;
    027import 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 1706239 2015-10-01 13:18:35Z tv $
    035 */
    036public abstract class AbstractValve
    037    implements Valve
    038{
    039    /**
    040     * Initialize this valve for use in a pipeline.
    041     *
    042     * @throws Exception
    043     */
    044    @Override
    045    public void initialize()
    046        throws Exception
    047    {
    048        // empty
    049    }
    050
    051    /**
    052     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
    053     */
    054    @Override
    055    public abstract void invoke(PipelineData data, ValveContext context)
    056        throws IOException, TurbineException;
    057
    058
    059    /**
    060     * utility for getting RunData out of the pipelineData object.
    061     * @param pipelineData
    062     * @return the RunData object extracted from pipelineData
    063     */
    064    public final RunData getRunData(PipelineData pipelineData)
    065    {
    066        if(!(pipelineData instanceof RunData))
    067        {
    068            throw new RuntimeException("Can't cast pipelineData to rundata");
    069        }
    070        return (RunData)pipelineData;
    071    }
    072
    073}