001 // Copyright Jun 2, 2006 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 package org.apache.tapestry.internal.event; 015 016 017 /** 018 * Provides a mapping for listener methods that are bound to events, used 019 * internally by {@link ComponentEventProperty}. 020 */ 021 public class EventBoundListener implements Cloneable 022 { 023 // the method name to invoke 024 private String _methodName; 025 // if not null the form to submit before invoking listener 026 private String _formId; 027 // if _formId set whether or not to validate form when submitted 028 private boolean _validateForm; 029 // The targeted component to listen to events on 030 private String _componentId; 031 032 // If targeting a form, whether or not to submit it asynchronously 033 private boolean _async; 034 // Whether or not to focus the form 035 private boolean _focus; 036 // If this is an autoSubmit form bound event, ie we need to discover the formId dynamically 037 private boolean _autoSubmit; 038 039 /** 040 * Creates a new listener binding. 041 * @param methodName 042 * The method to invoke. 043 */ 044 public EventBoundListener(String methodName, String componentId) 045 { 046 this(methodName, componentId, true); 047 } 048 049 /** 050 * Creates a new listener binding. 051 * @param methodName 052 * The method to invoke. 053 */ 054 public EventBoundListener(String methodName, String componentId, boolean autoSubmit) 055 { 056 this(methodName, null, false, componentId, true, false, autoSubmit); 057 } 058 059 /** 060 * Creates a new listener binding. 061 * @param methodName 062 * The method to invoke. 063 * @param formId 064 * If not null the form to submit before invoking listener 065 * @param validateForm 066 * If formId is set, whether or not to validate form when submitting. 067 */ 068 public EventBoundListener(String methodName, String formId, 069 boolean validateForm, String componentId, boolean async, boolean focus, boolean autoSubmit) 070 { 071 _methodName = methodName; 072 _formId = formId; 073 _validateForm = validateForm; 074 _componentId = componentId; 075 _async = async; 076 _focus = focus; 077 _autoSubmit = autoSubmit; 078 } 079 080 /** 081 * Creates a new listener binding. 082 * @param methodName 083 * The method to invoke. 084 * @param formId 085 * If not null the form to submit before invoking listener 086 * @param validateForm 087 * If formId is set, whether or not to validate form when submitting. 088 */ 089 public EventBoundListener(String methodName, String formId, 090 boolean validateForm, String componentId, boolean async, boolean focus) 091 { 092 this(methodName, formId, validateForm, componentId, async, focus, true); 093 } 094 095 /** 096 * @return the formId 097 */ 098 public String getFormId() 099 { 100 return _formId; 101 } 102 103 public void setFormId(String id) 104 { 105 _formId = id; 106 } 107 108 /** 109 * @return the methodName 110 */ 111 public String getMethodName() 112 { 113 return _methodName; 114 } 115 116 /** 117 * @return the componentId 118 */ 119 public String getComponentId() 120 { 121 return _componentId; 122 } 123 124 public void setComponentId(String id) 125 { 126 _componentId = id; 127 } 128 129 /** 130 * @return the validateForm 131 */ 132 public boolean isValidateForm() 133 { 134 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 return _async; 146 } 147 148 public boolean shouldFocusForm() 149 { 150 return _focus; 151 } 152 153 public boolean isAutoSubmit() 154 { 155 return _autoSubmit; 156 } 157 158 public Object clone() 159 throws CloneNotSupportedException 160 { 161 return super.clone(); 162 } 163 164 /** 165 * {@inheritDoc} 166 */ 167 public int hashCode() 168 { 169 final int prime = 31; 170 int result = 1; 171 result = prime * result + ((_componentId == null) ? 0 : _componentId.hashCode()); 172 result = prime * result + ((_methodName == null) ? 0 : _methodName.hashCode()); 173 result = prime * result + ((_formId == null) ? 0 : _formId.hashCode()); 174 return result; 175 } 176 177 /** 178 * {@inheritDoc} 179 */ 180 public boolean equals(Object obj) 181 { 182 if (this == obj) return true; 183 if (obj == null) return false; 184 if (getClass() != obj.getClass()) return false; 185 final EventBoundListener other = (EventBoundListener) obj; 186 if (_componentId == null) { 187 if (other._componentId != null) return false; 188 } else if (!_componentId.equals(other._componentId)) return false; 189 if (_methodName == null) { 190 if (other._methodName != null) return false; 191 } else if (!_methodName.equals(other._methodName)) return false; 192 return true; 193 } 194 }