1 /*
2 * Copyright 2001-2013 Stephen Colebourne
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 org.joda.beans;
17
18 import java.lang.annotation.ElementType;
19 import java.lang.annotation.Retention;
20 import java.lang.annotation.RetentionPolicy;
21 import java.lang.annotation.Target;
22
23 /**
24 * Annotation defining a property for code generation.
25 * <p>
26 * This annotation must be used on all private instance variables that
27 * should be treated as properties.
28 *
29 * @author Stephen Colebourne
30 */
31 @Retention(RetentionPolicy.RUNTIME)
32 @Target(ElementType.FIELD)
33 public @interface PropertyDefinition {
34
35 /**
36 * The style of the method used to query the property.
37 * <p>
38 * The style is a string describing the getter, typically used for code generation.
39 * By default this is 'smart' which will use the source code knowledge to determine
40 * what to generate. This will be a method of the form {@code isXxx()} for {@code boolean}
41 * and {@code getXxx()} for all other types.
42 * <p>
43 * Supported style stings are:
44 * <ul>
45 * <li>'' - do not generate any form of getter
46 * <li>'smart' - process intelligently - 'is' for boolean and 'get' for other types
47 * <li>'is' - generates isXxx()
48 * <li>'get' - generates getXxx()
49 * <li>'manual' - a method named getXxx() must be manually provided at package scope or greater
50 * </ul>
51 */
52 String get() default "smart";
53
54 /**
55 * The style of the method used to mutate the property.
56 * <p>
57 * The style is a string describing the mutator, typically used for code generation.
58 * By default this is 'smart' which will use the source code knowledge to determine
59 * what to generate. This will be a method of the form {@code setXxx()} for all types unless
60 * the field is {@code final}. If the field is a final {@code Collection} or {@code Map}
61 * of a known type then a set method is generated using {@code addAll} or {@code puAll}
62 * <p>
63 * Standard style stings are:
64 * <ul>
65 * <li>'' - do not generate any form of setter
66 * <li>'smart' - process intelligently - uses 'set' unless final, when it will use 'setClearAddAll'
67 * for common list types or 'setClearPutAll' for common map types and FlexiBean
68 * <li>'set' - generates setXxx()
69 * <li>'setClearAddAll' - generates setXxx() using field.clear() and field.addAll(newData)
70 * <li>'setClearPutAll' - generates setXxx() using field.clear() and field.putAll(newData)
71 * <li>'manual' - a method named setXxx() must be manually provided at package scope or greater
72 * </ul>
73 */
74 String set() default "smart";
75
76 /**
77 * The validator to use.
78 * <p>
79 * The property value may be validated by specifying this attribute.
80 * By default no validation is performed.
81 * The code generator places the validation into the set method and ensures that
82 * new objects are validated correctly.
83 * <p>
84 * Custom validations, are written by writing a static method and referring to it.
85 * For example, {@code public void checkMyValue(Integer val, String propertyName) ...}
86 * The method generally has a {@code void} return, throwing an exception if validation fails.
87 * There must be two arguments, the value and the property name. The value may be the
88 * property type or a superclass (like Object). The property name should be a String.
89 * <p>
90 * Standard validation stings are:
91 * <ul>
92 * <li>'' - do not generate any form of validation
93 * <li>'notNull' - suitable for checking that the value is non-null,
94 * calls JodaBeanUtils.notNull() which throws an IllegalArgumentException
95 * <li>'notEmpty' - suitable for checking that a string is non-null and non-empty,
96 * calls JodaBeanUtils.notEmpty() which throws an IllegalArgumentException
97 * <li>'{className}.{staticMethodName}' - a custom validation method, described above
98 * </ul>
99 */
100 String validate() default "";
101
102 }