1 /*
2 * Copyright 2012-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.properties.tutorial.property.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 /**
31 * A sample custom constraint for this tutorial.
32 */
33 @Target(
34 { METHOD, FIELD, ANNOTATION_TYPE })
35 @Retention(RUNTIME)
36 @Documented
37 @Constraint(validatedBy = RealHappinessValidator.class)
38 public @interface RealHappiness
39 {
40 // ********************************* Fields *********************************
41
42 /**
43 * The key of the message rendered, if the constraint has been violated.
44 * <p>
45 * The value of this constant is {@value}.
46 * </p>
47 */
48 String MESSAGE_KEY = "{de.smartics.properties.tutorial.property.constraints.RealHappiness.message}";
49
50 // ********************************* Methods ********************************
51
52 /**
53 * Returns the message key to be rendered, if the constraint has been
54 * violated.
55 * <p>
56 * Defaults to returning {@value #MESSAGE_KEY}.
57 * </p>
58 */
59 String message() default MESSAGE_KEY;
60
61 /**
62 * Support of validation groups.
63 */
64 Class<?>[] groups() default {};
65
66 /**
67 * Support of payloads.
68 */
69 Class<? extends Payload>[] payload() default {};
70 }