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