@Override
public void decorateAnnotationsList(
final List<AnnotationMetadataBuilder> annotations) {
super.decorateAnnotationsList(annotations);
if (past) {
annotations.add(new AnnotationMetadataBuilder(PAST));
}
if (future) {
annotations.add(new AnnotationMetadataBuilder(FUTURE));
}
if (persistenceType != null) {
// Add JSR 220 @Temporal annotation
String value = null;
if (persistenceType == DateFieldPersistenceType.JPA_DATE) {
value = "DATE";
}
else if (persistenceType == DateFieldPersistenceType.JPA_TIME) {
value = "TIME";
}
else if (persistenceType == DateFieldPersistenceType.JPA_TIMESTAMP) {
value = "TIMESTAMP";
}
final List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new EnumAttributeValue(new JavaSymbolName("value"),
new EnumDetails(TEMPORAL_TYPE, new JavaSymbolName(value))));
annotations.add(new AnnotationMetadataBuilder(TEMPORAL, attrs));
}
// Always add a DateTimeFormat annotation
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
if (pattern != null) {
attributes.add(new StringAttributeValue(new JavaSymbolName(
"pattern"), pattern));
}
else {
final String dateStyle = null != dateFormat ? String
.valueOf(dateFormat.getShortKey()) : "M";
final String timeStyle = null != timeFormat ? String
.valueOf(timeFormat.getShortKey()) : "-";
attributes.add(new StringAttributeValue(
new JavaSymbolName("style"), dateStyle + timeStyle));
}
annotations.add(new AnnotationMetadataBuilder(DATE_TIME_FORMAT,
attributes));
}