1 package net.sourceforge.formview; 2 3 import java.io.Serializable ; 4 5 import org.apache.commons.collections.FastHashMap; 6 import org.apache.commons.lang.StringUtils; 7 8 14 public class FieldView implements Cloneable , Serializable { 15 16 private static final long serialVersionUID = 1L; 17 18 protected String property = null; 19 protected String maxlength = null; 20 private String behaviour = null; 21 private String required = null; 22 private String date = null; 23 24 private String dependsOn = null; 25 26 private Integer index = null; 27 28 private String roles = null; 29 private String [] rolesArray = null; 30 private String roleDefinitionName = null; 31 32 35 protected FastHashMap hFieldsIndexed = null; 36 37 42 protected Class updatedByClass = null; 43 44 47 protected String updatedByMethodName = null; 48 49 51 public FieldView() { 52 53 } 54 55 public FieldView(String property) { 56 this.property = property; 57 } 58 59 62 public String getProperty() { 63 return this.property; 64 } 65 66 69 public void setProperty(String property) { 70 this.property = property; 71 } 72 73 public String getMaxlength() { 74 return maxlength; 75 } 76 77 public void setMaxlength(String maxlength) { 78 this.maxlength = maxlength; 79 } 80 81 public String getBehaviour() { 82 return behaviour; 83 } 84 85 public void setBehaviour(String behaviour) { 86 this.behaviour = behaviour; 87 } 88 89 public String getRequired() { 90 return required; 91 } 92 93 public void setRequired(String required) { 94 this.required = required; 95 } 96 97 public boolean isFiedlRequired() { 98 return (required != null && required.equalsIgnoreCase("true")); 99 } 100 101 public String getDate() { 102 return date; 103 } 104 105 public void setDate(String date) { 106 this.date = date; 107 } 108 109 public boolean isFieldDate() { 110 return (date != null && date.equalsIgnoreCase("true")); 111 } 112 113 public Class getUpdatedByClass() { 114 return updatedByClass; 115 } 116 117 public void setUpdatedByClass(Class updatedByClass) { 118 this.updatedByClass = updatedByClass; 119 } 120 121 public String getUpdatedByMethodName() { 122 return updatedByMethodName; 123 } 124 125 public void setUpdatedByMethodName(String updatedByMethodName) { 126 this.updatedByMethodName = updatedByMethodName; 127 } 128 129 public Integer getIndex() { 130 return index; 131 } 132 133 public void setIndex(Integer index) { 134 this.index = index; 135 } 136 137 140 public String getRoles() { 141 return roles; 142 } 143 146 public void setRoles(String roles) { 147 this.roles = roles; 148 this.rolesArray = null; 149 } 150 151 152 153 public String [] getRolesArray() { 154 if (rolesArray == null && 156 roles != null && 157 roles.length() > 0) { 158 this.rolesArray = StringUtils.split(roles, ","); 159 } 160 return rolesArray; 161 } 162 163 164 167 public String getRoleDefinitionName() { 168 return roleDefinitionName; 169 } 170 173 public void setRoleDefinitionName(String roleDefinitionName) { 174 this.roleDefinitionName = roleDefinitionName; 175 } 176 public void mergeFieldView(FieldView fieldView) { 177 Integer index = fieldView.getIndex(); 178 if (index != null) { 179 if (fieldView.getBehaviour() == null) 182 fieldView.setBehaviour(this.behaviour); 183 if (fieldView.getDate() == null) 184 fieldView.setDate(this.date); 185 if (fieldView.getMaxlength() == null) 186 fieldView.setMaxlength(this.maxlength); 187 if (fieldView.getRequired() == null) 188 fieldView.setRequired(this.required); 189 if (fieldView.getRoles() == null) 190 fieldView.setRoles(this.roles); 191 192 if (hFieldsIndexed == null) { 193 hFieldsIndexed = new FastHashMap(); 194 } 195 hFieldsIndexed.put(index, fieldView); 196 } 197 else { 198 merge(this, fieldView); 201 } 202 } 203 204 public boolean isIndexed() { 205 return (hFieldsIndexed != null && hFieldsIndexed.size() > 0); 206 } 207 208 public FieldView getFieldWithIndex(Integer index) { 209 if (hFieldsIndexed != null) { 210 return (FieldView)hFieldsIndexed.get(index); 211 } 212 return null; 213 } 214 215 private void merge(FieldView fieldView1, FieldView fieldView2) { 216 if (fieldView2.getBehaviour() != null) 217 fieldView1.setBehaviour(fieldView2.getBehaviour()); 218 if (fieldView2.getDate() != null) 219 fieldView1.setDate(fieldView2.getDate()); 220 if (fieldView2.getMaxlength() != null) 221 fieldView1.setMaxlength(fieldView2.getMaxlength()); 222 if (fieldView2.getRequired() != null) 223 fieldView1.setRequired(fieldView2.getRequired()); 224 if (fieldView2.getRoles() != null) 225 fieldView1.setRoles(fieldView2.getRoles()); 226 } 227 228 231 public String toString() { 232 StringBuffer results = new StringBuffer (); 233 results.append("\t\tproperty = " + property + "\n"); 234 results.append("\n"); 235 if (updatedByClass != null) 236 results.append("\t\tupdatedByClass = " + updatedByClass.getName() + "\n"); 237 results.append("\t\tupdatedByMethodName = " + updatedByMethodName + "\n"); 238 results.append("\t\tmaxlength = " + maxlength + "\n"); 239 results.append("\t\trequired = " + required + "\n"); 240 results.append("\t\tdate = " + date + "\n"); 241 results.append("\t\tbehaviour = " + behaviour + "\n"); 242 results.append("\t\troles = " + roles + "\n"); 243 results.append("\t\troleDefinitionName = " + roleDefinitionName + "\n"); 244 return results.toString(); 245 } 246 247 public String toHtml() { 248 StringBuffer results = new StringBuffer ("<tr>"); 249 results.append("<td>property : " + property + "</td>"); 250 results.append("<td>updated by : " + getUpdatedByInformation() + "</td>"); 251 results.append("<td>maxlength : " + maxlength + "</td>"); 252 results.append("<td>required : " + required + "</td>"); 253 results.append("<td>date : " + date + "</td>"); 254 results.append("<td>behaviour : " + behaviour + "</td>"); 255 results.append("<td>roles : " + roles + "</td>"); 256 results.append("<td>roleDefinitionName : " + roleDefinitionName + "</td>"); 257 results.append("</tr>"); 258 return results.toString(); 259 } 260 261 private String getUpdatedByInformation() { 262 if (updatedByClass == null) 263 return ""; 264 StringBuffer s = new StringBuffer (updatedByClass.getName()); 265 if (updatedByMethodName != null && updatedByMethodName.length() > 0) { 266 s.append(" [method : " + updatedByMethodName + "]"); 267 } 268 return s.toString(); 269 } 270 271 276 public boolean isDependsOn(String dependName) { 277 return (getDependsOn().indexOf(dependName) != -1); 278 } 279 280 private String getDependsOn() { 281 if (dependsOn != null) 282 return dependsOn; 283 dependsOn = ""; 284 if ("true".equals(date)) 285 dependsOn += "date,"; 286 if (maxlength != null && maxlength.length() > 0) 287 dependsOn += "maxlength,"; 288 if ("true".equals(required)) 289 dependsOn += "required,"; 290 return dependsOn; 291 } 292 293 public Object clone() { 294 FieldView fieldCloned = new FieldView(this.property); 295 fieldCloned.setBehaviour(this.behaviour); 296 fieldCloned.setDate(this.date); 297 fieldCloned.setIndex(this.index); 298 fieldCloned.setMaxlength(this.maxlength); 299 fieldCloned.setRequired(this.required); 300 fieldCloned.setUpdatedByClass(this.updatedByClass); 301 fieldCloned.setUpdatedByMethodName(this.updatedByMethodName); 302 fieldCloned.setRoles(this.roles); 303 fieldCloned.setRoleDefinitionName(this.roleDefinitionName); 304 return fieldCloned; 305 } 306 307 308 } 309 | Popular Tags |