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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. /**
  20. * <p>
  21. * Interface for validatable objects. Defines methods to verify if the object's
  22. * value is valid or not, and to add, remove and list registered validators of
  23. * the object.
  24. * </p>
  25. *
  26. * @author Vaadin Ltd.
  27. * @since 3.0
  28. * @see com.vaadin.data.Validator
  29. */
  30. public interface Validatable extends Serializable {
  31. /**
  32. * <p>
  33. * Adds a new validator for this object. The validator's
  34. * {@link Validator#validate(Object)} method is activated every time the
  35. * object's value needs to be verified, that is, when the {@link #isValid()}
  36. * method is called. This usually happens when the object's value changes.
  37. * </p>
  38. *
  39. * @param validator
  40. * the new validator
  41. */
  42. void addValidator(Validator validator);
  43. /**
  44. * <p>
  45. * Removes a previously registered validator from the object. The specified
  46. * validator is removed from the object and its <code>validate</code> method
  47. * is no longer called in {@link #isValid()}.
  48. * </p>
  49. *
  50. * @param validator
  51. * the validator to remove
  52. */
  53. void removeValidator(Validator validator);
  54. /**
  55. * Removes all validators from this object, as if
  56. * {@link #removeValidator(Validator) removeValidator} was called for each
  57. * registered validator.
  58. */
  59. void removeAllValidators();
  60. /**
  61. * <p>
  62. * Returns a collection of all validators currently registered for the
  63. * object. The collection may be immutable. Calling
  64. * <code>removeValidator</code> for this Validatable while iterating over
  65. * the collection may be unsafe (e.g. may throw
  66. * <code>ConcurrentModificationException</code>.)
  67. * </p>
  68. *
  69. * @return A collection of validators
  70. */
  71. public Collection<Validator> getValidators();
  72. /**
  73. * <p>
  74. * Tests the current value of the object against all registered validators.
  75. * The registered validators are iterated and for each the
  76. * {@link Validator#validate(Object)} method is called. If any validator
  77. * throws the {@link Validator.InvalidValueException} this method returns
  78. * <code>false</code>.
  79. * </p>
  80. *
  81. * @return <code>true</code> if the registered validators concur that the
  82. * value is valid, <code>false</code> otherwise
  83. */
  84. public boolean isValid();
  85. /**
  86. * <p>
  87. * Checks the validity of the validatable. If the validatable is valid this
  88. * method should do nothing, and if it's not valid, it should throw
  89. * <code>Validator.InvalidValueException</code>
  90. * </p>
  91. *
  92. * @throws Validator.InvalidValueException
  93. * if the value is not valid
  94. */
  95. public void validate() throws Validator.InvalidValueException;
  96. /**
  97. * <p>
  98. * Checks the validabtable object accept invalid values.The default value is
  99. * <code>true</code>.
  100. * </p>
  101. *
  102. */
  103. public boolean isInvalidAllowed();
  104. /**
  105. * <p>
  106. * Should the validabtable object accept invalid values. Supporting this
  107. * configuration possibility is optional. By default invalid values are
  108. * allowed.
  109. * </p>
  110. *
  111. * @param invalidValueAllowed
  112. *
  113. * @throws UnsupportedOperationException
  114. * if the setInvalidAllowed is not supported.
  115. */
  116. public void setInvalidAllowed(boolean invalidValueAllowed)
  117. throws UnsupportedOperationException;
  118. }