Package org.springframework.roo.classpath.itd

Examples of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder


    final JavaType converterJavaType = SpringJavaType.getConverterType(
        targetType, JavaType.STRING);
    final String targetTypeName = StringUtils.uncapitalize(targetType
        .getSimpleTypeName());

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("return new "
        + converterJavaType.getNameIncludingTypeParameters() + "() {");
    bodyBuilder.indent();
    bodyBuilder
        .appendFormalLine("public String convert("
            + targetType.getSimpleTypeName() + " " + targetTypeName
            + ") {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine(getTypeToStringLine(targetType,
        targetTypeName, toStringMethods));
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("};");

    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
        converterJavaType, bodyBuilder);
  }
View Full Code Here


    private String getMinAndMaxBody(final FieldMetadata field,
            final String suffix) {
        final String fieldName = field.getFieldName().getSymbolName();
        final JavaType fieldType = field.getFieldType();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        final AnnotationMetadata minAnnotation = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), MIN);
        final AnnotationMetadata maxAnnotation = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), MAX);
        if (minAnnotation != null && maxAnnotation == null) {
            final Number minValue = (Number) minAnnotation.getAttribute(VALUE)
                    .getValue();

            if (fieldType.equals(BIG_INTEGER)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + minValue + "\")) == -1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_INTEGER.getSimpleTypeName() + "(\"" + minValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " < "
                        + minValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + minValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (minAnnotation == null && maxAnnotation != null) {
            final Number maxValue = (Number) maxAnnotation.getAttribute(VALUE)
                    .getValue();

            if (fieldType.equals(BIG_INTEGER)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + maxValue + "\")) == 1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_INTEGER.getSimpleTypeName() + "(\"" + maxValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " > "
                        + maxValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + maxValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }
        else if (minAnnotation != null && maxAnnotation != null) {
            final Number minValue = (Number) minAnnotation.getAttribute(VALUE)
                    .getValue();
            final Number maxValue = (Number) maxAnnotation.getAttribute(VALUE)
                    .getValue();
            Validate.isTrue(
                    maxValue.longValue() >= minValue.longValue(),
                    "The value of @Max must be greater or equal to the value of @Min for field %s",
                    fieldName);

            if (fieldType.equals(BIG_INTEGER)) {
                bodyBuilder.appendFormalLine("if (" + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + minValue + "\")) == -1 || " + fieldName
                        + ".compareTo(new " + BIG_INTEGER.getSimpleTypeName()
                        + "(\"" + maxValue + "\")) == 1) {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = new "
                        + BIG_INTEGER.getSimpleTypeName() + "(\"" + maxValue
                        + "\");");
            }
            else {
                bodyBuilder.appendFormalLine("if (" + fieldName + " < "
                        + minValue + suffix + " || " + fieldName + " > "
                        + maxValue + suffix + ") {");
                bodyBuilder.indent();
                bodyBuilder.appendFormalLine(fieldName + " = " + maxValue
                        + suffix + ";");
            }

            bodyBuilder.indentRemove();
            bodyBuilder.appendFormalLine("}");
        }

        return bodyBuilder.getOutput();
    }
View Full Code Here

    annotations.add(new AnnotationMetadataBuilder(REQUEST_MAPPING,
        requestMappingAttributes));

    final String plural = javaTypeMetadataHolder.getPlural().toLowerCase();

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("if (page != null || size != null) {");
    bodyBuilder.indent();
    bodyBuilder
        .appendFormalLine("int sizeNo = size == null ? 10 : size.intValue();");
    bodyBuilder
        .appendFormalLine("final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;");
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\"" + plural
        + "\", " + findEntriesAdditions.getMethodCall() + ");");
    bodyBuilder.appendFormalLine("float nrOfPages = (float) "
        + countAllAdditions.getMethodCall() + " / sizeNo;");
    bodyBuilder
        .appendFormalLine("uiModel.addAttribute(\"maxPages\", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("} else {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\"" + plural
        + "\", " + findAllAdditions.getMethodCall() + ");");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    if (!dateTypes.isEmpty()) {
      bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);");
    }
    bodyBuilder.appendFormalLine("return \"" + controllerPath + "/list\";");

    final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
        getId(), Modifier.PUBLIC, methodName, STRING, parameterTypes,
        parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
View Full Code Here

    final List<JavaSymbolName> parameterNames = Arrays.asList(
        new JavaSymbolName("uiModel"), new JavaSymbolName(entityName));
    if (governorHasMethod(methodName, parameterTypes)) {
      return null;
    }
    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\"" + entityName
        + "\", " + entityName + ");");
    if (!dateTypes.isEmpty()) {
      bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);");
    }
    if (annotationValues.isPopulateMethods()) {
      for (final JavaTypeMetadataDetails domainType : specialDomainTypes) {
        if (editableFieldTypes.contains(domainType.getJavaType())) {
          final JavaTypePersistenceMetadataDetails persistenceDetails = domainType
              .getPersistenceDetails();
          final String modelAttribute = domainType.getPlural()
              .toLowerCase();
          if (persistenceDetails != null
              && persistenceDetails.getFindAllMethod() != null) {
            bodyBuilder.appendFormalLine("uiModel.addAttribute(\""
                + modelAttribute
                + "\", "
                + persistenceDetails.getFindAllMethod()
                    .getMethodCall() + ");");
            persistenceDetails.getFindAllMethod().copyAdditionsTo(
                builder, governorTypeDetails);
          } else if (domainType.isEnumType()) {
            bodyBuilder.appendFormalLine("uiModel.addAttribute(\""
                + modelAttribute + "\", "
                + getShortName(ARRAYS) + ".asList("
                + getShortName(domainType.getJavaType())
                + ".values())" + ");");
          }
View Full Code Here

    final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
        REQUEST_MAPPING, requestMappingAttributes);
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(requestMapping);

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    if (!dateTypes.isEmpty()) {
      bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);");
    }
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\""
        + entityName.toLowerCase() + "\", "
        + findMethod.getMethodCall() + ");");
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\"itemId\", "
        + (compositePk ? "conversionService.convert(" : "")
        + idFieldName + (compositePk ? ", String.class)" : "") + ");");
    bodyBuilder.appendFormalLine("return \"" + controllerPath + "/show\";");

    final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
        getId(), Modifier.PUBLIC, methodName, STRING, parameterTypes,
        parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
