Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 136   Methods: 4
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Hidden.java 100% 85% 75% 85.7%
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    * Returns false.
 36    */
 37   
 38  4 protected boolean getCanTakeFocus()
 39    {
 40  4 return false;
 41    }
 42   
 43    /**
 44    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 45    * org.apache.tapestry.IRequestCycle)
 46    */
 47  4 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 48    {
 49  4 IForm form = getForm();
 50  4 String externalValue = null;
 51   
 52  4 if (getEncode())
 53    {
 54  2 Object value = getValue();
 55   
 56  2 try
 57    {
 58  2 externalValue = getDataSqueezer().squeeze(value);
 59    }
 60    catch (Exception e)
 61    {
 62  0 throw new ApplicationRuntimeException(e.getMessage(), this, null, e);
 63    }
 64    }
 65    else
 66  2 externalValue = (String) getBinding("value").getObject(String.class);
 67   
 68  4 String id = getClientId();
 69   
 70  4 form.addHiddenValue(getName(), id, externalValue);
 71    }
 72   
 73    /**
 74    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IRequestCycle)
 75    */
 76  4 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 77    {
 78  4 String parameter = cycle.getParameter(getName());
 79   
 80  4 Object value = parameter;
 81   
 82  4 if (getEncode())
 83    {
 84  2 try
 85    {
 86  2 value = getDataSqueezer().unsqueeze(parameter);
 87    }
 88    catch (Exception ex)
 89    {
 90  0 throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
 91    }
 92    }
 93   
 94    // A listener is not always necessary ... it's easy to code
 95    // the synchronization as a side-effect of the accessor method.
 96   
 97  4 setValue(value);
 98   
 99  4 getListenerInvoker().invokeListener(getListener(), this, cycle);
 100    }
 101   
 102    /** @since 2.2 * */
 103    public abstract DataSqueezer getDataSqueezer();
 104   
 105    public abstract Object getValue();
 106   
 107    public abstract void setValue(Object value);
 108   
 109    public abstract IActionListener getListener();
 110   
 111    /**
 112    * Injected.
 113    *
 114    * @since 4.0
 115    */
 116   
 117    public abstract ListenerInvoker getListenerInvoker();
 118   
 119    /**
 120    * Returns false. Hidden components are never disabled.
 121    *
 122    * @since 2.2
 123    */
 124  0 public boolean isDisabled()
 125    {
 126  0 return false;
 127    }
 128   
 129    /**
 130    * Returns true if the compent encodes object values using a
 131    * {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
 132    *
 133    * @since 2.2
 134    */
 135    public abstract boolean getEncode();
 136    }