001package org.apache.turbine.pipeline;
002
003import java.util.Map;
004
005import org.apache.turbine.util.RunData;
006import org.apache.turbine.util.TurbineRuntimeException;
007
008
009/*
010 * Licensed to the Apache Software Foundation (ASF) under one
011 * or more contributor license agreements.  See the NOTICE file
012 * distributed with this work for additional information
013 * regarding copyright ownership.  The ASF licenses this file
014 * to you under the Apache License, Version 2.0 (the
015 * "License"); you may not use this file except in compliance
016 * with the License.  You may obtain a copy of the License at
017 *
018 *   http://www.apache.org/licenses/LICENSE-2.0
019 *
020 * Unless required by applicable law or agreed to in writing,
021 * software distributed under the License is distributed on an
022 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023 * KIND, either express or implied.  See the License for the
024 * specific language governing permissions and limitations
025 * under the License.
026 */
027
028
029/**
030 * <p>A <b>PipelineData</b> is a holder for data being passed from one
031 * Valve to the next.
032 * The detailed contract for a Valve is included in the description of
033 * the <code>invoke()</code> method below.</p>
034 *
035 * <b>HISTORICAL NOTE</b>:  The "PipelineData" name was assigned to this
036 * holder as it functions similarly to the RunData object, but without
037 * the additional methods
038 *
039 * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh</a>
040 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
041 */
042public interface PipelineData extends AutoCloseable
043{
044    /**
045     * Put a configured map of objects into the pipeline data object
046     *
047     * @param name the key class
048     * @param value the value map
049     */
050    void put(Class<?> name, Map<Class<?>, ? super Object> value);
051
052    /**
053     * Get the configured map of objects for the given key
054     *
055     * @param name the key class
056     * @return the value map or null if no such key exists
057     */
058    Map<Class<?>, ? super Object> get(Class<?> name);
059
060    /**
061     * Get a value from the configured map of objects for the given keys
062     *
063     * @param key the key class
064     * @param innerKey the key into the value map
065     *
066     * @param <T> the type of the inner key
067     *
068     * @return the inner value or null if no such keys exist
069     */
070    <T> T get(Class<?> key, Class<T> innerKey);
071
072    /**
073     * Get RunData from PipelineData
074     *
075     * @return RunData extracted from PipelineData
076     */
077    default RunData getRunData()
078    {
079        if (!(this instanceof RunData))
080        {
081            throw new TurbineRuntimeException("Cannot cast to rundata from pipeline data.");
082        }
083        return (RunData) this;
084    }
085}