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

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