Coverage Report - org.apache.tapestry.internal.event.EventBoundListener
 
Classes in this File Line Coverage Branch Coverage Complexity
EventBoundListener
93% 
83% 
2
 
 1  
 // Copyright Jun 2, 2006 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  
 package org.apache.tapestry.internal.event;
 15  
 
 16  
 
 17  
 /**
 18  
  * Provides a mapping for listener methods that are bound to events, used
 19  
  * internally by {@link ComponentEventProperty}.
 20  
  */
 21  
 public class EventBoundListener implements Cloneable
 22  
 {
 23  
     // the method name to invoke
 24  
     private String _methodName;
 25  
     // if not null the form to submit before invoking listener
 26  
     private String _formId;
 27  
     // if _formId set whether or not to validate form when submitted
 28  
     private boolean _validateForm;
 29  
     // The targeted component to listen to events on
 30  
     private String _componentId;
 31  
     
 32  
     // If targeting a form, whether or not to submit it asynchronously
 33  
     private boolean _async;
 34  
     // Whether or not to focus the form
 35  
     private boolean _focus;
 36  
     // If this is an autoSubmit form bound event, ie we need to discover the formId dynamically
 37  
     private boolean _autoSubmit;
 38  
     
 39  
     /**
 40  
      * Creates a new listener binding. 
 41  
      * @param methodName
 42  
      *          The method to invoke.
 43  
      */
 44  
     public EventBoundListener(String methodName, String componentId)
 45  
     {
 46  18
         this(methodName, componentId, true);
 47  18
     }
 48  
 
 49  
     /**
 50  
      * Creates a new listener binding.
 51  
      * @param methodName
 52  
      *          The method to invoke.
 53  
      */
 54  
     public EventBoundListener(String methodName, String componentId, boolean autoSubmit)
 55  
     {
 56  18
         this(methodName, null, false, componentId, true, false, autoSubmit);
 57  18
     }
 58  
 
 59  
     /**
 60  
      * Creates a new listener binding. 
 61  
      * @param methodName
 62  
      *          The method to invoke.
 63  
      * @param formId
 64  
      *          If not null the form to submit before invoking listener
 65  
      * @param validateForm
 66  
      *          If formId is set, whether or not to validate form when submitting.
 67  
      */
 68  
     public EventBoundListener(String methodName, String formId, 
 69  
             boolean validateForm, String componentId, boolean async, boolean focus, boolean autoSubmit)
 70  37
     {
 71  37
         _methodName = methodName;
 72  37
         _formId = formId;
 73  37
         _validateForm = validateForm;
 74  37
         _componentId = componentId;
 75  37
         _async = async;
 76  37
         _focus = focus;
 77  37
         _autoSubmit = autoSubmit;
 78  37
     }
 79  
 
 80  
     /**
 81  
      * Creates a new listener binding.
 82  
      * @param methodName
 83  
      *          The method to invoke.
 84  
      * @param formId
 85  
      *          If not null the form to submit before invoking listener
 86  
      * @param validateForm
 87  
      *          If formId is set, whether or not to validate form when submitting.
 88  
      */
 89  
     public EventBoundListener(String methodName, String formId,
 90  
             boolean validateForm, String componentId, boolean async, boolean focus)
 91  
     {
 92  19
         this(methodName, formId, validateForm, componentId, async, focus, true);
 93  19
     }
 94  
     
 95  
     /**
 96  
      * @return the formId
 97  
      */
 98  
     public String getFormId()
 99  
     {
 100  19
         return _formId;
 101  
     }
 102  
 
 103  
     public void setFormId(String id)
 104  
     {
 105  4
         _formId = id;
 106  4
     }
 107  
 
 108  
     /**
 109  
      * @return the methodName
 110  
      */
 111  
     public String getMethodName()
 112  
     {
 113  10
         return _methodName;
 114  
     }
 115  
     
 116  
     /**
 117  
      * @return the componentId
 118  
      */
 119  
     public String getComponentId()
 120  
     {
 121  14
         return _componentId;
 122  
     }
 123  
 
 124  
     public void setComponentId(String id)
 125  
     {
 126  6
         _componentId = id;
 127  6
     }
 128  
 
 129  
     /**
 130  
      * @return the validateForm
 131  
      */
 132  
     public boolean isValidateForm()
 133  
     {
 134  9
         return _validateForm;
 135  
     }
 136  
     
 137  
     /**
 138  
      * Whether or not listener should submit form
 139  
      * asynchronously.
 140  
      * 
 141  
      * @return True if listener is asynchronous.
 142  
      */
 143  
     public boolean isAsync()
 144  
     {
 145  6
         return _async;
 146  
     }
 147  
     
 148  
     public boolean shouldFocusForm()
 149  
     {
 150  3
         return _focus;
 151  
     }
 152  
 
 153  
     public boolean isAutoSubmit()
 154  
     {
 155  3
         return _autoSubmit;
 156  
     }
 157  
 
 158  
     public Object clone()
 159  
     throws CloneNotSupportedException
 160  
     {
 161  2
         return super.clone();
 162  
     }
 163  
 
 164  
     /**
 165  
      * {@inheritDoc}
 166  
      */
 167  
     public int hashCode()
 168  
     {
 169  9
         final int prime = 31;
 170  9
         int result = 1;
 171  9
         result = prime * result + ((_componentId == null) ? 0 : _componentId.hashCode());
 172  9
         result = prime * result + ((_methodName == null) ? 0 : _methodName.hashCode());
 173  9
         result = prime * result + ((_formId == null) ? 0 : _formId.hashCode());
 174  9
         return result;
 175  
     }
 176  
     
 177  
     /** 
 178  
      * {@inheritDoc}
 179  
      */
 180  
     public boolean equals(Object obj)
 181  
     {
 182  5
         if (this == obj) return true;
 183  5
         if (obj == null) return false;
 184  5
         if (getClass() != obj.getClass()) return false;
 185  5
         final EventBoundListener other = (EventBoundListener) obj;
 186  5
         if (_componentId == null) {
 187  0
             if (other._componentId != null) return false;
 188  5
         } else if (!_componentId.equals(other._componentId)) return false;
 189  5
         if (_methodName == null) {
 190  0
             if (other._methodName != null) return false;
 191  5
         } else if (!_methodName.equals(other._methodName)) return false;
 192  0
         return true;
 193  
     }
 194  
 }