Coverage Report - org.apache.tiles.request.render.BasicRendererFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicRendererFactory
100%
13/13
100%
4/4
1.75
 
 1  
 /*
 2  
  * $Id: BasicRendererFactory.java 1306435 2012-03-28 15:39:11Z nlebas $
 3  
  *
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 package org.apache.tiles.request.render;
 22  
 
 23  
 import java.util.HashMap;
 24  
 import java.util.Map;
 25  
 
 26  
 
 27  
 /**
 28  
  * Basic renderer factory implementation.
 29  
  *
 30  
  * @version $Rev: 1306435 $ $Date: 2012-03-29 02:39:11 +1100 (Thu, 29 Mar 2012) $
 31  
  */
 32  
 public class BasicRendererFactory implements RendererFactory {
 33  
 
 34  
     /**
 35  
      * The renderer name/renderer map.
 36  
      */
 37  
     protected Map<String, Renderer> renderers;
 38  
 
 39  
     /**
 40  
      * The default renderer.
 41  
      */
 42  
     protected Renderer defaultRenderer;
 43  
 
 44  
     /**
 45  
      * Constructor.
 46  
      */
 47  3
     public BasicRendererFactory() {
 48  3
         renderers = new HashMap<String, Renderer>();
 49  3
     }
 50  
 
 51  
     /** {@inheritDoc} */
 52  
     public Renderer getRenderer(String name) {
 53  
         Renderer retValue;
 54  5
         if (name != null) {
 55  4
             retValue = renderers.get(name);
 56  4
             if (retValue == null) {
 57  1
                 throw new NoSuchRendererException("Cannot find a renderer named '" + name + "'");
 58  
             }
 59  
         } else {
 60  1
             retValue = defaultRenderer;
 61  
         }
 62  
 
 63  4
         return retValue;
 64  
     }
 65  
 
 66  
     /**
 67  
      * Sets the default renderer.
 68  
      *
 69  
      * @param renderer The default renderer.
 70  
      */
 71  
     public void setDefaultRenderer(Renderer renderer) {
 72  2
         this.defaultRenderer = renderer;
 73  2
     }
 74  
 
 75  
     /**
 76  
      * Registers a renderer.
 77  
      *
 78  
      * @param name The name of the renderer.
 79  
      * @param renderer The renderer to register.
 80  
      */
 81  
     public void registerRenderer(String name, Renderer renderer) {
 82  6
         renderers.put(name, renderer);
 83  6
     }
 84  
 }