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;
}
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;
}
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;
}
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;
}
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\";"));
}
Aggregations