Clover coverage report - Code Coverage for tapestry release 4.0-beta-4
Coverage timestamp: Wed Aug 10 2005 21:19:31 EDT
file stats: LOC: 153   Methods: 7
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractFormComponent.java 100% 96.3% 85.7% 95.8%
coverage 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.tapestry.AbstractComponent;
 18    import org.apache.tapestry.IForm;
 19    import org.apache.tapestry.IMarkupWriter;
 20    import org.apache.tapestry.IRequestCycle;
 21    import org.apache.tapestry.TapestryUtils;
 22    import org.apache.tapestry.valid.IValidationDelegate;
 23    import org.apache.tapestry.valid.ValidationConstants;
 24   
 25    /**
 26    * A base class for building components that correspond to HTML form elements. All such components
 27    * must be wrapped (directly or indirectly) by a {@link Form} component.
 28    *
 29    * @author Howard Lewis Ship
 30    * @author Paul Ferraro
 31    * @since 1.0.3
 32    */
 33    public abstract class AbstractFormComponent extends AbstractComponent implements IFormComponent
 34    {
 35    public abstract IForm getForm();
 36   
 37    public abstract void setForm(IForm form);
 38   
 39    public abstract String getName();
 40   
 41    public abstract void setName(String name);
 42   
 43    /**
 44    * Should be connected to a parameter named "id" (annotations would be helpful here!). For
 45    * components w/o such a parameter, this will simply return null.
 46    */
 47   
 48    public abstract String getIdParameter();
 49   
 50    /**
 51    * Stores the actual id allocated (or null if the component doesn't support this).
 52    */
 53   
 54    public abstract void setClientId(String id);
 55   
 56    /**
 57    * Invoked from {@link #renderFormComponent(IMarkupWriter, IRequestCycle)} (that is, an
 58    * implementation in a subclass), to obtain an id and render an id attribute. Reads
 59    * {@link #getIdParameter()}.
 60    */
 61   
 62  40 protected void renderIdAttribute(IMarkupWriter writer, IRequestCycle cycle)
 63    {
 64    // If the user explicitly sets the id parameter to null, then
 65    // we honor that!
 66   
 67  40 String rawId = getIdParameter();
 68   
 69  40 if (rawId == null)
 70  25 return;
 71   
 72  15 String id = cycle.getUniqueId(rawId);
 73   
 74    // Store for later access by the FieldLabel (or JavaScript).
 75   
 76  15 setClientId(id);
 77   
 78  15 writer.attribute("id", id);
 79    }
 80   
 81    /**
 82    * @see org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
 83    * org.apache.tapestry.IRequestCycle)
 84    */
 85  121 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 86    {
 87  121 IForm form = TapestryUtils.getForm(cycle, this);
 88   
 89  120 setForm(form);
 90   
 91  120 if (form.wasPrerendered(writer, this))
 92  5 return;
 93   
 94  115 IValidationDelegate delegate = form.getDelegate();
 95   
 96  115 delegate.setFormComponent(this);
 97   
 98  115 setName(form);
 99   
 100  114 if (form.isRewinding())
 101    {
 102  48 if (!isDisabled())
 103    {
 104  41 rewindFormComponent(writer, cycle);
 105    }
 106    }
 107  66 else if (!cycle.isRewinding())
 108    {
 109  59 if (!isDisabled())
 110  50 delegate.registerForFocus(this, ValidationConstants.NORMAL_FIELD);
 111   
 112  59 renderFormComponent(writer, cycle);
 113   
 114  57 if (delegate.isInError())
 115  1 delegate.registerForFocus(this, ValidationConstants.ERROR_FIELD);
 116    }
 117    }
 118   
 119  22 protected void renderDelegatePrefix(IMarkupWriter writer, IRequestCycle cycle)
 120    {
 121  22 getForm().getDelegate().writePrefix(writer, cycle, this, null);
 122    }
 123   
 124  22 protected void renderDelegateAttributes(IMarkupWriter writer, IRequestCycle cycle)
 125    {
 126  22 getForm().getDelegate().writeAttributes(writer, cycle, this, null);
 127    }
 128   
 129  21 protected void renderDelegateSuffix(IMarkupWriter writer, IRequestCycle cycle)
 130    {
 131  21 getForm().getDelegate().writeSuffix(writer, cycle, this, null);
 132    }
 133   
 134  107 protected void setName(IForm form)
 135    {
 136  107 form.getElementId(this);
 137    }
 138   
 139    /**
 140    * Returns false. Subclasses that might be required must override this method. Typically, this
 141    * involves checking against the component's validators.
 142    *
 143    * @since 4.0
 144    */
 145  0 public boolean isRequired()
 146    {
 147  0 return false;
 148    }
 149   
 150    protected abstract void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle);
 151   
 152    protected abstract void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle);
 153    }