Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 207   Methods: 9
NCLOC: 108   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.components.ForBean;
 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    * @deprecated As of release 4.0, replaced by {@link ForBean}
 39    */
 40   
 41    public abstract class ListEdit extends AbstractFormComponent
 42    {
 43    /**
 44    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 45    * org.apache.tapestry.IRequestCycle)
 46    */
 47  3 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 48    {
 49  3 this.render(writer, cycle, getSource());
 50    }
 51   
 52    /**
 53    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter,
 54    * org.apache.tapestry.IRequestCycle)
 55    */
 56  2 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 57    {
 58  2 String[] values = cycle.getParameters(getName());
 59   
 60  2 this.render(writer, cycle, (Iterator) getValueConverter().coerceValue(
 61    values,
 62    Iterator.class));
 63    }
 64   
 65  5 protected void render(IMarkupWriter writer, IRequestCycle cycle, Iterator i)
 66    {
 67    // If the source (when rendering), or the submitted values (on submit)
 68    // are null, then skip the remainder (nothing to update, nothing to
 69    // render).
 70   
 71  5 if (i == null)
 72  0 return;
 73   
 74  5 int index = 0;
 75   
 76  5 String element = getElement();
 77   
 78  5 boolean indexBound = isParameterBound("index");
 79   
 80  5 while (i.hasNext())
 81    {
 82  10 Object value = null;
 83   
 84  10 if (indexBound)
 85  3 setIndex(index++);
 86   
 87  10 if (cycle.isRewinding())
 88  4 value = convertValue((String) i.next());
 89    else
 90    {
 91  6 value = i.next();
 92  6 writeValue(getForm(), getName(), value);
 93    }
 94   
 95  9 setValue(value);
 96   
 97  9 getListenerInvoker().invokeListener(getListener(), this, cycle);
 98   
 99  9 if (element != null)
 100    {
 101  6 writer.begin(element);
 102  6 renderInformalParameters(writer, cycle);
 103    }
 104   
 105  9 renderBody(writer, cycle);
 106   
 107  9 if (element != null)
 108  6 writer.end();
 109    }
 110    }
 111   
 112  6 private void writeValue(IForm form, String name, Object value)
 113    {
 114  6 String externalValue;
 115   
 116  6 try
 117    {
 118  6 externalValue = getDataSqueezer().squeeze(value);
 119    }
 120    catch (Exception ex)
 121    {
 122  0 throw new ApplicationRuntimeException(Tapestry.format(
 123    "ListEdit.unable-to-convert-value",
 124    value), this, null, ex);
 125    }
 126   
 127  6 form.addHiddenValue(name, externalValue);
 128    }
 129   
 130  4 private Object convertValue(String value)
 131    {
 132  4 try
 133    {
 134  4 return getDataSqueezer().unsqueeze(value);
 135    }
 136    catch (Exception ex)
 137    {
 138  1 throw new ApplicationRuntimeException(Tapestry.format(
 139    "ListEdit.unable-to-convert-string",
 140    value), this, null, ex);
 141    }
 142    }
 143   
 144    public abstract String getElement();
 145   
 146    /** @since 2.2 * */
 147   
 148    public abstract IActionListener getListener();
 149   
 150    /** @since 3.0 * */
 151   
 152  0 public boolean isDisabled()
 153    {
 154  0 return false;
 155    }
 156   
 157    /** @since 4.0 */
 158   
 159    public abstract Iterator getSource();
 160   
 161    /** @since 4.0 */
 162   
 163    public abstract void setValue(Object value);
 164   
 165    /** @since 4.0 */
 166   
 167    public abstract void setIndex(int index);
 168   
 169    /** @since 4.0 */
 170   
 171    public abstract DataSqueezer getDataSqueezer();
 172   
 173    /** @since 4.0 */
 174   
 175    public abstract ValueConverter getValueConverter();
 176   
 177    /**
 178    * Injected.
 179    *
 180    * @since 4.0
 181    */
 182   
 183    public abstract ListenerInvoker getListenerInvoker();
 184   
 185    /**
 186    * Returns false; ListEdit components can't take focus.
 187    *
 188    * @since 4.0
 189    */
 190  3 protected boolean getCanTakeFocus()
 191    {
 192  3 return false;
 193    }
 194   
 195  0 public String getClientId()
 196    {
 197    // TODO Auto-generated method stub
 198  0 return null;
 199    }
 200   
 201  0 public String getDisplayName()
 202    {
 203    // TODO Auto-generated method stub
 204  0 return null;
 205    }
 206   
 207    }