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

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


            final String versionColumn, final JavaType versionType,
            final InheritanceType inheritanceType,
            final boolean mappedSuperclass, final String persistenceUnit,
            final String transactionManager, final String entityName,
            final String sequenceName, final boolean activeRecord) {
        final AnnotationMetadataBuilder entityAnnotationBuilder = new AnnotationMetadataBuilder(
                getEntityAnnotationType(activeRecord));

        // Attributes that apply to all JPA entities (active record or not)
        if (catalog != null) {
            entityAnnotationBuilder.addStringAttribute("catalog", catalog);
        }
        if (entityName != null) {
            entityAnnotationBuilder
                    .addStringAttribute("entityName", entityName);
        }
        if (sequenceName != null) {
            entityAnnotationBuilder.addStringAttribute("sequenceName",
                    sequenceName);
        }
        if (identifierColumn != null) {
            entityAnnotationBuilder.addStringAttribute("identifierColumn",
                    identifierColumn);
        }
        if (identifierField != null) {
            entityAnnotationBuilder.addStringAttribute("identifierField",
                    identifierField);
        }
        if (!LONG_OBJECT.equals(identifierType)) {
            entityAnnotationBuilder.addClassAttribute("identifierType",
                    identifierType);
        }
        if (inheritanceType != null) {
            entityAnnotationBuilder.addStringAttribute("inheritanceType",
                    inheritanceType.name());
        }
        if (mappedSuperclass) {
            entityAnnotationBuilder.addBooleanAttribute("mappedSuperclass",
                    mappedSuperclass);
        }
        if (schema != null) {
            entityAnnotationBuilder.addStringAttribute("schema", schema);
        }
        if (table != null) {
            entityAnnotationBuilder.addStringAttribute("table", table);
        }
        if (versionColumn != null
                && !RooJpaEntity.VERSION_COLUMN_DEFAULT.equals(versionColumn)) {
            entityAnnotationBuilder.addStringAttribute("versionColumn",
                    versionColumn);
        }
        if (versionField != null
                && !RooJpaEntity.VERSION_FIELD_DEFAULT.equals(versionField)) {
            entityAnnotationBuilder.addStringAttribute("versionField",
                    versionField);
        }
        if (!JavaType.INT_OBJECT.equals(versionType)) {
            entityAnnotationBuilder.addClassAttribute("versionType",
                    versionType);
        }

        // Attributes that only apply to entities with CRUD active record
        // methods
        if (activeRecord) {
            if (persistenceUnit != null) {
                entityAnnotationBuilder.addStringAttribute("persistenceUnit",
                        persistenceUnit);
            }
            if (transactionManager != null) {
                entityAnnotationBuilder.addStringAttribute(
                        "transactionManager", transactionManager);
            }
        }

        return entityAnnotationBuilder;
View Full Code Here


                Path.SRC_MAIN_JAVA, permissionEvaluatorClass);
        if (fileManager.exists(identifier)) {
            return; // Type already exists - nothing to do
        }

        final AnnotationMetadataBuilder classAnnotationMetadata = new AnnotationMetadataBuilder(
                ROO_PERMISSION_EVALUATOR);
        final String classMid = PhysicalTypeIdentifier.createIdentifier(
                permissionEvaluatorClass, pathResolver.getPath(identifier));
        final ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                classMid, PUBLIC, permissionEvaluatorClass, CLASS);
        classBuilder.addAnnotation(classAnnotationMetadata.build());
        classBuilder.addImplementsType(PERMISSION_EVALUATOR);
        typeManagementService.createOrUpdateTypeOnDisk(classBuilder.build());

        metadataService.get(PermissionEvaluatorMetadata.createIdentifier(
                permissionEvaluatorClass, focusedSrcMainJava));
View Full Code Here

        if (entityAnnotation == null) {
            return null;
        }

        if (StringUtils.isNotBlank(annotationValues.getEntityName())) {
            final AnnotationMetadataBuilder entityBuilder = new AnnotationMetadataBuilder(
                    entityAnnotation);
            entityBuilder.addStringAttribute("name",
                    annotationValues.getEntityName());
            entityAnnotation = entityBuilder.build();
        }

        return entityAnnotation;
    }
