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

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