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.InetAdressAvailabilityValidator;
31  import de.smartics.validation.constraints.impl.MailServerAvailabilityValidator;
32  import de.smartics.validation.constraints.impl.UriAvailabilityValidator;
33  import de.smartics.validation.constraints.impl.UrlAvailabilityValidator;
34  
35  /**
36   * The annotated element is checked to be available.
37   */
38  @Target({ METHOD, FIELD, ANNOTATION_TYPE })
39  @Retention(RUNTIME)
40  @Documented
41  @Constraint(validatedBy = { UriAvailabilityValidator.class,
42                             UrlAvailabilityValidator.class,
43                             InetAdressAvailabilityValidator.class,
44                             MailServerAvailabilityValidator.class })
45  public @interface Available
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.Available.message}";
56  
57    /**
58     * A second in milliseconds.
59     */
60    int ONE_SECOND = 1000;
61  
62    // ********************************* Methods ********************************
63  
64    /**
65     * The value expected to be returned.
66     */
67    String value() default "200";
68  
69    /**
70     * The connection timeout in milliseconds.
71     */
72    int timeout() default ONE_SECOND;
73  
74    /**
75     * Returns the message key to be rendered, if the constraint has been
76     * violated.
77     * <p>
78     * Defaults to returning {@value #MESSAGE_KEY}.
79     * </p>
80     */
81    String message() default MESSAGE_KEY;
82  
83    /**
84     * Support of validation groups.
85     */
86    Class<?>[] groups() default {};
87  
88    /**
89     * Support of payloads.
90     */
91    Class<? extends Payload>[] payload() default {};
92  
93  }