Package org.springframework.roo.classpath.details.annotations

Examples of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder


                .add(new ArrayAttributeValue<StringAttributeValue>(
                        new JavaSymbolName("params"), arrayValues));
        requestMappingAttributes.add(new EnumAttributeValue(new JavaSymbolName(
                "method"), new EnumDetails(REQUEST_METHOD, new JavaSymbolName(
                "GET"))));
        final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
                REQUEST_MAPPING, requestMappingAttributes);
        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(requestMapping);

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
View Full Code Here


            if (field.getFieldType().equals(JavaType.BOOLEAN_PRIMITIVE)
                    || field.getFieldType().equals(JavaType.BOOLEAN_OBJECT)) {
                attributes.add(new BooleanAttributeValue(new JavaSymbolName(
                        "required"), false));
            }
            final AnnotationMetadataBuilder requestParamAnnotation = new AnnotationMetadataBuilder(
                    REQUEST_PARAM, attributes);
            annotations.add(requestParamAnnotation.build());
            if (field.getFieldType().equals(DATE)
                    || field.getFieldType().equals(CALENDAR)) {
                dateFieldPresent = true;
                final AnnotationMetadata annotation = MemberFindingUtils
                        .getAnnotationOfType(field.getAnnotations(),
                                DATE_TIME_FORMAT);
                if (annotation != null) {
                    getShortName(DATE_TIME_FORMAT);
                    annotations.add(annotation);
                }
            }
            parameterNames.add(fieldName);
            parameterTypes.add(new AnnotatedJavaType(field.getFieldType(),
                    annotations));

            if (field.getFieldType().equals(JavaType.BOOLEAN_OBJECT)) {
                methodParams.append(fieldName + " == null ? Boolean.FALSE : "
                        + fieldName + ", ");
            }
            else {
                methodParams.append(fieldName + ", ");
            }
        }

        if (methodParams.length() > 0) {
            methodParams.delete(methodParams.length() - 2,
                    methodParams.length());
        }
       
        final List<AnnotationAttributeValue<?>> firstResultAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        firstResultAttributes.add(new StringAttributeValue(new JavaSymbolName(
                "value"), "page"));
        firstResultAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
                "required"), false));
        final AnnotationMetadataBuilder firstResultAnnotation = new AnnotationMetadataBuilder(
                REQUEST_PARAM, firstResultAttributes);

        final List<AnnotationAttributeValue<?>> maxResultsAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        maxResultsAttributes.add(new StringAttributeValue(new JavaSymbolName(
                "value"), "size"));
        maxResultsAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
                "required"), false));
        final AnnotationMetadataBuilder maxResultAnnotation = new AnnotationMetadataBuilder(
                REQUEST_PARAM, maxResultsAttributes);
       
        final List<AnnotationAttributeValue<?>> sortFieldNameAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        sortFieldNameAttributes.add(new StringAttributeValue(new JavaSymbolName(
                "value"), "sortFieldName"));
        sortFieldNameAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
                "required"), false));
        final AnnotationMetadataBuilder sortFieldNameAnnotation = new AnnotationMetadataBuilder(
                REQUEST_PARAM, sortFieldNameAttributes);
       
        final List<AnnotationAttributeValue<?>> sortOrderAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        sortOrderAttributes.add(new StringAttributeValue(new JavaSymbolName(
                "value"), "sortOrder"));
        sortOrderAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
                "required"), false));
        final AnnotationMetadataBuilder sortOrderAnnotation = new AnnotationMetadataBuilder(
                REQUEST_PARAM, sortOrderAttributes);
       
       
        parameterTypes.add(new AnnotatedJavaType(
                new JavaType(Integer.class.getName()),
                firstResultAnnotation.build()));
        parameterTypes.add(new AnnotatedJavaType(
                new JavaType(Integer.class.getName()),
                maxResultAnnotation.build()));
        parameterTypes.add(new AnnotatedJavaType(
                new JavaType(String.class.getName()),
                sortFieldNameAnnotation.build()));
        parameterTypes.add(new AnnotatedJavaType(
                new JavaType(String.class.getName()),
                sortOrderAnnotation.build()));
       
        parameterTypes.add(new AnnotatedJavaType(MODEL));
        if (getGovernorMethod(finderMethodName,
                AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)) != null) {
            return null;
        }

        final List<JavaSymbolName> newParamNames = new ArrayList<JavaSymbolName>();
        newParamNames.addAll(parameterNames);
        newParamNames.add(new JavaSymbolName("page"));
        newParamNames.add(new JavaSymbolName("size"));
        newParamNames.add(new JavaSymbolName("sortFieldName"));
        newParamNames.add(new JavaSymbolName("sortOrder"));
        newParamNames.add(new JavaSymbolName("uiModel"));    
       
        final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        requestMappingAttributes.add(new StringAttributeValue(
                new JavaSymbolName("params"), "find="
                        + finderMetadataDetails
                                .getFinderMethodMetadata()
                                .getMethodName()
                                .getSymbolName()
                                .replaceFirst(
                                        "find"
                                                + javaTypeMetadataHolder
                                                        .getPlural(), "")));
        requestMappingAttributes.add(new EnumAttributeValue(new JavaSymbolName(
                "method"), new EnumDetails(REQUEST_METHOD, new JavaSymbolName(
                "GET"))));
        final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
                REQUEST_MAPPING, requestMappingAttributes);
        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(requestMapping);

        bodyBuilder.appendFormalLine("if (page != null || size != null) {");
View Full Code Here

            // Create field and add it to the ITD, if it hasn't already been
            if (!fields.contains(fieldSymbolName)) {
                // Must make the field
                final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
                annotations.add(new AnnotationMetadataBuilder(AUTOWIRED));
                builder.addField(new FieldMetadataBuilder(getId(), 0,
                        annotations, fieldSymbolName, collaboratorType));
                fields.add(fieldSymbolName);
            }
        }
