| 1 | |
package org.kuali.rice.core.api.uif.control; |
| 2 | |
|
| 3 | |
import org.apache.commons.lang.StringUtils; |
| 4 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 5 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 6 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 7 | |
import org.kuali.rice.core.api.CoreConstants; |
| 8 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 9 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 10 | |
import org.kuali.rice.core.api.uif.control.widget.AbstractWidget; |
| 11 | |
import org.w3c.dom.Element; |
| 12 | |
|
| 13 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 14 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 15 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 16 | |
import javax.xml.bind.annotation.XmlElement; |
| 17 | |
import javax.xml.bind.annotation.XmlType; |
| 18 | |
import java.util.Collection; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 24 | |
@XmlType(name = AbstractControl.Constants.TYPE_NAME) |
| 25 | |
public abstract class AbstractControl implements AbstractControlContract, ModelObjectComplete { |
| 26 | |
|
| 27 | |
@XmlElement(name = Elements.NAME, required = true) |
| 28 | |
private final String name; |
| 29 | |
|
| 30 | |
@XmlElement(name = Elements.SHORT_LABEL, required = false) |
| 31 | |
private final String shortLabel; |
| 32 | |
|
| 33 | |
@XmlElement(name = Elements.LONG_LABEL, required = false) |
| 34 | |
private final String longLabel; |
| 35 | |
|
| 36 | |
@XmlElement(name = Elements.HELP_SUMMARY, required = false) |
| 37 | |
private final String helpSummary; |
| 38 | |
|
| 39 | |
@XmlElement(name = Elements.HELP_CONSTRAInteger, required = false) |
| 40 | |
private final String helpConstraInteger; |
| 41 | |
|
| 42 | |
@XmlElement(name = Elements.HELP_DESCRIPTION, required = false) |
| 43 | |
private final String helpDescription; |
| 44 | |
|
| 45 | |
@XmlElement(name = Elements.FORCE_UPPERCASE, required = false) |
| 46 | |
private final boolean forceUpperCase; |
| 47 | |
|
| 48 | |
@XmlElement(name = Elements.MIN_LENGTH, required = false) |
| 49 | |
private final Integer minLength; |
| 50 | |
|
| 51 | |
@XmlElement(name = Elements.MAX_LENGTH, required = false) |
| 52 | |
private final Integer maxLength; |
| 53 | |
|
| 54 | |
@XmlElement(name = Elements.MIN_VALUE, required = false) |
| 55 | |
private final Integer minValue; |
| 56 | |
|
| 57 | |
@XmlElement(name = Elements.MAX_VALUE, required = false) |
| 58 | |
private final Integer maxValue; |
| 59 | |
|
| 60 | |
@XmlElement(name = Elements.REGEX_CONSTRAInteger, required = false) |
| 61 | |
private final String regexConstraint; |
| 62 | |
|
| 63 | |
@XmlElement(name = Elements.REGEX_CONSTRAInteger_MSG, required = false) |
| 64 | |
private final String regexContraintMsg; |
| 65 | |
|
| 66 | |
@XmlElement(name = Elements.REQUIRED, required = false) |
| 67 | |
private final boolean required; |
| 68 | |
|
| 69 | |
@XmlElement(name = Elements.WIDGETS, required = false) |
| 70 | |
private final Collection<? extends AbstractWidget> widgets; |
| 71 | |
|
| 72 | 0 | @SuppressWarnings("unused") |
| 73 | |
@XmlAnyElement |
| 74 | |
private final Collection<Element> _futureElements = null; |
| 75 | |
|
| 76 | |
@Override |
| 77 | |
public final String getName() { |
| 78 | 0 | return name; |
| 79 | |
} |
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public final String getShortLabel() { |
| 83 | 0 | return shortLabel; |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
public final String getLongLabel() { |
| 88 | 0 | return longLabel; |
| 89 | |
} |
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public final String getHelpSummary() { |
| 93 | 0 | return helpSummary; |
| 94 | |
} |
| 95 | |
|
| 96 | |
@Override |
| 97 | |
public final String getHelpConstraInteger() { |
| 98 | 0 | return helpConstraInteger; |
| 99 | |
} |
| 100 | |
|
| 101 | |
@Override |
| 102 | |
public final String getHelpDescription() { |
| 103 | 0 | return helpDescription; |
| 104 | |
} |
| 105 | |
|
| 106 | |
@Override |
| 107 | |
public final boolean isForceUpperCase() { |
| 108 | 0 | return forceUpperCase; |
| 109 | |
} |
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public final Integer getMinLength() { |
| 113 | 0 | return minLength; |
| 114 | |
} |
| 115 | |
|
| 116 | |
@Override |
| 117 | |
public final Integer getMaxLength() { |
| 118 | 0 | return maxLength; |
| 119 | |
} |
| 120 | |
|
| 121 | |
@Override |
| 122 | |
public final Integer getMinValue() { |
| 123 | 0 | return minValue; |
| 124 | |
} |
| 125 | |
|
| 126 | |
@Override |
| 127 | |
public final Integer getMaxValue() { |
| 128 | 0 | return maxValue; |
| 129 | |
} |
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public final String getRegexConstraint() { |
| 133 | 0 | return regexConstraint; |
| 134 | |
} |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public final String getRegexContraintMsg() { |
| 138 | 0 | return regexContraintMsg; |
| 139 | |
} |
| 140 | |
|
| 141 | |
@Override |
| 142 | |
public final boolean isRequired() { |
| 143 | 0 | return required; |
| 144 | |
} |
| 145 | |
|
| 146 | |
@Override |
| 147 | |
public final Collection<? extends AbstractWidget> getWidgets() { |
| 148 | 0 | return widgets; |
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | 0 | AbstractControl() { |
| 153 | 0 | this.name = null; |
| 154 | 0 | this.shortLabel = null; |
| 155 | 0 | this.longLabel = null; |
| 156 | 0 | this.helpSummary = null; |
| 157 | 0 | this.helpConstraInteger = null; |
| 158 | 0 | this.helpDescription = null; |
| 159 | 0 | this.forceUpperCase = false; |
| 160 | 0 | this.minLength = null; |
| 161 | 0 | this.maxLength = null; |
| 162 | 0 | this.minValue = null; |
| 163 | 0 | this.maxValue = null; |
| 164 | 0 | this.regexConstraint = null; |
| 165 | 0 | this.regexContraintMsg = null; |
| 166 | 0 | this.required = false; |
| 167 | 0 | this.widgets = null; |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | 0 | AbstractControl(Builder b) { |
| 172 | 0 | this.name = b.name; |
| 173 | 0 | this.shortLabel = b.shortLabel; |
| 174 | 0 | this.longLabel = b.longLabel; |
| 175 | 0 | this.helpSummary = b.helpSummary; |
| 176 | 0 | this.helpConstraInteger = b.helpConstraInteger; |
| 177 | 0 | this.helpDescription = b.helpDescription; |
| 178 | 0 | this.forceUpperCase = b.forceUpperCase; |
| 179 | 0 | this.minLength = b.minLength; |
| 180 | 0 | this.maxLength = b.maxLength; |
| 181 | 0 | this.minValue = b.getMinValue(); |
| 182 | 0 | this.maxValue = b.maxValue; |
| 183 | 0 | this.regexConstraint = b.regexConstraint; |
| 184 | 0 | this.regexContraintMsg = b.regexContraintMsg; |
| 185 | 0 | this.required = b.required; |
| 186 | 0 | this.widgets = b.widgets; |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
@Override |
| 190 | |
public final int hashCode() { |
| 191 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 192 | |
} |
| 193 | |
|
| 194 | |
@Override |
| 195 | |
public final boolean equals(Object obj) { |
| 196 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 197 | |
} |
| 198 | |
|
| 199 | |
@Override |
| 200 | |
public final String toString() { |
| 201 | 0 | return ToStringBuilder.reflectionToString(this); |
| 202 | |
} |
| 203 | |
|
| 204 | 0 | abstract static class Builder implements AbstractControlContract, ModelBuilder { |
| 205 | |
private String name; |
| 206 | |
private String shortLabel; |
| 207 | |
private String longLabel; |
| 208 | |
|
| 209 | |
private String helpSummary; |
| 210 | |
private String helpConstraInteger; |
| 211 | |
private String helpDescription; |
| 212 | |
|
| 213 | |
private boolean forceUpperCase; |
| 214 | |
|
| 215 | |
private Integer minLength; |
| 216 | |
private Integer maxLength; |
| 217 | |
|
| 218 | |
private Integer minValue; |
| 219 | |
private Integer maxValue; |
| 220 | |
|
| 221 | |
private String regexConstraint; |
| 222 | |
private String regexContraintMsg; |
| 223 | |
|
| 224 | |
private boolean required; |
| 225 | |
|
| 226 | |
private Collection<? extends AbstractWidget> widgets; |
| 227 | |
|
| 228 | 0 | Builder(String name) { |
| 229 | 0 | setName(name); |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
static final void partialCreate(AbstractControlContract contract, Builder b) { |
| 233 | |
|
| 234 | 0 | b.setShortLabel(contract.getShortLabel()); |
| 235 | 0 | b.setLongLabel(contract.getLongLabel()); |
| 236 | |
|
| 237 | 0 | b.setHelpSummary(contract.getHelpSummary()); |
| 238 | 0 | b.setHelpConstraInteger(contract.getHelpConstraInteger()); |
| 239 | 0 | b.setHelpDescription(contract.getHelpDescription()); |
| 240 | |
|
| 241 | 0 | b.setForceUpperCase(contract.isForceUpperCase()); |
| 242 | |
|
| 243 | 0 | b.setMinLength(contract.getMinLength()); |
| 244 | 0 | b.setMaxLength(contract.getMaxLength()); |
| 245 | |
|
| 246 | 0 | b.setMinValue(contract.getMinValue()); |
| 247 | 0 | b.setMaxValue(contract.getMaxValue()); |
| 248 | |
|
| 249 | 0 | b.setRegexConstraint(contract.getRegexConstraint()); |
| 250 | 0 | b.setRegexContraintMsg(contract.getRegexContraintMsg()); |
| 251 | |
|
| 252 | 0 | b.setRequired(contract.isRequired()); |
| 253 | |
|
| 254 | 0 | b.setWidgets(contract.getWidgets()); |
| 255 | 0 | } |
| 256 | |
|
| 257 | |
@Override |
| 258 | |
public final String getName() { |
| 259 | 0 | return name; |
| 260 | |
} |
| 261 | |
|
| 262 | |
public final void setName(String name) { |
| 263 | 0 | if (StringUtils.isBlank(name)) { |
| 264 | 0 | throw new IllegalArgumentException("name is blank"); |
| 265 | |
} |
| 266 | |
|
| 267 | 0 | this.name = name; |
| 268 | 0 | } |
| 269 | |
|
| 270 | |
@Override |
| 271 | |
public final String getShortLabel() { |
| 272 | 0 | return shortLabel; |
| 273 | |
} |
| 274 | |
|
| 275 | |
public final void setShortLabel(String shortLabel) { |
| 276 | 0 | this.shortLabel = shortLabel; |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
@Override |
| 280 | |
public final String getLongLabel() { |
| 281 | 0 | return longLabel; |
| 282 | |
} |
| 283 | |
|
| 284 | |
public final void setLongLabel(String longLabel) { |
| 285 | 0 | this.longLabel = longLabel; |
| 286 | 0 | } |
| 287 | |
|
| 288 | |
@Override |
| 289 | |
public final String getHelpSummary() { |
| 290 | 0 | return helpSummary; |
| 291 | |
} |
| 292 | |
|
| 293 | |
public final void setHelpSummary(String helpSummary) { |
| 294 | 0 | this.helpSummary = helpSummary; |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
@Override |
| 298 | |
public final String getHelpConstraInteger() { |
| 299 | 0 | return helpConstraInteger; |
| 300 | |
} |
| 301 | |
|
| 302 | |
public final void setHelpConstraInteger(String helpConstraInteger) { |
| 303 | 0 | this.helpConstraInteger = helpConstraInteger; |
| 304 | 0 | } |
| 305 | |
|
| 306 | |
@Override |
| 307 | |
public final String getHelpDescription() { |
| 308 | 0 | return helpDescription; |
| 309 | |
} |
| 310 | |
|
| 311 | |
public final void setHelpDescription(String helpDescription) { |
| 312 | 0 | this.helpDescription = helpDescription; |
| 313 | 0 | } |
| 314 | |
|
| 315 | |
@Override |
| 316 | |
public final boolean isForceUpperCase() { |
| 317 | 0 | return forceUpperCase; |
| 318 | |
} |
| 319 | |
|
| 320 | |
public final void setForceUpperCase(boolean forceUpperCase) { |
| 321 | 0 | this.forceUpperCase = forceUpperCase; |
| 322 | 0 | } |
| 323 | |
|
| 324 | |
@Override |
| 325 | |
public final Integer getMinLength() { |
| 326 | 0 | return minLength; |
| 327 | |
} |
| 328 | |
|
| 329 | |
public final void setMinLength(Integer minLength) { |
| 330 | 0 | if (minLength != null && minLength < 1) { |
| 331 | 0 | throw new IllegalArgumentException("minLength was < 1"); |
| 332 | |
} |
| 333 | |
|
| 334 | 0 | this.minLength = minLength; |
| 335 | 0 | } |
| 336 | |
|
| 337 | |
@Override |
| 338 | |
public final Integer getMaxLength() { |
| 339 | 0 | return maxLength; |
| 340 | |
} |
| 341 | |
|
| 342 | |
public final void setMaxLength(Integer maxLength) { |
| 343 | 0 | if (maxLength != null && maxLength < 1) { |
| 344 | 0 | throw new IllegalArgumentException("maxLength was < 1"); |
| 345 | |
} |
| 346 | |
|
| 347 | 0 | this.maxLength = maxLength; |
| 348 | 0 | } |
| 349 | |
|
| 350 | |
@Override |
| 351 | |
public final Integer getMinValue() { |
| 352 | 0 | return minValue; |
| 353 | |
} |
| 354 | |
|
| 355 | |
public final void setMinValue(Integer minValue) { |
| 356 | 0 | this.minValue = minValue; |
| 357 | 0 | } |
| 358 | |
|
| 359 | |
@Override |
| 360 | |
public final Integer getMaxValue() { |
| 361 | 0 | return maxValue; |
| 362 | |
} |
| 363 | |
|
| 364 | |
public final void setMaxValue(Integer maxValue) { |
| 365 | 0 | this.maxValue = maxValue; |
| 366 | 0 | } |
| 367 | |
|
| 368 | |
@Override |
| 369 | |
public final String getRegexConstraint() { |
| 370 | 0 | return regexConstraint; |
| 371 | |
} |
| 372 | |
|
| 373 | |
public final void setRegexConstraint(String regexConstraint) { |
| 374 | 0 | this.regexConstraint = regexConstraint; |
| 375 | 0 | } |
| 376 | |
|
| 377 | |
@Override |
| 378 | |
public final String getRegexContraintMsg() { |
| 379 | 0 | return regexContraintMsg; |
| 380 | |
} |
| 381 | |
|
| 382 | |
public final void setRegexContraintMsg(String regexContraintMsg) { |
| 383 | 0 | this.regexContraintMsg = regexContraintMsg; |
| 384 | 0 | } |
| 385 | |
|
| 386 | |
@Override |
| 387 | |
public final boolean isRequired() { |
| 388 | 0 | return required; |
| 389 | |
} |
| 390 | |
|
| 391 | |
public final void setRequired(boolean required) { |
| 392 | 0 | this.required = required; |
| 393 | 0 | } |
| 394 | |
|
| 395 | |
@Override |
| 396 | |
public final Collection<? extends AbstractWidget> getWidgets() { |
| 397 | 0 | return widgets; |
| 398 | |
} |
| 399 | |
|
| 400 | |
public final void setWidgets(Collection<? extends AbstractWidget> widgets) { |
| 401 | 0 | this.widgets = widgets; |
| 402 | 0 | } |
| 403 | |
} |
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | 0 | static final class Constants { |
| 409 | |
static final String TYPE_NAME = "AbstractControlType"; |
| 410 | 0 | static final String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
| 411 | |
} |
| 412 | |
|
| 413 | 0 | static final class Elements { |
| 414 | |
static final String NAME = "name"; |
| 415 | |
static final String SHORT_LABEL = "shortLabel"; |
| 416 | |
static final String LONG_LABEL = "longLabel"; |
| 417 | |
static final String HELP_SUMMARY = "helpSummary"; |
| 418 | |
static final String HELP_CONSTRAInteger = "helpConstraInteger"; |
| 419 | |
static final String HELP_DESCRIPTION = "helpDescription"; |
| 420 | |
static final String FORCE_UPPERCASE = "forceUpperCase"; |
| 421 | |
static final String MIN_LENGTH = "minLength"; |
| 422 | |
static final String MAX_LENGTH = "maxLength"; |
| 423 | |
static final String MIN_VALUE = "minValue"; |
| 424 | |
static final String MAX_VALUE = "maxValue"; |
| 425 | |
static final String REGEX_CONSTRAInteger = "regexConstraint"; |
| 426 | |
static final String REGEX_CONSTRAInteger_MSG = "regexContraintMsg"; |
| 427 | |
static final String REQUIRED = "required"; |
| 428 | |
static final String WIDGETS = "widgets"; |
| 429 | |
} |
| 430 | |
} |