use of org.springframework.roo.classpath.details.ConstructorMetadataBuilder in project spring-roo by spring-projects.
the class ThymeleafMetadata method getConstructor.
private ConstructorMetadata getConstructor(String itemLinkBuilderLine, String collectionLinkBuilderLine, boolean autowired) {
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Generating constructor
ConstructorMetadataBuilder newConstructor = new ConstructorMetadataBuilder(getId());
newConstructor.setModifier(Modifier.PUBLIC);
if (autowired) {
newConstructor.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
}
// Getting serviceFieldName
String serviceFieldName = controllerMetadata.getServiceField().getFieldName().getSymbolName();
newConstructor.addParameter(serviceFieldName, controllerMetadata.getService());
bodyBuilder.appendFormalLine(String.format("%s(%s);", getMutatorMethod(controllerMetadata.getServiceField()).getMethodName(), serviceFieldName));
if (this.type == ControllerType.DETAIL || this.type == ControllerType.DETAIL_ITEM) {
for (FieldMetadata serviceField : controllerMetadata.getDetailsServiceFields().values()) {
// Getting parentServiceFieldName
String childServiceFieldName = serviceField.getFieldName().getSymbolName();
// Adding parameters
newConstructor.addParameter(childServiceFieldName, serviceField.getFieldType());
// Generating body
bodyBuilder.appendFormalLine(String.format("%s(%s);", getMutatorMethod(serviceField).getMethodName(), childServiceFieldName));
}
}
// field
if (this.type == ControllerType.COLLECTION || this.type == ControllerType.DETAIL || this.type == ControllerType.SEARCH) {
String conversionServiceFieldName = this.conversionServiceField.getFieldName().getSymbolName();
newConstructor.addParameter(conversionServiceFieldName, this.conversionServiceField.getFieldType());
bodyBuilder.appendFormalLine("%s(%s);", getMutatorMethod(this.getConversionServiceField()).getMethodName(), conversionServiceFieldName);
}
String messageSourceName = this.messageSourceField.getFieldName().getSymbolName();
newConstructor.addParameter(messageSourceName, messageSourceField.getFieldType());
bodyBuilder.appendFormalLine("%s(%s);", getMutatorMethod(this.messageSourceField).getMethodName(), messageSourceName);
// Add ControllerMethodLinkBuilderFactory argument
if (StringUtils.isNotBlank(itemLinkBuilderLine) || StringUtils.isNotBlank(collectionLinkBuilderLine)) {
newConstructor.addParameter(LINK_BUILDER_ARGUMENT_NAME, SpringletsJavaType.SPRINGLETS_CONTROLLER_METHOD_LINK_BUILDER_FACTORY);
this.builder.getImportRegistrationResolver().addImport(SpringletsJavaType.SPRINGLETS_CONTROLLER_METHOD_LINK_BUILDER_FACTORY);
if (StringUtils.isNotBlank(itemLinkBuilderLine)) {
bodyBuilder.appendFormalLine(itemLinkBuilderLine);
}
if (StringUtils.isNotBlank(collectionLinkBuilderLine)) {
bodyBuilder.appendFormalLine(collectionLinkBuilderLine);
}
}
// Adding body
newConstructor.setBodyBuilder(bodyBuilder);
return newConstructor.build();
}
Aggregations