Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 179   Methods: 6
NCLOC: 94   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ListEdit.java 91.7% 87.9% 83.3% 88.2%
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 java.io.IOException;
 18    import java.util.Iterator;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.tapestry.IActionListener;
 22    import org.apache.tapestry.IForm;
 23    import org.apache.tapestry.IMarkupWriter;
 24    import org.apache.tapestry.IRequestCycle;
 25    import org.apache.tapestry.Tapestry;
 26    import org.apache.tapestry.coerce.ValueConverter;
 27    import org.apache.tapestry.listener.ListenerInvoker;
 28    import org.apache.tapestry.services.DataSqueezer;
 29   
 30    /**
 31    * A specialized component used to edit a list of items within a form; it is similar to a
 32    * {@link org.apache.tapestry.components.Foreach}but leverages hidden inputs within the
 33    * &lt;form&gt; to store the items in the list. [ <a
 34    * href="../../../../../ComponentReference/ListEdit.html">Component Reference </a>]
 35    *
 36    * @author Howard Lewis Ship
 37    * @since 1.0.2
 38    */
 39   
 40    public abstract class ListEdit extends AbstractFormComponent
 41    {
 42    /**
 43    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 44    */
 45  3 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 46    {
 47  3 this.render(writer, cycle, getSource());
 48    }
 49   
 50    /**
 51    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 52    */
 53  2 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 54    {
 55  2 String[] values = cycle.getParameters(getName());
 56   
 57  2 this.render(writer, cycle, (Iterator) getValueConverter().coerceValue(values, Iterator.class));
 58    }
 59   
 60  5 protected void render(IMarkupWriter writer, IRequestCycle cycle, Iterator i)
 61    {
 62    // If the source (when rendering), or the submitted values (on submit)
 63    // are null, then skip the remainder (nothing to update, nothing to
 64    // render).
 65   
 66  5 if (i == null)
 67  0 return;
 68   
 69  5 int index = 0;
 70   
 71  5 String element = getElement();
 72   
 73  5 boolean indexBound = isParameterBound("index");
 74   
 75  5 while (i.hasNext())
 76    {
 77  10 Object value = null;
 78   
 79  10 if (indexBound)
 80  3 setIndex(index++);
 81   
 82  10 if (cycle.isRewinding())
 83  4 value = convertValue((String) i.next());
 84    else
 85    {
 86  6 value = i.next();
 87  6 writeValue(getForm(), getName(), value);
 88    }
 89   
 90  9 setValue(value);
 91   
 92  9 getListenerInvoker().invokeListener(getListener(), this, cycle);
 93   
 94  9 if (element != null)
 95    {
 96  6 writer.begin(element);
 97  6 renderInformalParameters(writer, cycle);
 98    }
 99   
 100  9 renderBody(writer, cycle);
 101   
 102  9 if (element != null)
 103  6 writer.end();
 104    }
 105    }
 106   
 107  6 private void writeValue(IForm form, String name, Object value)
 108    {
 109  6 String externalValue;
 110   
 111  6 try
 112    {
 113  6 externalValue = getDataSqueezer().squeeze(value);
 114    }
 115    catch (IOException ex)
 116    {
 117  0 throw new ApplicationRuntimeException(Tapestry.format(
 118    "ListEdit.unable-to-convert-value",
 119    value), this, null, ex);
 120    }
 121   
 122  6 form.addHiddenValue(name, externalValue);
 123    }
 124   
 125  4 private Object convertValue(String value)
 126    {
 127  4 try
 128    {
 129  4 return getDataSqueezer().unsqueeze(value);
 130    }
 131    catch (IOException ex)
 132    {
 133  0 throw new ApplicationRuntimeException(Tapestry.format(
 134    "ListEdit.unable-to-convert-string",
 135    value), this, null, ex);
 136    }
 137    }
 138   
 139    public abstract String getElement();
 140   
 141    /** @since 2.2 * */
 142   
 143    public abstract IActionListener getListener();
 144   
 145    /** @since 3.0 * */
 146   
 147  0 public boolean isDisabled()
 148    {
 149  0 return false;
 150    }
 151   
 152    /** @since 4.0 */
 153   
 154    public abstract Iterator getSource();
 155   
 156    /** @since 4.0 */
 157   
 158    public abstract void setValue(Object value);
 159   
 160    /** @since 4.0 */
 161   
 162    public abstract void setIndex(int index);
 163   
 164    /** @since 4.0 */
 165   
 166    public abstract DataSqueezer getDataSqueezer();
 167   
 168    /** @since 4.0 */
 169   
 170    public abstract ValueConverter getValueConverter();
 171   
 172    /**
 173    * Injected.
 174    *
 175    * @since 4.0
 176    */
 177   
 178    public abstract ListenerInvoker getListenerInvoker();
 179    }