You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Validatable.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.data;
  5. import java.util.Collection;
  6. /**
  7. * <p>
  8. * Interface for validatable objects. Defines methods to verify if the object's
  9. * value is valid or not, and to add, remove and list registered validators of
  10. * the object.
  11. * </p>
  12. *
  13. * @author IT Mill Ltd.
  14. * @version
  15. * @VERSION@
  16. * @since 3.0
  17. * @see com.itmill.toolkit.data.Validator
  18. */
  19. public interface Validatable {
  20. /**
  21. * <p>
  22. * Adds a new validator for this object. The validator's
  23. * {@link Validator#validate(Object)} method is activated every time the
  24. * object's value needs to be verified, that is, when the {@link #isValid()}
  25. * method is called. This usually happens when the object's value changes.
  26. * </p>
  27. *
  28. * @param validator
  29. * the new validator
  30. */
  31. void addValidator(Validator validator);
  32. /**
  33. * <p>
  34. * Removes a previously registered validator from the object. The specified
  35. * validator is removed from the object and its <code>validate</code>
  36. * method is no longer called in {@link #isValid()}.
  37. * </p>
  38. *
  39. * @param validator
  40. * the validator to remove
  41. */
  42. void removeValidator(Validator validator);
  43. /**
  44. * <p>
  45. * Lists all validators currently registered for the object. If no
  46. * validators are registered, returns <code>null</code>.
  47. * </p>
  48. *
  49. * @return collection of validators or <code>null</code>
  50. */
  51. public Collection getValidators();
  52. /**
  53. * <p>
  54. * Tests the current value of the object against all registered validators.
  55. * The registered validators are iterated and for each the
  56. * {@link Validator#validate(Object)} method is called. If any validator
  57. * throws the {@link Validator.InvalidValueException} this method returns
  58. * <code>false</code>.
  59. * </p>
  60. *
  61. * @return <code>true</code> if the registered validators concur that the
  62. * value is valid, <code>false</code> otherwise
  63. */
  64. public boolean isValid();
  65. /**
  66. * <p>
  67. * Checks the validity of the validatable. If the validatable is valid this
  68. * method should do nothing, and if it's not valid, it should throw
  69. * <code>Validator.InvalidValueException</code>
  70. * </p>
  71. *
  72. * @throws Validator.InvalidValueException
  73. * if the value is not valid
  74. */
  75. public void validate() throws Validator.InvalidValueException;
  76. /**
  77. * <p>
  78. * Checks the validabtable object accept invalid values.The default value is
  79. * <code>true</code>.
  80. * </p>
  81. *
  82. */
  83. public boolean isInvalidAllowed();
  84. /**
  85. * <p>
  86. * Should the validabtable object accept invalid values. Supporting this
  87. * configuration possibility is optional. By default invalid values are
  88. * allowed.
  89. * </p>
  90. *
  91. * @param invalidValueAllowed
  92. *
  93. * @throws UnsupportedOperationException
  94. * if the setInvalidAllowed is not supported.
  95. */
  96. public void setInvalidAllowed(boolean invalidValueAllowed)
  97. throws UnsupportedOperationException;
  98. }