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: 127   Methods: 3
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Hidden.java 100% 84.2% 66.7% 84.6%
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.hivemind.ApplicationRuntimeException;
 18    import org.apache.tapestry.IActionListener;
 19    import org.apache.tapestry.IForm;
 20    import org.apache.tapestry.IMarkupWriter;
 21    import org.apache.tapestry.IRequestCycle;
 22    import org.apache.tapestry.listener.ListenerInvoker;
 23    import org.apache.tapestry.services.DataSqueezer;
 24   
 25    /**
 26    * Implements a hidden field within a {@link Form}. [ <a
 27    * href="../../../../../ComponentReference/Hidden.html">Component Reference </a>]
 28    *
 29    * @author Howard Lewis Ship
 30    * @author Paul Ferraro
 31    */
 32    public abstract class Hidden extends AbstractFormComponent
 33    {
 34    /**
 35    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 36    * org.apache.tapestry.IRequestCycle)
 37    */
 38  4 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 39    {
 40  4 IForm form = getForm();
 41  4 String externalValue = null;
 42   
 43  4 if (getEncode())
 44    {
 45  2 Object value = getValue();
 46   
 47  2 try
 48    {
 49  2 externalValue = getDataSqueezer().squeeze(value);
 50    }
 51    catch (Exception e)
 52    {
 53  0 throw new ApplicationRuntimeException(e.getMessage(), this, null, e);
 54    }
 55    }
 56    else
 57  2 externalValue = (String) getBinding("value").getObject(String.class);
 58   
 59  4 String id = getClientId();
 60   
 61  4 form.addHiddenValue(getName(), id, externalValue);
 62    }
 63   
 64    /**
 65    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IRequestCycle)
 66    */
 67  4 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 68    {
 69  4 String parameter = cycle.getParameter(getName());
 70   
 71  4 Object value = parameter;
 72   
 73  4 if (getEncode())
 74    {
 75  2 try
 76    {
 77  2 value = getDataSqueezer().unsqueeze(parameter);
 78    }
 79    catch (Exception ex)
 80    {
 81  0 throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
 82    }
 83    }
 84   
 85    // A listener is not always necessary ... it's easy to code
 86    // the synchronization as a side-effect of the accessor method.
 87   
 88  4 setValue(value);
 89   
 90  4 getListenerInvoker().invokeListener(getListener(), this, cycle);
 91    }
 92   
 93    /** @since 2.2 * */
 94    public abstract DataSqueezer getDataSqueezer();
 95   
 96    public abstract Object getValue();
 97   
 98    public abstract void setValue(Object value);
 99   
 100    public abstract IActionListener getListener();
 101   
 102    /**
 103    * Injected.
 104    *
 105    * @since 4.0
 106    */
 107   
 108    public abstract ListenerInvoker getListenerInvoker();
 109   
 110    /**
 111    * Returns false. Hidden components are never disabled.
 112    *
 113    * @since 2.2
 114    */
 115  0 public boolean isDisabled()
 116    {
 117  0 return false;
 118    }
 119   
 120    /**
 121    * Returns true if the compent encodes object values using a
 122    * {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
 123    *
 124    * @since 2.2
 125    */
 126    public abstract boolean getEncode();
 127    }