View Full Code Here

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        final boolean hasIdClass = !(identifierType.isCoreType() || identifierType
                .equals(GAE_DATASTORE_KEY));
        final JavaType annotationType = hasIdClass ? EMBEDDED_ID : ID;
        annotations.add(new AnnotationMetadataBuilder(annotationType));

        // Encode keys as strings on GAE to support entity group hierarchies
        if (isGaeEnabled && identifierType.equals(JavaType.STRING)) {
            AnnotationMetadataBuilder extensionBuilder = new AnnotationMetadataBuilder(
                    DATANUCLEUS_JPA_EXTENSION);
            extensionBuilder.addStringAttribute("vendorName", "datanucleus");
            extensionBuilder.addStringAttribute("key", "gae.encoded-pk");
            extensionBuilder.addStringAttribute("value", "true");
            annotations.add(extensionBuilder);
        }

        // Compute the column name, as required
        if (!hasIdClass) {
            if (!"".equals(annotationValues.getSequenceName())) {
                String generationType = isGaeEnabled || isDatabaseDotComEnabled ? "IDENTITY"
                        : "AUTO";

                // ROO-746: Use @GeneratedValue(strategy = GenerationType.TABLE)
                // If the root of the governor declares @Inheritance(strategy =
                // InheritanceType.TABLE_PER_CLASS)
                if ("AUTO".equals(generationType)) {
                    AnnotationMetadata inheritance = governorTypeDetails
                            .getAnnotation(INHERITANCE);
                    if (inheritance == null) {
                        inheritance = getInheritanceAnnotation();
                    }
                    if (inheritance != null) {
                        final AnnotationAttributeValue<?> value = inheritance
                                .getAttribute(new JavaSymbolName("strategy"));
                        if (value instanceof EnumAttributeValue) {
                            final EnumAttributeValue enumAttributeValue = (EnumAttributeValue) value;
                            final EnumDetails details = enumAttributeValue
                                    .getValue();
                            if (details != null
                                    && details.getType().equals(
                                            INHERITANCE_TYPE)) {
                                if ("TABLE_PER_CLASS".equals(details.getField()
                                        .getSymbolName())) {
                                    generationType = "TABLE";
                                }
                            }
                        }
                    }
                }

                final AnnotationMetadataBuilder generatedValueBuilder = new AnnotationMetadataBuilder(
                        GENERATED_VALUE);
                generatedValueBuilder.addEnumAttribute("strategy",
                        new EnumDetails(GENERATION_TYPE, new JavaSymbolName(
                                generationType)));

                if (StringUtils.isNotBlank(annotationValues.getSequenceName())
                        && !(isGaeEnabled || isDatabaseDotComEnabled)) {
                    final String sequenceKey = StringUtils
                            .uncapitalize(destination.getSimpleTypeName())
                            + "Gen";
                    generatedValueBuilder.addStringAttribute("generator",
                            sequenceKey);
                    final AnnotationMetadataBuilder sequenceGeneratorBuilder = new AnnotationMetadataBuilder(
                            SEQUENCE_GENERATOR);
                    sequenceGeneratorBuilder.addStringAttribute("name",
                            sequenceKey);
                    sequenceGeneratorBuilder.addStringAttribute("sequenceName",
                            annotationValues.getSequenceName());
                    annotations.add(sequenceGeneratorBuilder);
                }
                annotations.add(generatedValueBuilder);
            }

            final String identifierColumn = StringUtils
                    .stripToEmpty(getIdentifierColumn());
            String columnName = idField.getSymbolName();
            if (StringUtils.isNotBlank(identifierColumn)) {
                // User has specified an alternate column name
                columnName = identifierColumn;
            }

            final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(
                    COLUMN);
            columnBuilder.addStringAttribute("name", columnName);
            if (identifier != null
                    && StringUtils.isNotBlank(identifier.getColumnDefinition())) {
                columnBuilder.addStringAttribute("columnDefinition",
                        identifier.getColumnDefinition());
            }

            // Add length attribute for String field
            if (identifier != null && identifier.getColumnSize() > 0
                    && identifier.getColumnSize() < 4000
                    && identifierType.equals(JavaType.STRING)) {
                columnBuilder.addIntegerAttribute("length",
                        identifier.getColumnSize());
            }

            // Add precision and scale attributes for numeric field
            if (identifier != null
                    && identifier.getScale() > 0
                    && (identifierType.equals(JavaType.DOUBLE_OBJECT)
                            || identifierType.equals(JavaType.DOUBLE_PRIMITIVE) || identifierType
                                .equals(BIG_DECIMAL))) {
                columnBuilder.addIntegerAttribute("precision",
                        identifier.getColumnSize());
                columnBuilder.addIntegerAttribute("scale",
                        identifier.getScale());
            }

            annotations.add(columnBuilder);
        }
View Full Code Here

    private AnnotationMetadata getInheritanceAnnotation() {
        if (governorTypeDetails.getAnnotation(INHERITANCE) != null) {
            return null;
        }
        if (StringUtils.isNotBlank(annotationValues.getInheritanceType())) {
            final AnnotationMetadataBuilder inheritanceBuilder = new AnnotationMetadataBuilder(
                    INHERITANCE);
            inheritanceBuilder.addEnumAttribute("strategy",
                    new EnumDetails(INHERITANCE_TYPE, new JavaSymbolName(
                            annotationValues.getInheritanceType())));
            return inheritanceBuilder.build();
        }
        return null;
    }
View Full Code Here

        final String catalog = annotationValues.getCatalog();
        final String schema = annotationValues.getSchema();
        final String table = annotationValues.getTable();
        if (StringUtils.isNotBlank(table) || StringUtils.isNotBlank(schema)
                || StringUtils.isNotBlank(catalog)) {
            final AnnotationMetadataBuilder tableBuilder = new AnnotationMetadataBuilder(
                    tableAnnotation);
            if (StringUtils.isNotBlank(catalog)) {
                tableBuilder.addStringAttribute("catalog", catalog);
            }
            if (StringUtils.isNotBlank(schema)) {
                tableBuilder.addStringAttribute("schema", schema);
            }
            if (StringUtils.isNotBlank(table)) {
                tableBuilder.addStringAttribute("name", table);
            }
            return tableBuilder.build();
        }
        return null;
    }
