Search in sources :

Example 16 with FieldMetadataBuilder

use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.

the class WsClientsMetadata method getEndPointField.

/**
 * This method provides the related field for the provided endPoint
 *
 * @param endPoint to obtain the related field
 *
 * @return FieldMetadataBuilder that contains all information about the field
 */
public FieldMetadataBuilder getEndPointField(WsClientEndpoint endPoint) {
    // prevent to generate it again
    if (endPointFields.get(endPoint.getName()) != null) {
        return endPointFields.get(endPoint.getName());
    }
    // Calculate the field name
    JavaSymbolName fieldName = new JavaSymbolName(StringUtils.uncapitalize(endPoint.getName()).concat("Url"));
    // Create the field
    FieldMetadataBuilder endPointField = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, fieldName, JavaType.STRING, null);
    // Include @Value annotation
    AnnotationMetadataBuilder valueAnnotation = new AnnotationMetadataBuilder(SpringJavaType.VALUE);
    valueAnnotation.addStringAttribute("value", String.format("${url/%s}", endPoint.getName()));
    endPointField.addAnnotation(valueAnnotation);
    // Cache generated fields
    endPointFields.put(endPoint.getName(), endPointField);
    return endPointField;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 17 with FieldMetadataBuilder

use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.

the class WsEndpointsMetadata method getLoggerField.

/**
 * This method obtains the LOGGER field
 *
 * @return FieldMetadataBuilder that contians information about
 * the LOGGER field
 */
public FieldMetadata getLoggerField() {
    if (loggerField != null) {
        return loggerField;
    }
    // Create the field
    FieldMetadataBuilder loggger = new FieldMetadataBuilder(getId(), Modifier.PRIVATE + Modifier.STATIC + Modifier.FINAL, new JavaSymbolName("LOGGER"), new JavaType("org.slf4j.Logger"), String.format("%s.getLogger(%s.class)", getNameOfJavaType(new JavaType("org.slf4j.LoggerFactory")), getNameOfJavaType(this.governor)));
    this.loggerField = loggger.build();
    return loggerField;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 18 with FieldMetadataBuilder

use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.

the class WsEndpointsMetadata method getServletField.

/**
 * This method obtains the servlet field that will be used in some different methods
 *
 * @return FieldMetadata that contains all the necessary information
 * about the servlet field
 */
private FieldMetadata getServletField() {
    // Check if already exists
    if (this.servletField != null) {
        return this.servletField;
    }
    // Create the field
    FieldMetadataBuilder servlet = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new JavaSymbolName("cxfServletPath"), JavaType.STRING, null);
    AnnotationMetadataBuilder valueAnnotation = new AnnotationMetadataBuilder(SpringJavaType.VALUE);
    valueAnnotation.addStringAttribute("value", "${cxf.path}");
    servlet.addAnnotation(valueAnnotation);
    servletField = servlet.build();
    return servletField;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 19 with FieldMetadataBuilder

use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.

the class WsEndpointsMetadata method getBusField.

/**
 * This method obtains the bus field that will be used in some different methods
 *
 * @return FieldMetadata that contains all the necessary information
 * about the bus field
 */
private FieldMetadata getBusField() {
    // Check if already exists
    if (this.busField != null) {
        return this.busField;
    }
    // Create the field
    FieldMetadataBuilder bus = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new JavaSymbolName("bus"), new JavaType("org.apache.cxf.Bus"), null);
    bus.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
    busField = bus.build();
    return busField;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 20 with FieldMetadataBuilder

use of org.springframework.roo.classpath.details.FieldMetadataBuilder in project spring-roo by spring-projects.

the class UpdateCompilationUnitTest method testSimpleClassAddField.

@Test
public void testSimpleClassAddField() throws Exception {
    // Set up
    final File file = getResource(SIMPLE_CLASS_FILE_PATH);
    final String fileContents = getResourceContents(file);
    final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
    final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(SIMPLE_CLASS_DECLARED_BY_MID, Modifier.PRIVATE, new JavaSymbolName("newFieldAddedByCode"), new JavaType(String.class), "\"Create by code\"");
    final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addField(simpleInterfaceDetails, fieldBuilder.build());
    // Invoke
    final String result = typeParsingService.getCompilationUnitContents(newSimpleInterfaceDetails);
    // save to file for debug
    saveResult(file, result, "-addedField");
    checkSimpleClass(result);
    assertTrue(result.contains("private String newFieldAddedByCode = \"Create by code\";"));
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) File(java.io.File) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) Test(org.junit.Test)

Aggregations

FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)66 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)48 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)40 ArrayList (java.util.ArrayList)21 JavaType (org.springframework.roo.model.JavaType)19 JdkJavaType (org.springframework.roo.model.JdkJavaType)10 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)8 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)7 FieldDetails (org.springframework.roo.classpath.details.FieldDetails)7 ForeignKey (org.springframework.roo.addon.dbre.addon.model.ForeignKey)5 CommentStructure (org.springframework.roo.classpath.details.comments.CommentStructure)5 JavadocComment (org.springframework.roo.classpath.details.comments.JavadocComment)5 LinkedHashMap (java.util.LinkedHashMap)4 Reference (org.springframework.roo.addon.dbre.addon.model.Reference)4 Table (org.springframework.roo.addon.dbre.addon.model.Table)4 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)4 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)4 CollectionField (org.springframework.roo.classpath.operations.jsr303.CollectionField)4 DateField (org.springframework.roo.classpath.operations.jsr303.DateField)4 EnumDetails (org.springframework.roo.model.EnumDetails)4