Package org.springframework.roo.classpath.details

Examples of org.springframework.roo.classpath.details.FieldMetadata


        for (final MethodMetadata method : mutatorMethods) {
            if (!BeanInfoUtils.isMutatorMethod(method)) {
                continue;
            }

            final FieldMetadata field = BeanInfoUtils
                    .getFieldForJavaBeanMethod(memberDetails, method);
            if (field == null) {
                continue;
            }

            // Track any changes to the mutator method (eg it goes away)
            metadataDependencyRegistry.registerDependency(
                    method.getDeclaredByMetadataId(), dodMetadataId);

            final Set<Object> fieldCustomDataKeys = field.getCustomData()
                    .keySet();

            // Never include id or version fields (they shouldn't normally have
            // a mutator anyway, but the user might have added one), or embedded
            // types
            if (fieldCustomDataKeys.contains(IDENTIFIER_FIELD)
                    || fieldCustomDataKeys.contains(EMBEDDED_ID_FIELD)
                    || fieldCustomDataKeys.contains(EMBEDDED_FIELD)
                    || fieldCustomDataKeys.contains(VERSION_FIELD)) {
                continue;
            }

            // Never include persistence transient fields
            if (fieldCustomDataKeys.contains(TRANSIENT_FIELD)) {
                continue;
            }

            // Never include any sort of collection; user has to make such
            // entities by hand
            if (field.getFieldType().isCommonCollectionType()
                    || fieldCustomDataKeys.contains(ONE_TO_MANY_FIELD)
                    || fieldCustomDataKeys.contains(MANY_TO_MANY_FIELD)) {
                continue;
            }
View Full Code Here


                        .contains(CustomDataKeys.VERSION_ACCESSOR_METHOD)) {
            return false; // Only interested in methods which are not accessors
                          // for persistence id or version fields
        }

        final FieldMetadata field = BeanInfoUtils.getFieldForJavaBeanMethod(
                memberDetails, method);
        if (field == null) {
            return false;
        }
        final JavaType fieldType = field.getFieldType();
        if (fieldType.isCommonCollectionType()
                || fieldType.isArray() // Exclude collections and arrays
                || typeLocationService.isInProject(fieldType) // Exclude
                                                              // references to
                                                              // other domain
                                                              // objects as they
                                                              // are too verbose
                || fieldType.equals(JavaType.BOOLEAN_PRIMITIVE)
                || fieldType.equals(JavaType.BOOLEAN_OBJECT) // Exclude boolean
                                                             // values as they
                                                             // would not be
                                                             // meaningful in
                                                             // this
                                                             // presentation
                || field.getCustomData().keySet()
                        .contains(CustomDataKeys.EMBEDDED_FIELD) /*
                                                                  * Not
                                                                  * interested
                                                                  * in embedded
                                                                  * types
 
View Full Code Here

        final List<FieldMetadata> idFields = persistenceMemberLocator
                .getIdentifierFields(entity);
        if (idFields.isEmpty()) {
            return Collections.emptyMap();
        }
        final FieldMetadata identifierField = idFields.get(0);
        final JavaType identifierType = persistenceMemberLocator
                .getIdentifierType(entity);
        if (identifierType == null) {
            return Collections.emptyMap();
        }
        metadataDependencyRegistry.registerDependency(
                identifierField.getDeclaredByMetadataId(),
                metadataIdentificationString);

        final JavaSymbolName entityName = JavaSymbolName
                .getReservedWordSafeName(entity);
        final MethodParameter entityParameter = new MethodParameter(entity,
View Full Code Here

                continue;
            }
            if (method.hasSameName(identifierAccessor, versionAccessor)) {
                continue;
            }
            final FieldMetadata field = BeanInfoUtils.getFieldForPropertyName(
                    memberDetails,
                    BeanInfoUtils.getPropertyNameForJavaBeanMethod(method));
            if (field == null) {
                continue;
            }
            metadataDependencyRegistry.registerDependency(
                    field.getDeclaredByMetadataId(),
                    metadataIdentificationString);

            final CustomDataBuilder customDataBuilder = new CustomDataBuilder(
                    field.getCustomData());
            final JavaType fieldType = field.getFieldType();
            if (fieldType.equals(DATE)
                    && field.getFieldName().getSymbolName().equals("created")) {
                continue;
            }

            final ClassOrInterfaceTypeDetails fieldTypeCid = typeLocationService
                    .getTypeDetails(fieldType);

            // Check field is to be displayed in the entity's list view
            if (listViewFields < MAX_LIST_VIEW_FIELDS
                    && isFieldOfInterest(field) && fieldTypeCid == null) {
                listViewFields++;
                customDataBuilder.put(LIST_VIEW_FIELD_KEY, field);
            }

            final boolean enumerated = field.getCustomData().keySet()
                    .contains(CustomDataKeys.ENUMERATED_FIELD)
                    || isEnum(fieldTypeCid);
            if (enumerated) {
                customDataBuilder.put(ENUMERATED_KEY, null);
            }
            else {
                if (fieldType.isCommonCollectionType()) {
                    parameterTypeLoop: for (final JavaType parameter : fieldType
                            .getParameters()) {
                        final ClassOrInterfaceTypeDetails parameterTypeCid = typeLocationService
                                .getTypeDetails(parameter);
                        if (parameterTypeCid == null) {
                            continue;
                        }

                        for (final ClassOrInterfaceTypeDetails managedBeanType : managedBeanTypes) {
                            final AnnotationMetadata managedBeanAnnotation = managedBeanType
                                    .getAnnotation(ROO_JSF_MANAGED_BEAN);
                            if (((JavaType) managedBeanAnnotation.getAttribute(
                                    "entity").getValue()).equals(parameter)) {
                                customDataBuilder.put(PARAMETER_TYPE_KEY,
                                        parameter);
                                customDataBuilder.put(
                                        PARAMETER_TYPE_MANAGED_BEAN_NAME_KEY,
                                        managedBeanAnnotation.getAttribute(
                                                "beanName").getValue());

                                final LogicalPath logicalPath = PhysicalTypeIdentifier
                                        .getPath(parameterTypeCid
                                                .getDeclaredByMetadataId());
                                final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
                                        .get(PluralMetadata.createIdentifier(
                                                parameter, logicalPath));
                                if (pluralMetadata != null) {
                                    customDataBuilder.put(
                                            PARAMETER_TYPE_PLURAL_KEY,
                                            pluralMetadata.getPlural());
                                }
                                // Only support one generic type parameter
                                break parameterTypeLoop;
                            }
                            // Parameter type is not an entity - test for an
                            // enum
                            if (isEnum(parameterTypeCid)) {
                                customDataBuilder.put(PARAMETER_TYPE_KEY,
                                        parameter);
                            }
                        }
                    }
                }
                else {
                    if (fieldTypeCid != null
                            && !customDataBuilder.keySet().contains(
                                    CustomDataKeys.EMBEDDED_FIELD)) {
                        customDataBuilder.put(APPLICATION_TYPE_KEY, null);
                        final MethodMetadata applicationTypeIdentifierAccessor = persistenceMemberLocator
                                .getIdentifierAccessor(entity);
                        final MethodMetadata applicationTypeVersionAccessor = persistenceMemberLocator
                                .getVersionAccessor(entity);
                        final List<FieldMetadata> applicationTypeFields = new ArrayList<FieldMetadata>();

                        int dropDownFields = 0;
                        final MemberDetails applicationTypeMemberDetails = getMemberDetails(fieldType);
                        for (final MethodMetadata applicationTypeMethod : applicationTypeMemberDetails
                                .getMethods()) {
                            if (!BeanInfoUtils
                                    .isAccessorMethod(applicationTypeMethod)) {
                                continue;
                            }
                            if (applicationTypeMethod.hasSameName(
                                    applicationTypeIdentifierAccessor,
                                    applicationTypeVersionAccessor)) {
                                continue;
                            }
                            final FieldMetadata applicationTypeField = BeanInfoUtils
                                    .getFieldForJavaBeanMethod(
                                            applicationTypeMemberDetails,
                                            applicationTypeMethod);
                            if (applicationTypeField == null) {
                                continue;
                            }
                            if (dropDownFields < MAX_DROP_DOWN_FIELDS
                                    && isFieldOfInterest(applicationTypeField)
                                    && !typeLocationService
                                            .isInProject(applicationTypeField
                                                    .getFieldType())) {
                                dropDownFields++;
                                applicationTypeFields.add(applicationTypeField);
                            }
                        }
View Full Code Here

        entityToWebScaffoldMidMap.put(formBackingType,
                metadataIdentificationString);
        webScaffoldMidToEntityMap.put(metadataIdentificationString,
                formBackingType);

        final FieldMetadata idField = webMetadataService
                .getIdentifierField(formBackingType);
        final SortedMap<JavaType, JavaTypeMetadataDetails> relatedApplicationTypeMetadata = webMetadataService
                .getRelatedApplicationTypeMetadata(formBackingType,
                        formBackingObjectMemberDetails,
                        metadataIdentificationString);
View Full Code Here

        entity = annotationValues.getEntity();

        // Calculate and store field initializers
        for (final Map.Entry<FieldMetadata, DataOnDemandMetadata> entry : locatedFields
                .entrySet()) {
            final FieldMetadata field = entry.getKey();
            final String initializer = getFieldInitializer(field,
                    entry.getValue());
            if (!StringUtils.isBlank(initializer)) {
                fieldInitializers.put(field, initializer);
            }
View Full Code Here

            final String collaboratingFieldName = getCollaboratingFieldName(
                    entityNeedingCollaborator).getSymbolName();

            final JavaSymbolName fieldSymbolName = new JavaSymbolName(
                    collaboratingFieldName);
            final FieldMetadata candidate = governorTypeDetails
                    .getField(fieldSymbolName);
            if (candidate != null) {
                // We really expect the field to be correct if we're going to
                // rely on it
                Validate.isTrue(
                        candidate.getFieldType().equals(collaboratorType),
                        "Field '%s' on '%s' must be of type '%s'",
                        collaboratingFieldName,
                        destination.getFullyQualifiedTypeName(),
                        collaboratorType.getFullyQualifiedTypeName());
                Validate.isTrue(Modifier.isPrivate(candidate.getModifier()),
                        "Field '%s' on '%s' must be private",
                        collaboratingFieldName,
                        destination.getFullyQualifiedTypeName());
                Validate.notNull(
                        MemberFindingUtils.getAnnotationOfType(
                                candidate.getAnnotations(), AUTOWIRED),
                        "Field '%s' on '%s' must be @Autowired",
                        collaboratingFieldName,
                        destination.getFullyQualifiedTypeName());
                // It's ok, so we can move onto the new field
                continue;
View Full Code Here

            // The type parameters to be used by the field type
            final JavaSymbolName fieldName = new JavaSymbolName("data"
                    + StringUtils.repeat("_", index));
            dataFieldName = fieldName;
            final FieldMetadata candidate = governorTypeDetails
                    .getField(fieldName);
            if (candidate != null) {
                // Verify if candidate is suitable
                if (!Modifier.isPrivate(candidate.getModifier())) {
                    // Candidate is not private, so we might run into naming
                    // clashes if someone subclasses this (therefore go onto the
                    // next possible name)
                    continue;
                }

                if (!candidate.getFieldType().equals(listType)) {
                    // Candidate isn't a java.util.List<theEntity>, so it isn't
                    // suitable
                    // The equals method also verifies type params are present
                    continue;
                }
View Full Code Here

                .getIdFields();
        for (int i = 0, n = identifierFields.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            final FieldMetadata field = identifierFields.get(i);
            final String fieldName = field.getFieldName().getSymbolName();
            final JavaType fieldType = field.getFieldType();
            builder.getImportRegistrationResolver().addImport(fieldType);
            final String initializer = getFieldInitializer(field, null);
            bodyBuilder.append(getFieldValidationBody(field, initializer, null,
                    true));
            sb.append(fieldName);
View Full Code Here

                INDEX_SYMBOL);
        final JavaType[] parameterTypes = { entity, JavaType.INT_PRIMITIVE };

        for (final Map.Entry<FieldMetadata, String> entry : fieldInitializers
                .entrySet()) {
            final FieldMetadata field = entry.getKey();
            final JavaSymbolName mutatorName = BeanInfoUtils
                    .getMutatorMethodName(field.getFieldName());

            // Locate user-defined method
            if (governorHasMethod(mutatorName, parameterTypes)) {
                // Method found in governor so do not create method in ITD
                continue;
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.FieldMetadata

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.