View Full Code Here

            versionType = CALENDAR;
            versionColumn = "lastModifiedDate";
        }

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(new AnnotationMetadataBuilder(VERSION));

        final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(
                COLUMN);
        columnBuilder.addStringAttribute("name", versionColumn);
        annotations.add(columnBuilder);

        return new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations,
                verField, versionType).build();
    }
View Full Code Here

        // We are going to build a replacement AnnotationMetadata.
        // This variable tracks the new attribute values the replacement will
        // hold.
        final Map<JavaSymbolName, AnnotationAttributeValue<?>> replacementAttributeValues = new LinkedHashMap<JavaSymbolName, AnnotationAttributeValue<?>>();

        final AnnotationMetadataBuilder existingBuilder = getDeclaredTypeAnnotation(annotation
                .getAnnotationType());

        if (existingBuilder == null) {
            // Not already present, so just go and add it
            for (final JavaSymbolName incomingAttributeName : annotation
                    .getAttributeNames()) {
                // Do not copy incoming attributes which exist in the
                // attributesToDeleteIfPresent Set
                if (attributesToDeleteIfPresent == null
                        || !attributesToDeleteIfPresent
                                .contains(incomingAttributeName)) {
                    final AnnotationAttributeValue<?> incomingValue = annotation
                            .getAttribute(incomingAttributeName);
                    replacementAttributeValues.put(incomingAttributeName,
                            incomingValue);
                }
            }

            final AnnotationMetadataBuilder replacement = new AnnotationMetadataBuilder(
                    annotation.getAnnotationType(),
                    new ArrayList<AnnotationAttributeValue<?>>(
                            replacementAttributeValues.values()));
            addAnnotation(replacement);
            return true;
        }

        final AnnotationMetadata existing = existingBuilder.build();

        // Copy the existing attributes into the new attributes
        for (final JavaSymbolName existingAttributeName : existing
                .getAttributeNames()) {
            if (attributesToDeleteIfPresent != null
                    && attributesToDeleteIfPresent
                            .contains(existingAttributeName)) {
                hasChanged = true;
            }
            else {
                final AnnotationAttributeValue<?> existingValue = existing
                        .getAttribute(existingAttributeName);
                replacementAttributeValues.put(existingAttributeName,
                        existingValue);
            }
        }

        // Now we ensure every incoming attribute replaces the existing
        for (final JavaSymbolName incomingAttributeName : annotation
                .getAttributeNames()) {
            final AnnotationAttributeValue<?> incomingValue = annotation
                    .getAttribute(incomingAttributeName);

            // Add this attribute to the end of the list if the attribute is not
            // already present
            if (replacementAttributeValues.keySet().contains(
                    incomingAttributeName)) {
                // There was already an attribute. Need to determine if this new
                // attribute value is materially different
                final AnnotationAttributeValue<?> existingValue = replacementAttributeValues
                        .get(incomingAttributeName);
                Validate.notNull(existingValue,
                        "Existing value should have been provided by earlier loop");
                if (!existingValue.equals(incomingValue)) {
                    replacementAttributeValues.put(incomingAttributeName,
                            incomingValue);
                    hasChanged = true;
                }
            }
            else if (attributesToDeleteIfPresent == null
                    || !attributesToDeleteIfPresent
                            .contains(incomingAttributeName)) {
                // This is a new attribute that does not already exist, so add
                // it to the end of the replacement attributes
                replacementAttributeValues.put(incomingAttributeName,
                        incomingValue);
                hasChanged = true;
            }
        }
        // Were there any material changes?
        if (!hasChanged) {
            return false;
        }

        // Make a new AnnotationMetadata representing the replacement
        final AnnotationMetadataBuilder replacement = new AnnotationMetadataBuilder(
                annotation.getAnnotationType(),
                new ArrayList<AnnotationAttributeValue<?>>(
                        replacementAttributeValues.values()));
        annotations.remove(existingBuilder);
        addAnnotation(replacement);
View Full Code Here

            cidBuilder.setImplementsTypes(implementsTypes);
        }

        if (rooAnnotations) {
            final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
            annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
            annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));
            annotations.add(new AnnotationMetadataBuilder(ROO_EQUALS));
            annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE));
            cidBuilder.setAnnotations(annotations);
        }
        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
    }
View Full Code Here

        final AnnotationMetadata annotation = getTypeAnnotation(FACES_CONVERTER);
        if (annotation == null) {
            return null;
        }

        final AnnotationMetadataBuilder annotationBuulder = new AnnotationMetadataBuilder(
                annotation);
        // annotationBuulder.addClassAttribute("forClass", entity); // TODO The
        // forClass attribute causes issues
        annotationBuulder.addStringAttribute("value",
                destination.getFullyQualifiedTypeName());
        return annotationBuulder.build();
    }
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.