Package org.springframework.roo.classpath.details

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


      final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
      bodyBuilder.appendFormalLine("this."
          + field.getFieldName().getSymbolName() + " = "
          + field.getFieldName().getSymbolName() + ";");

      return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
          methodName, JavaType.VOID_PRIMITIVE,
          AnnotatedJavaType.convertFromJavaTypes(parameterType),
          parameterNames, bodyBuilder);
    }
View Full Code Here


        bodyBuilder.appendFormalLine("return '\0';");
      }
    } else {
      bodyBuilder.appendFormalLine("return null;");
    }
    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
        returnType, bodyBuilder);

  }
View Full Code Here

        itdTypeDetails = builder.build();
    }

    private MethodMetadataBuilder getIdentifierAccessor() {
        if (parent != null) {
            final MethodMetadataBuilder parentIdAccessor = parent
                    .getIdentifierAccessor();
            if (parentIdAccessor != null
                    && parentIdAccessor.getReturnType().equals(idType)) {
                return parentIdAccessor;
            }
        }

        JavaSymbolName requiredAccessorName = BeanInfoUtils
                .getAccessorMethodName(idField);

        // See if the user provided the field
        if (!getId().equals(idField.getDeclaredByMetadataId())) {
            // Locate an existing accessor
            final MethodMetadata method = memberDetails.getMethod(
                    requiredAccessorName, new ArrayList<JavaType>());
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required accessor name
                // unique
                requiredAccessorName = new JavaSymbolName(
                        requiredAccessorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public accessor for
        // it
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("return this."
                + idField.getFieldName().getSymbolName() + ";");

        return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
                requiredAccessorName, idField.getFieldType(), bodyBuilder);
    }
View Full Code Here

        return fieldBuilder.build();
    }

    private MethodMetadataBuilder getIdentifierMutator() {
        if (parent != null) {
            final MethodMetadataBuilder parentIdMutator = parent
                    .getIdentifierMutator();
            if (parentIdMutator != null
                    && parentIdMutator.getParameterTypes().get(0).getJavaType()
                            .equals(idType)) {
                return parentIdMutator;
            }
        }

        JavaSymbolName requiredMutatorName = BeanInfoUtils
                .getMutatorMethodName(idField);

        final List<JavaType> parameterTypes = Arrays.asList(idField
                .getFieldType());
        final List<JavaSymbolName> parameterNames = Arrays
                .asList(new JavaSymbolName("id"));

        // See if the user provided the field
        if (!getId().equals(idField.getDeclaredByMetadataId())) {
            // Locate an existing mutator
            final MethodMetadata method = memberDetails.getMethod(
                    requiredMutatorName, parameterTypes);
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required mutator name unique
                requiredMutatorName = new JavaSymbolName(
                        requiredMutatorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public mutator for it
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("this."
                + idField.getFieldName().getSymbolName() + " = id;");

        return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
                requiredMutatorName, JavaType.VOID_PRIMITIVE,
                AnnotatedJavaType.convertFromJavaTypes(parameterTypes),
                parameterNames, bodyBuilder);
    }
View Full Code Here

                    final String body = method.getBody(lowerLayerCallAdditions);
                    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
                    bodyBuilder.appendFormalLine(body);
                    List<JavaSymbolName> parameterNames = method
                            .getParameterNames(domainType, idType);
                    MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder(
                            getId(), Modifier.PUBLIC, methodName,
                            method.getReturnType(domainType),
                            AnnotatedJavaType.convertFromJavaTypes(method
                                    .getParameterTypes(domainType, idType)),
                            parameterNames, bodyBuilder);

                    boolean isCreateOrUpdateMethod = false;
                    boolean isReadMethod = false;
                    boolean isDeleteMethod = false;

                    // checks to see if the method is a "save" method
                    if (method.getKey().equals(
                            CustomDataKeys.PERSIST_METHOD.name())
                            || method.getKey().equals(
                                    CustomDataKeys.MERGE_METHOD.name())) {
                        isCreateOrUpdateMethod = true;
                    }

                    // Checks to see if the method is a "delete method
                    if (method.getKey().equals(
                            CustomDataKeys.REMOVE_METHOD.name())) {
                        isDeleteMethod = true;
                    }

                    // Checks to see if the method is a "read" method
                    if (method.getKey().equals(
                            CustomDataKeys.FIND_ALL_METHOD.name())
                            || method.getKey().equals(
                                    CustomDataKeys.FIND_ENTRIES_METHOD.name())
                            || method.getKey().equals(
                                    CustomDataKeys.FIND_METHOD.name())
                            || method.getKey().equals(
                                    CustomDataKeys.COUNT_ALL_METHOD)) {
                        isReadMethod = true;
                    }
                   
                    String authorizeValue = "";
                    String authorizedRolesComponent = "";
                    String permissionEvalutorComponent = "";

                    // Adds required roles to @PreAuthorize or @PostAuthorize annotation if the
                    // required roles for persist methods
                    if (serviceAnnotationValues.getAuthorizedCreateOrUpdateRoles() != null &&
                        serviceAnnotationValues.getAuthorizedCreateOrUpdateRoles().length > 0
                            && isCreateOrUpdateMethod) {
                        authorizedRolesComponent = getRoles(serviceAnnotationValues.getAuthorizedCreateOrUpdateRoles());
                    }

                    // Adds required roles to @PreAuthorize or @PostAuthorize annotation if the
                    // required roles exist for read methods
                    if (serviceAnnotationValues.getAuthorizedReadRoles() != null &&
                        serviceAnnotationValues.getAuthorizedReadRoles().length > 0
                            && isReadMethod) {
                        authorizedRolesComponent = getRoles(serviceAnnotationValues.getAuthorizedReadRoles());
                    }

                    // Adds required roles to @PreAuthorize or @PostAuthorize annotation if the
                    // required roles exist for delete methods
                    if (serviceAnnotationValues.getAuthorizedDeleteRoles() != null &&
                        serviceAnnotationValues.getAuthorizedDeleteRoles().length > 0
                        && isDeleteMethod) {
                        authorizedRolesComponent = getRoles(serviceAnnotationValues.getAuthorizedDeleteRoles());
                    }
                   
                    final String permissionName = method.getPermissionName(domainType,
                            domainTypePlurals.get(domainType));
                   
                    if (permissionName != null && serviceAnnotationValues.usePermissionEvaluator()) {
                      // Add hasPermission to @PreAuthorize or @PostAuthorize annotation if
                      // required
                      permissionEvalutorComponent = String.format("hasPermission(%s, '%s')", method.usesPostAuthorize() ? "returnObject" : "#" + parameterNames.get(0).getSymbolName(), permissionName);
                    }

                    // Builds value for @PreAuthorize
                    if (!authorizedRolesComponent.equals("") && !permissionEvalutorComponent.equals("")) {
                      authorizeValue= String.format("isAuthenticated() AND ((%s) OR %s)", authorizedRolesComponent, permissionEvalutorComponent);
                    }
                    else if (!authorizedRolesComponent.equals("")) {
                      authorizeValue= String.format("isAuthenticated() AND (%s)", authorizedRolesComponent);
                    }
                    else if (!permissionEvalutorComponent.equals("")) {
                      authorizeValue= String.format("isAuthenticated() AND %s", permissionEvalutorComponent);
                    }
                    else if (serviceAnnotationValues.requireAuthentication()) {
                      authorizeValue ="isAuthenticated()";
                    }

                    if (!authorizeValue.equals("")) {
                        final AnnotationMetadataBuilder annotationMetadataBuilder = new AnnotationMetadataBuilder(method.usesPostAuthorize() ? SpringJavaType.POST_AUTHORIZE : PRE_AUTHORIZE);
                        annotationMetadataBuilder.addStringAttribute("value",
                            authorizeValue.toString());
                        methodMetadataBuilder
                                .addAnnotation(annotationMetadataBuilder
                                        .build());
                    }

                    builder.addMethod(methodMetadataBuilder);
View Full Code Here

                config));

        final List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
        final List<AnnotationMetadataBuilder> methodAnnotations = new ArrayList<AnnotationMetadataBuilder>();
        methodAnnotations.add(new AnnotationMetadataBuilder(TEST));
        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName(
                        "testMarkerMethod"), JavaType.VOID_PRIMITIVE,
                new InvocableMemberBodyBuilder());
        methodBuilder.setAnnotations(methodAnnotations);
        methods.add(methodBuilder);

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, Modifier.PUBLIC, name,
                PhysicalTypeCategory.CLASS);
