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