Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 90   Methods: 1
NCLOC: 39   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Option.java 100% 100% 100% 100%
coverage
 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.form;
 16   
 
 17   
 import org.apache.hivemind.ApplicationRuntimeException;
 18   
 import org.apache.tapestry.AbstractComponent;
 19   
 import org.apache.tapestry.IMarkupWriter;
 20   
 import org.apache.tapestry.IRequestCycle;
 21   
 import org.apache.tapestry.Tapestry;
 22   
 
 23   
 /**
 24   
  * A component that renders an HTML <option> form element. Such a component must be wrapped
 25   
  * (possibly indirectly) inside a {@link Select}component. [ <a
 26   
  * href="../../../../../ComponentReference/Option.html">Component Reference </a>]
 27   
  * 
 28   
  * @author Howard Lewis Ship
 29   
  */
 30   
 
 31   
 public abstract class Option extends AbstractComponent
 32   
 {
 33   
     /**
 34   
      * Renders the &lt;option&gt; element, or responds when the form containing the element is
 35   
      * submitted (by checking {@link Form#isRewinding()}.
 36   
      * <p>
 37   
      * If the <code>label</code> property is set, it is inserted inside the &lt;option&gt;
 38   
      * element.
 39   
      */
 40   
 
 41  37
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 42   
     {
 43  37
         Select select = Select.get(cycle);
 44  37
         if (select == null)
 45  1
             throw new ApplicationRuntimeException(Tapestry
 46   
                     .getMessage("Option.must-be-contained-by-select"), this, null, null);
 47   
 
 48   
         // It isn't enough to know whether the cycle in general is rewinding, need to know
 49   
         // specifically if the form which contains this component is rewinding.
 50   
 
 51  36
         boolean rewinding = select.isRewinding();
 52   
 
 53  36
         String value = select.getNextOptionId();
 54   
 
 55  36
         if (rewinding)
 56   
         {
 57  14
             if (!select.isDisabled())
 58  11
                 setSelected(select.isSelected(value));
 59   
 
 60  14
             renderBody(writer, cycle);
 61   
         }
 62   
         else
 63   
         {
 64  22
             writer.begin("option");
 65   
 
 66  22
             writer.attribute("value", value);
 67   
 
 68  22
             if (isSelected())
 69  4
                 writer.attribute("selected", "selected");
 70   
 
 71  22
             renderInformalParameters(writer, cycle);
 72   
 
 73  22
             String label = getLabel();
 74   
 
 75  22
             if (label != null)
 76  16
                 writer.print(label);
 77   
 
 78  22
             renderBody(writer, cycle);
 79   
 
 80  22
             writer.end();
 81   
         }
 82   
 
 83   
     }
 84   
 
 85   
     public abstract String getLabel();
 86   
 
 87   
     public abstract boolean isSelected();
 88   
 
 89   
     public abstract void setSelected(boolean selected);
 90   
 }