View Full Code Here

                        .appendFormalLine("org.junit.Assert.assertEquals(expectedCount, "
                                + countMethod + ");");
            }
        }

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName(
                        "testMethod"), JavaType.VOID_PRIMITIVE, bodyBuilder);
        methodBuilder.setAnnotations(methodAnnotations);
        methods.add(methodBuilder);

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, Modifier.PUBLIC, name,
                PhysicalTypeCategory.CLASS);
View Full Code Here

                            && !Modifier.isAbstract(method.getModifier())) {
                        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
                        bodyBuilder
                                .appendFormalLine("org.junit.Assert.assertTrue(true);");

                        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                                declaredByMetadataId, Modifier.PUBLIC,
                                method.getMethodName(),
                                JavaType.VOID_PRIMITIVE, bodyBuilder);
                        methodBuilder.setAnnotations(methodAnnotations);
                        methods.add(methodBuilder);
                    }
                }
            }
        }
View Full Code Here

            parameterNames.add(new JavaSymbolName(fieldName));
            final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
            bodyBuilder.append("\n\tthis." + fieldName + " = " + fieldName
                    + ";\n");

            MethodMetadataBuilder setSeviceMethod = new MethodMetadataBuilder(
                    callerMID, PUBLIC, setMethodName, JavaType.VOID_PRIMITIVE,
                    AnnotatedJavaType.convertFromJavaTypes(parameterTypes),
                    parameterNames, bodyBuilder);

            cidBuilder.addMethod(setSeviceMethod);
View Full Code Here

        }
        builder.append(".isEquals();");

        bodyBuilder.appendFormalLine(builder.toString());

        return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
                EQUALS_METHOD_NAME, BOOLEAN_PRIMITIVE,
                AnnotatedJavaType.convertFromJavaTypes(parameterType),
                parameterNames, bodyBuilder);
    }
View Full Code Here

TOP

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

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.