View Javadoc

1   /*
2    * Copyright 2009-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.validation.constraints;
17  
18  import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
19  import static java.lang.annotation.ElementType.FIELD;
20  import static java.lang.annotation.ElementType.METHOD;
21  import static java.lang.annotation.RetentionPolicy.RUNTIME;
22  
23  import java.lang.annotation.Documented;
24  import java.lang.annotation.Retention;
25  import java.lang.annotation.Target;
26  
27  import javax.validation.Constraint;
28  import javax.validation.Payload;
29  
30  import de.smartics.validation.constraints.impl.NotBlankValidator;
31  
32  /**
33   * The annotated element of type {@link String} must not be <code>null</code>,
34   * empty or contain only whitespaces. With other words, the String value must
35   * not be <em>blank</em>.
36   * <p>
37   * Only {@link String} values are allowed.
38   * </p>
39   */
40  @Target(
41  { METHOD, FIELD, ANNOTATION_TYPE })
42  @Retention(RUNTIME)
43  @Documented
44  @Constraint(validatedBy = NotBlankValidator.class)
45  public @interface NotBlank
46  {
47    // ********************************* Fields *********************************
48  
49    /**
50     * The key of the message rendered, if the constraint has been violated.
51     * <p>
52     * The value of this constant is {@value}.
53     * </p>
54     */
55    String MESSAGE_KEY = "{de.smartics.validation.constraints.NotBlank.message}";
56  
57    // ********************************* Methods ********************************
58  
59    /**
60     * Returns the message key to be rendered, if the constraint has been
61     * violated.
62     * <p>
63     * Defaults to returning {@value #MESSAGE_KEY}.
64     * </p>
65     */
66    String message() default MESSAGE_KEY;
67  
68    /**
69     * Support of validation groups.
70     */
71    Class<?>[] groups() default {};
72  
73    /**
74     * Support of payloads.
75     */
76    Class<? extends Payload>[] payload() default {};
77  
78  }