View Full Code Here

     */
    public AnnotationMetadata getComponentAnnotation() {
        if (governorTypeDetails.getAnnotation(COMPONENT) != null) {
            return null;
        }
        final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(
                COMPONENT);
        return annotationBuilder.build();
    }
View Full Code Here

                        pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, Modifier.PUBLIC, type,
                PhysicalTypeCategory.CLASS);
        cidBuilder.addAnnotation(getAnnotation(jsonEntity));
        cidBuilder.addAnnotation(new AnnotationMetadataBuilder(
                SpringJavaType.CONTROLLER));
        final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
                SpringJavaType.REQUEST_MAPPING);
        requestMapping.addAttribute(new StringAttributeValue(
                new JavaSymbolName("value"), "/"
                        + pluralMetadata.getPlural().toLowerCase()));
        cidBuilder.addAnnotation(requestMapping);
        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
    }
View Full Code Here

    private AnnotationMetadataBuilder getAnnotation(final JavaType type) {
        // Create annotation @RooWebJson(jsonObject = MyObject.class)
        final List<AnnotationAttributeValue<?>> rooJsonAttributes = new ArrayList<AnnotationAttributeValue<?>>();
        rooJsonAttributes.add(new ClassAttributeValue(new JavaSymbolName(
                "jsonObject"), type));
        return new AnnotationMetadataBuilder(RooJavaType.ROO_WEB_JSON,
                rooJsonAttributes);
    }
View Full Code Here

    private Map<JavaType, List<Identifier>> identifierResults;

    private void createIdentifierClass(final JavaType identifierType) {
        final List<AnnotationMetadataBuilder> identifierAnnotations = new ArrayList<AnnotationMetadataBuilder>();

        final AnnotationMetadataBuilder identifierBuilder = new AnnotationMetadataBuilder(
                ROO_IDENTIFIER);
        identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
        identifierAnnotations.add(identifierBuilder);

        // Produce identifier itself
        final String declaredByMetadataId = PhysicalTypeIdentifier
                .createIdentifier(identifierType, projectOperations
View Full Code Here

    private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(
            final JavaType javaType, final Table table,
            final boolean activeRecord) {
        // Create type annotations for new entity
        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
        annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));

        // Find primary key from db metadata and add identifier attributes to
        // @RooJpaEntity
        final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(
                activeRecord ? ROO_JPA_ACTIVE_RECORD : ROO_JPA_ENTITY);
        manageIdentifier(javaType, jpaAnnotationBuilder,
                new HashSet<JavaSymbolName>(), table);

        if (!hasVersionField(table)) {
            jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
        }
        if (table.isDisableGeneratedIdentifiers()) {
            jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
        }

        jpaAnnotationBuilder.addStringAttribute("table", table.getName());
        if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema()
                .getName())) {
            jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema()
                    .getName());
        }

        annotations.add(jpaAnnotationBuilder);
View Full Code Here

        }
        return (PhysicalTypeMetadata) metadataService.get(declaredByMetadataId);
    }

    private AnnotationMetadataBuilder getRooDbManagedAnnotation() {
        final AnnotationMetadataBuilder rooDbManagedBuilder = new AnnotationMetadataBuilder(
                ROO_DB_MANAGED);
        rooDbManagedBuilder.addBooleanAttribute("automaticallyDelete", true);
        return rooDbManagedBuilder;
    }
View Full Code Here

        table.setDisableVersionFields(database.isDisableVersionFields());
        table.setDisableGeneratedIdentifiers(database
                .isDisableGeneratedIdentifiers());

        // Update the @RooJpaEntity/@RooJpaActiveRecord attributes
        final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(
                jpaAnnotation);
        final Set<JavaSymbolName> attributesToDeleteIfPresent = new LinkedHashSet<JavaSymbolName>();
        manageIdentifier(managedEntity.getName(), jpaAnnotationBuilder,
                attributesToDeleteIfPresent, table);

        // Manage versionField attribute
        final AnnotationAttributeValue<?> versionFieldAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName(VERSION_FIELD));
        if (versionFieldAttribute == null) {
            if (hasVersionField(table)) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        VERSION_FIELD));
            }
            else {
                jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
            }
        }
        else {
            final String versionFieldValue = (String) versionFieldAttribute
                    .getValue();
            if (hasVersionField(table)
                    && (StringUtils.isBlank(versionFieldValue) || VERSION
                            .equals(versionFieldValue))) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        VERSION_FIELD));
            }
        }

        final AnnotationAttributeValue<?> sequenceNameFieldAttribute = jpaAnnotation
                .getAttribute(new JavaSymbolName(SEQUENCE_NAME_FIELD));
        if (sequenceNameFieldAttribute == null) {
            if (!table.isDisableGeneratedIdentifiers()) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        SEQUENCE_NAME_FIELD));
            }
            else {
                jpaAnnotationBuilder
                        .addStringAttribute(SEQUENCE_NAME_FIELD, "");
            }
        }
        else {
            final String sequenceNameFieldValue = (String) sequenceNameFieldAttribute
                    .getValue();
            if (!table.isDisableGeneratedIdentifiers()
                    && ("".equals(sequenceNameFieldValue))) {
                attributesToDeleteIfPresent.add(new JavaSymbolName(
                        SEQUENCE_NAME_FIELD));
            }
        }

        // Update the annotation on disk
        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                managedEntity);
        cidBuilder.updateTypeAnnotation(jpaAnnotationBuilder.build(),
                attributesToDeleteIfPresent);
        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
        return table;
    }
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.