View Full Code Here

    final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
        REQUEST_MAPPING, requestMappingAttributes);
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(requestMapping);

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("populateEditForm(uiModel, "
        + findMethod.getMethodCall() + ");");
    bodyBuilder.appendFormalLine("return \"" + controllerPath
        + "/update\";");

    final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
        getId(), Modifier.PUBLIC, methodName, STRING, parameterTypes,
        parameterNames, bodyBuilder);
View Full Code Here

            modifyMethod = userMethod;
            return;
        }

        // Create method
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("return false;");

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC, methodName, returnType,
                AnnotatedJavaType.convertFromJavaTypes(parameterType),
                parameterNames, bodyBuilder);
View Full Code Here

    final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
        REQUEST_MAPPING, requestMappingAttributes);
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(requestMapping);

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("if (bindingResult.hasErrors()) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("populateEditForm(uiModel, " + entityName
        + ");");
    bodyBuilder.appendFormalLine("return \"" + controllerPath
        + "/update\";");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("uiModel.asMap().clear();");
    bodyBuilder.appendFormalLine(updateMethod.getMethodCall() + ";");
    bodyBuilder.appendFormalLine("return \"redirect:/"
        + controllerPath
        + "/\" + encodeUrlPathSegment("
        + (compositePk ? "conversionService.convert(" : "")
        + entityName
        + "."
View Full Code Here

        }

        // Create method
        builder.getImportRegistrationResolver().addImport(entity);

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entity.getSimpleTypeName() + " " + OBJ_VAR
                + " = new " + entity.getSimpleTypeName() + "();");

        // Create the composite key embedded id method call if required
        if (hasEmbeddedIdentifier()) {
            bodyBuilder.appendFormalLine(getEmbeddedIdMutatorMethodName() + "("
                    + OBJ_VAR + ", " + INDEX_VAR + ");");
        }

        // Create a mutator method call for each embedded class
        for (final EmbeddedHolder embeddedHolder : embeddedHolders) {
            bodyBuilder
                    .appendFormalLine(getEmbeddedFieldMutatorMethodName(embeddedHolder
                            .getEmbeddedField().getFieldName())
                            + "("
                            + OBJ_VAR
                            + ", " + INDEX_VAR + ");");
        }

        // Create mutator method calls for each entity field
        for (final FieldMetadata field : fieldInitializers.keySet()) {
            final JavaSymbolName mutatorName = BeanInfoUtils
                    .getMutatorMethodName(field);
            bodyBuilder.appendFormalLine(mutatorName.getSymbolName() + "("
                    + OBJ_VAR + ", " + INDEX_VAR + ");");
        }

        bodyBuilder.appendFormalLine("return " + OBJ_VAR + ";");

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC, methodName, entity,
                AnnotatedJavaType.convertFromJavaTypes(parameterType),
                parameterNames, bodyBuilder);
View Full Code Here

        }

        builder.getImportRegistrationResolver().addImport(identifierType);

        // Create method
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("init();");
        bodyBuilder.appendFormalLine(entity.getSimpleTypeName() + " " + OBJ_VAR
                + " = " + getDataFieldName().getSymbolName() + ".get("
                + getRndFieldName().getSymbolName() + ".nextInt("
                + getDataField().getFieldName().getSymbolName() + ".size()));");
        bodyBuilder.appendFormalLine(identifierType.getSimpleTypeName()
                + " id = " + OBJ_VAR + "."
                + identifierAccessor.getMethodName().getSymbolName() + "();");
        bodyBuilder.appendFormalLine("return " + findMethod.getMethodCall()
                + ";");

        findMethod.copyAdditionsTo(builder, governorTypeDetails);

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder

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.