diff options
author | Artur Signell <artur.signell@itmill.com> | 2010-05-10 14:53:13 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2010-05-10 14:53:13 +0000 |
commit | 5b5b4970584df91f136ef5c198ba2d42113deee3 (patch) | |
tree | 0105a1314e15bcd57e5a33eccc7a90e0e803e88d /src/com | |
parent | 5e35e3c36da3de2f0832a9f5a4e7c3f1b42033e7 (diff) | |
download | vaadin-framework-5b5b4970584df91f136ef5c198ba2d42113deee3.tar.gz vaadin-framework-5b5b4970584df91f136ef5c198ba2d42113deee3.zip |
Updated javadoc (#4681)
svn changeset:13121/svn branch:6.4
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/data/validator/AbstractValidator.java | 144 |
1 files changed, 76 insertions, 68 deletions
diff --git a/src/com/vaadin/data/validator/AbstractValidator.java b/src/com/vaadin/data/validator/AbstractValidator.java index af78faa442..84cf379f31 100644 --- a/src/com/vaadin/data/validator/AbstractValidator.java +++ b/src/com/vaadin/data/validator/AbstractValidator.java @@ -1,71 +1,79 @@ /* @ITMillApache2LicenseForJavaFiles@ */ -package com.vaadin.data.validator;
-
-import com.vaadin.data.Validator;
-
-/**
- * Default Validator base class. See {@link com.vaadin.data.validator.Validator}
- * for more information.
- * <p>
- * If the validation fails, the exception thrown contains the error message with
- * its argument 0 replaced with the toString() of the object being validated.
- * </p>
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 5.4
- */
-@SuppressWarnings("serial")
-public abstract class AbstractValidator implements Validator {
-
- /**
- * Error message.
- */
- private String errorMessage;
-
- /**
- * Constructs a validator with an error message.
- *
- * @param errorMessage
- * the message included in the exception (with its parameter {0}
- * replaced by toString() of the object to be validated) in case
- * the validation fails
- */
- public AbstractValidator(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
- public void validate(Object value) throws InvalidValueException {
- if (!isValid(value)) {
- String message;
- if (value == null) {
- message = errorMessage.replace("{0}", "null");
- } else {
- message = errorMessage.replace("{0}", value.toString());
- }
- throw new InvalidValueException(message);
- }
- }
-
- /**
- * Gets the message to be displayed in case the value does not validate.
- *
- * @return the Error Message.
- */
- public String getErrorMessage() {
- return errorMessage;
- }
-
- /**
- * Sets the message to be displayed in case the value does not validate.
- *
- * @param errorMessage
- * the Error Message to set.
- */
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-}
+package com.vaadin.data.validator; + +import com.vaadin.data.Validator; + +/** + * Abstract {@link com.vaadin.data.validator.Validator Validator} implementation + * that provides a basic Validator implementation except the + * {@link #isValid(Object)} method. Sub-classes need to implement the + * {@link #isValid(Object)} method. + * <p> + * To include the value that failed validation in the exception message you can + * use "{0}" in the error message. This will be replaced with the failed value + * (converted to string using {@link #toString()}) or "null" if the value is + * null. + * </p> + * + * @author IT Mill Ltd. + * @version + * @VERSION@ + * @since 5.4 + */ +@SuppressWarnings("serial") +public abstract class AbstractValidator implements Validator { + + /** + * Error message that is included in an {@link InvalidValueException} if + * such is thrown. + */ + private String errorMessage; + + /** + * Constructs a validator with the given error message. + * + * @param errorMessage + * the message to be included in an {@link InvalidValueException} + * (with "{0}" replaced by the value that failed validation). + */ + public AbstractValidator(String errorMessage) { + this.errorMessage = errorMessage; + } + + public void validate(Object value) throws InvalidValueException { + if (!isValid(value)) { + String message; + if (value == null) { + message = errorMessage.replace("{0}", "null"); + } else { + message = errorMessage.replace("{0}", value.toString()); + } + throw new InvalidValueException(message); + } + } + + /** + * Returns the message to be included in the exception in case the value + * does not validate. + * + * @return the error message provided in the constructor or using + * {@link #setErrorMessage(String)}. + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Sets the message to be included in the exception in case the value does + * not validate. The exception message is typically shown to the end user. + * + * @param errorMessage + * the error message. "{0}" is automatically replaced by the + * value that did not validate. + */ + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} |