|
22 | 22 | import java.lang.annotation.RetentionPolicy; |
23 | 23 | import java.lang.annotation.Target; |
24 | 24 |
|
| 25 | +import org.ocpsoft.rewrite.bind.Converter; |
| 26 | + |
| 27 | +/** |
| 28 | + * <p> |
| 29 | + * Tells Rewrite to use a converter to convert the value of a specific parameter binding. |
| 30 | + * </p> |
| 31 | + * |
| 32 | + * There are various ways to specify the kind of converter you want to use. You could for example reference a converter |
| 33 | + * class this way: |
| 34 | + * |
| 35 | + * <pre> |
| 36 | + * {@literal @}ParameterBinding |
| 37 | + * {@literal @}Convert(with = MyLocaleConverter.class) |
| 38 | + * private Locale locale; |
| 39 | + * </pre> |
| 40 | + * |
| 41 | + * <p> |
| 42 | + * You can always refer to {@link Converter} implementations this way. Integration modules like the JSF integration |
| 43 | + * module provide support for frameworks specific converters on top of that. |
| 44 | + * </p> |
| 45 | + * |
| 46 | + * <p> |
| 47 | + * You can also refer to a converter using an unique ID like this: |
| 48 | + * </p> |
| 49 | + * |
| 50 | + * <pre> |
| 51 | + * {@literal @}ParameterBinding |
| 52 | + * {@literal @}Convert(id = "com.example.MyConverterId") |
| 53 | + * private Locale locale; |
| 54 | + * </pre> |
| 55 | + * |
| 56 | + * <p> |
| 57 | + * Without any attributes set, Rewrite will try to find a converter by the type of the annotated field. |
| 58 | + * </p> |
| 59 | + * |
| 60 | + * <pre> |
| 61 | + * {@literal @}ParameterBinding |
| 62 | + * {@literal @}Convert |
| 63 | + * private Locale locale; |
| 64 | + * </pre> |
| 65 | + * |
| 66 | + * <p> |
| 67 | + * Please note that which of the three ways works in your case highly depends on the integration modules that you have |
| 68 | + * added to your application. |
| 69 | + * </p> |
| 70 | + * |
| 71 | + * @author Christian Kaltepoth |
| 72 | + */ |
25 | 73 | @Inherited |
26 | 74 | @Documented |
27 | 75 | @Target(ElementType.FIELD) |
28 | 76 | @Retention(RetentionPolicy.RUNTIME) |
29 | 77 | public @interface Convert |
30 | 78 | { |
| 79 | + |
| 80 | + /** |
| 81 | + * Can be used to refer to a converter class that should be used for conversion. |
| 82 | + */ |
31 | 83 | Class<?> with() default Object.class; |
32 | 84 |
|
| 85 | + /** |
| 86 | + * Can be used to refer to a converter by some kind of unique ID. |
| 87 | + */ |
33 | 88 | String id() default ""; |
| 89 | + |
34 | 90 | } |
0 commit comments