Search in sources :

Example 11 with EnumAttributeValue

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);
    }
}
Also used : ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) List(java.util.List) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails)

Example 12 with EnumAttributeValue

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;
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) JavaType(org.springframework.roo.model.JavaType) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 13 with EnumAttributeValue

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));
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)13 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)13 ArrayList (java.util.ArrayList)11 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)11 EnumDetails (org.springframework.roo.model.EnumDetails)11 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)10 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)7 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)6 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)5 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)5 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)5 JavaType (org.springframework.roo.model.JavaType)5 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)4 CharAttributeValue (org.springframework.roo.classpath.details.annotations.CharAttributeValue)4 DoubleAttributeValue (org.springframework.roo.classpath.details.annotations.DoubleAttributeValue)4 IntegerAttributeValue (org.springframework.roo.classpath.details.annotations.IntegerAttributeValue)4 LongAttributeValue (org.springframework.roo.classpath.details.annotations.LongAttributeValue)4 List (java.util.List)3 AnnotationExpr (com.github.antlrjavaparser.api.expr.AnnotationExpr)2 ArrayInitializerExpr (com.github.antlrjavaparser.api.expr.ArrayInitializerExpr)2