Coverage Report - org.apache.tapestry.components.Block
 
Classes in this File Line Coverage Branch Coverage Complexity
Block
0%
0/13
N/A
1
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.components;
 16  
 
 17  
 import org.apache.hivemind.util.Defense;
 18  
 import org.apache.tapestry.AbstractComponent;
 19  
 import org.apache.tapestry.IComponent;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 
 23  
 /**
 24  
  * Prevents its contents from being rendered until triggered by an {@link RenderBlock} component. [<a
 25  
  * href="../../../../../components/general/block.html">Component Reference</a>]
 26  
  * <p>
 27  
  * Block and {@link RenderBlock} are used to build a certain class of complicated component that
 28  
  * can't be assembled using the normal wrapping containment. Such a super component would have two
 29  
  * or more sections that need to be supplied by the containing page (or component).
 30  
  * <p>
 31  
  * Using Blocks, the blocks can be provided as parameters to the super component.
 32  
  * <p>
 33  
  * The invoker property gives the components inside the block access to the component (typically an
 34  
  * {@link RenderBlock}) that rendered the block. More often, the {@link #getParameter(String)}
 35  
  * method is used to get parameters <em>of the invoking component</em>.
 36  
  * 
 37  
  * @author Howard Lewis Ship
 38  
  * @since 0.2.9
 39  
  */
 40  
 
 41  0
 public abstract class Block extends AbstractComponent
 42  
 {
 43  
     private IComponent _invoker;
 44  
 
 45  
     /**
 46  
      * Provides access to the invoking component's parameters.
 47  
      * 
 48  
      * @since 4.0
 49  
      */
 50  
 
 51  
     public Object getParameter(String name)
 52  
     {
 53  0
         return _invoker.getBinding(name).getObject();
 54  
     }
 55  
 
 56  
     public void renderForComponent(IMarkupWriter writer, IRequestCycle cycle, IComponent invoker)
 57  
     {
 58  0
         Defense.notNull(invoker, "invoker");
 59  
 
 60  0
         IComponent oldInvoker = _invoker;
 61  
 
 62  
         try
 63  
         {
 64  0
             _invoker = invoker;
 65  0
             renderBody(writer, cycle);
 66  
         }
 67  
         finally
 68  
         {
 69  0
             _invoker = oldInvoker;
 70  
 
 71  0
         }
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Does nothing; the idea of a Block is to defer the rendering of the body of the block until an
 76  
      * {@link RenderBlock} forces it out.
 77  
      */
 78  
 
 79  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 80  
     {
 81  
         // Nothing!
 82  0
     }
 83  
 
 84  
     /**
 85  
      * Returns the object which invoked this Block's
 86  
      * {@link #renderForComponent(IMarkupWriter, IRequestCycle, IComponent)} method. This is often
 87  
      * used to access the informal parameters of a {@link RenderBlock} component.
 88  
      * 
 89  
      * @since 4.0
 90  
      */
 91  
     public IComponent getInvoker()
 92  
     {
 93  0
         return _invoker;
 94  
     }
 95  
 
 96  
     /**
 97  
      * Used for testing only.
 98  
      * 
 99  
      * @since 4.0
 100  
      */
 101  
 
 102  
     void setInvoker(IComponent invoker)
 103  
     {
 104  0
         _invoker = invoker;
 105  0
     }
 106  
 }