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: 116   Methods: 3
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractSubmit.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.Collection;
 18   
 19    import org.apache.tapestry.IActionListener;
 20    import org.apache.tapestry.IForm;
 21    import org.apache.tapestry.IMarkupWriter;
 22    import org.apache.tapestry.IRequestCycle;
 23    import org.apache.tapestry.listener.ListenerInvoker;
 24   
 25    /**
 26    * Superclass for components submitting their form.
 27    *
 28    * @author Richard Lewis-Shell
 29    * @since 4.0
 30    */
 31   
 32    abstract class AbstractSubmit extends AbstractFormComponent
 33    {
 34    /**
 35    * Determine if this submit component was clicked.
 36    *
 37    * @param cycle
 38    * @param name
 39    * @return true if this submit was clicked
 40    */
 41    protected abstract boolean isClicked(IRequestCycle cycle, String name);
 42   
 43    /**
 44    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 45    */
 46  6 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 47    {
 48  6 if (isClicked(cycle, getName()))
 49  3 handleClick(cycle, getForm());
 50    }
 51   
 52  8 void handleClick(final IRequestCycle cycle, IForm form)
 53    {
 54  8 if (isParameterBound("selected"))
 55  3 setSelected(getTag());
 56   
 57  8 final IActionListener listener = getListener();
 58  8 final IActionListener action = getAction();
 59   
 60  8 if (listener == null && action == null)
 61  3 return;
 62   
 63  5 final ListenerInvoker listenerInvoker = getListenerInvoker();
 64   
 65  5 Object parameters = getParameters();
 66  5 if (parameters != null)
 67    {
 68  2 if (parameters instanceof Collection)
 69    {
 70  1 cycle.setListenerParameters(((Collection) parameters).toArray());
 71    }
 72    else
 73    {
 74  1 cycle.setListenerParameters(new Object[]
 75    { parameters });
 76    }
 77    }
 78   
 79    // Invoke 'listener' now, but defer 'action' for later
 80  5 if (listener != null)
 81  2 listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
 82   
 83  5 if (action != null) {
 84  4 Runnable notify = new Runnable()
 85    {
 86  4 public void run()
 87    {
 88  4 listenerInvoker.invokeListener(action, AbstractSubmit.this, cycle);
 89    }
 90    };
 91   
 92  4 form.addDeferredRunnable(notify);
 93    }
 94    }
 95   
 96    /** parameter */
 97    public abstract IActionListener getListener();
 98   
 99    /** parameter */
 100    public abstract IActionListener getAction();
 101   
 102    /** parameter */
 103    public abstract Object getTag();
 104   
 105    /** parameter */
 106    public abstract void setSelected(Object tag);
 107   
 108    /** parameter */
 109    public abstract boolean getDefer();
 110   
 111    /** parameter */
 112    public abstract Object getParameters();
 113   
 114    /** Injected */
 115    public abstract ListenerInvoker getListenerInvoker();
 116    }