use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class DbreMetadata method addCascadeType.
private void addCascadeType(final AnnotationMetadataBuilder annotationBuilder, final CascadeAction onUpdate, final CascadeAction onDelete) {
final String attributeName = "cascade";
boolean hasCascadeType = true;
if (onUpdate == CascadeAction.CASCADE && onDelete == CascadeAction.CASCADE) {
annotationBuilder.addEnumAttribute(attributeName, CASCADE_TYPE, "ALL");
} else if (onUpdate == CascadeAction.CASCADE && onDelete != CascadeAction.CASCADE) {
final List<EnumAttributeValue> arrayValues = new ArrayList<EnumAttributeValue>();
arrayValues.add(new EnumAttributeValue(new JavaSymbolName(attributeName), new EnumDetails(CASCADE_TYPE, new JavaSymbolName("PERSIST"))));
arrayValues.add(new EnumAttributeValue(new JavaSymbolName(attributeName), new EnumDetails(CASCADE_TYPE, new JavaSymbolName("MERGE"))));
annotationBuilder.addAttribute(new ArrayAttributeValue<EnumAttributeValue>(new JavaSymbolName(attributeName), arrayValues));
} else if (onUpdate != CascadeAction.CASCADE && onDelete == CascadeAction.CASCADE) {
annotationBuilder.addEnumAttribute(attributeName, CASCADE_TYPE.getSimpleTypeName(), "REMOVE");
} else {
hasCascadeType = false;
}
if (hasCascadeType) {
builder.getImportRegistrationResolver().addImport(CASCADE_TYPE);
}
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class JspOperationsImpl method getHttpPostMethod.
private MethodMetadataBuilder getHttpPostMethod(final String declaredByMetadataId) {
final List<AnnotationMetadataBuilder> postMethodAnnotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> postMethodAttributes = new ArrayList<AnnotationAttributeValue<?>>();
postMethodAttributes.add(new EnumAttributeValue(new JavaSymbolName("method"), new EnumDetails(REQUEST_METHOD, new JavaSymbolName("POST"))));
postMethodAttributes.add(new StringAttributeValue(new JavaSymbolName("value"), "{id}"));
postMethodAnnotations.add(new AnnotationMetadataBuilder(REQUEST_MAPPING, postMethodAttributes));
final List<AnnotatedJavaType> postParamTypes = new ArrayList<AnnotatedJavaType>();
final AnnotationMetadataBuilder idParamAnnotation = new AnnotationMetadataBuilder(PATH_VARIABLE);
postParamTypes.add(new AnnotatedJavaType(new JavaType("java.lang.Long"), idParamAnnotation.build()));
postParamTypes.add(new AnnotatedJavaType(MODEL_MAP));
postParamTypes.add(new AnnotatedJavaType(HTTP_SERVLET_REQUEST));
postParamTypes.add(new AnnotatedJavaType(HTTP_SERVLET_RESPONSE));
final List<JavaSymbolName> postParamNames = new ArrayList<JavaSymbolName>();
postParamNames.add(new JavaSymbolName("id"));
postParamNames.add(new JavaSymbolName("modelMap"));
postParamNames.add(new JavaSymbolName("request"));
postParamNames.add(new JavaSymbolName("response"));
final MethodMetadataBuilder postMethodBuilder = new MethodMetadataBuilder(declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName("post"), JavaType.VOID_PRIMITIVE, postParamTypes, postParamNames, new InvocableMemberBodyBuilder());
postMethodBuilder.setAnnotations(postMethodAnnotations);
return postMethodBuilder;
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class DateField method decorateAnnotationsList.
@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));
}
// Only add a DateTimeFormat annotation if class is not a DTO
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));
}
Aggregations