Coverage Report - org.apache.turbine.pipeline.DefaultPipelineData
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultPipelineData
100%
13/13
75%
3/4
1,75
 
 1  
 package org.apache.turbine.pipeline;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.Map;
 5  
 
 6  
 import org.apache.turbine.services.TurbineServices;
 7  
 import org.apache.turbine.services.rundata.RunDataService;
 8  
 import org.apache.turbine.util.RunData;
 9  
 
 10  
 
 11  
 /*
 12  
  * Licensed to the Apache Software Foundation (ASF) under one
 13  
  * or more contributor license agreements.  See the NOTICE file
 14  
  * distributed with this work for additional information
 15  
  * regarding copyright ownership.  The ASF licenses this file
 16  
  * to you under the Apache License, Version 2.0 (the
 17  
  * "License"); you may not use this file except in compliance
 18  
  * with the License.  You may obtain a copy of the License at
 19  
  *
 20  
  *   http://www.apache.org/licenses/LICENSE-2.0
 21  
  *
 22  
  * Unless required by applicable law or agreed to in writing,
 23  
  * software distributed under the License is distributed on an
 24  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 25  
  * KIND, either express or implied.  See the License for the
 26  
  * specific language governing permissions and limitations
 27  
  * under the License.
 28  
  */
 29  
 
 30  
 
 31  
 /**
 32  
  * <p>A <b>PipelineData</b> is a holder for data being passed from one
 33  
  * Valve to the next.
 34  
  * The detailed contract for a Valve is included in the description of
 35  
  * the <code>invoke()</code> method below.</p>
 36  
  *
 37  
  * <b>HISTORICAL NOTE</b>:  The "PipelineData" name was assigned to this
 38  
  * holder as it functions similarly to the RunData object, but without
 39  
  * the additional methods
 40  
  *
 41  
  * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh</a>
 42  
  * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
 43  
  */
 44  105
 public class DefaultPipelineData implements PipelineData
 45  
 {
 46  105
     private final Map<Class<?>, Map<Class<?>, ? super Object>> map =
 47  
         new HashMap<Class<?>, Map<Class<?>, ? super Object>>();
 48  
 
 49  
     /**
 50  
      * Put a configured map of objects into the pipeline data object
 51  
      *
 52  
      * @param key the key class
 53  
      * @param value the value map
 54  
      */
 55  
     @Override
 56  
     public void put(Class<?> key, Map<Class<?>, ? super Object> value)
 57  
     {
 58  105
         map.put(key, value);
 59  105
     }
 60  
 
 61  
     /**
 62  
      * Get the configured map of objects for the given key
 63  
      *
 64  
      * @param key the key class
 65  
      * @return the value map or null if no such key exists
 66  
      */
 67  
     @Override
 68  
     public Map<Class<?>, ? super Object> get(Class<?> key)
 69  
     {
 70  1884
         return map.get(key);
 71  
     }
 72  
 
 73  
     /**
 74  
      * Get a value from the configured map of objects for the given keys
 75  
      *
 76  
      * @param key the key class
 77  
      * @param innerKey the key into the value map
 78  
      * @return the inner value or null if no such keys exist
 79  
      */
 80  
     @Override
 81  
     @SuppressWarnings("unchecked")
 82  
     public <T> T get(Class<?> key, Class<T> innerKey)
 83  
     {
 84  1068
         Map<Class<?>, ? super Object> innerMap = get(key);
 85  1068
         if (innerMap == null)
 86  
         {
 87  9
             return null;
 88  
         }
 89  1059
         return (T) innerMap.get(innerKey);
 90  
     }
 91  
 
 92  
     /**
 93  
      * Put object back into RunDataService for recycling
 94  
      */
 95  
     @Override
 96  
     public void close() throws Exception
 97  
     {
 98  3
         RunDataService rds = (RunDataService) TurbineServices.getInstance().getService(RunDataService.SERVICE_NAME);
 99  3
         if (rds != null)
 100  
         {
 101  3
             rds.putRunData((RunData) this);
 102  
         }
 103  3
     }
 104  
 }