use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class SeiImplMetadata method getConstructor.
/**
* This method obtains the constructor method of the annotated endpoint
*
* @return constructor method for this endpoint
*/
private ConstructorMetadata getConstructor() {
// Check if constructor has been generated before
if (constructor != null) {
return constructor;
}
// Creating new constructor
ConstructorMetadataBuilder constructorMethod = new ConstructorMetadataBuilder(getId());
constructorMethod.setModifier(Modifier.PUBLIC);
constructorMethod.addParameter(getServiceField().getFieldName().getSymbolNameUnCapitalisedFirstLetter(), getServiceField().getFieldType());
// Generating constructor body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("%s(%s);", getMutatorMethod(getServiceField()).getMethodName(), getServiceField().getFieldName().getSymbolNameUnCapitalisedFirstLetter());
constructorMethod.setBodyBuilder(bodyBuilder);
constructor = constructorMethod.build();
return constructor;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class JaxbEntityMetadata method getXmlIdentityInfoMethod.
/**
* This method returns the getXmlIdentityInfo() method.
*
* @return MethodMetadata that contains the getXmlIdentityInfoMethod
*/
public MethodMetadata getXmlIdentityInfoMethod() {
// Check if already exists
if (xmlIdentityInfoMethod != null) {
return xmlIdentityInfoMethod;
}
// If not, generate a new one
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// return getClass().getName() + ":" + getId();
bodyBuilder.appendFormalLine(String.format("return getClass().getName() + \":\" + %s();", identifierAccessor.getMethodName()));
MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("getXmlIdentityInfo"), JavaType.STRING, bodyBuilder);
method.addAnnotation(new AnnotationMetadataBuilder(JavaType.XML_ID));
AnnotationMetadataBuilder xmlAttributeAnnotation = new AnnotationMetadataBuilder(JavaType.XML_ATTRIBUTE);
xmlAttributeAnnotation.addStringAttribute("name", "id");
method.addAnnotation(xmlAttributeAnnotation);
CommentStructure comment = new CommentStructure();
comment.addComment(new JavadocComment("Must return an unique ID across all entities"), CommentLocation.BEGINNING);
method.setCommentStructure(comment);
xmlIdentityInfoMethod = method.build();
return xmlIdentityInfoMethod;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class WsEndpointsMetadata method getOpenEntityManagerInViewFilterMethod.
/**
* This method obtains the method that register the openEntityManagerInView
* filter
*
* @return MethodMetadata with the information about the new method
*/
private MethodMetadata getOpenEntityManagerInViewFilterMethod() {
// Check if already exists
if (openEntityManagerInViewFilterMethod != null) {
return openEntityManagerInViewFilterMethod;
}
JavaType filterRegistrationBeanType = new JavaType("org.springframework.boot.context.embedded.FilterRegistrationBean");
// Generating method body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
bodyBuilder.appendFormalLine("%s filterRegBean = new FilterRegistrationBean();", getNameOfJavaType(filterRegistrationBeanType));
// filterRegBean.setFilter(new OpenEntityManagerInViewFilter());
bodyBuilder.appendFormalLine("filterRegBean.setFilter(new %s());", getNameOfJavaType(new JavaType("org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter")));
// List<String> urlPatterns = new ArrayList<String>();
bodyBuilder.appendFormalLine("%s<String> urlPatterns = new %s<String>();", getNameOfJavaType(JavaType.LIST), getNameOfJavaType(JavaType.ARRAY_LIST));
// urlPatterns.add(this.cxfServletPath + "/*");
bodyBuilder.appendFormalLine("urlPatterns.add(%s() + \"/*\");", getAccessorMethod(getServletField()).getMethodName());
// filterRegBean.setUrlPatterns(urlPatterns);
bodyBuilder.appendFormalLine("filterRegBean.setUrlPatterns(urlPatterns);");
// if (LOG.isDebugEnabled()) {
bodyBuilder.appendFormalLine("if (%s().isDebugEnabled()) {", getAccessorMethod(getLoggerField()).getMethodName());
// LOG.debug("Registering the 'OpenEntityManagerInViewFilter' filter for the '"
bodyBuilder.indent();
bodyBuilder.appendFormalLine("%s().debug(\"Registering the 'OpenEntityManagerInViewFilter' filter for the '\"", getAccessorMethod(getLoggerField()).getMethodName());
// .concat(this.cxfServletPath + "/*").concat("' URL."));
bodyBuilder.indent();
bodyBuilder.appendFormalLine(".concat(%s() + \"/*\").concat(\"' URL.\"));", getAccessorMethod(getServletField()).getMethodName());
bodyBuilder.indentRemove();
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
// return filterRegBean;
bodyBuilder.appendFormalLine("return filterRegBean;");
MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("openEntityManagerInViewFilter"), filterRegistrationBeanType, bodyBuilder);
method.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
openEntityManagerInViewFilterMethod = method.build();
return openEntityManagerInViewFilterMethod;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class JspOperationsImpl method getIndexMethod.
private MethodMetadataBuilder getIndexMethod(final String folderName, final String declaredByMetadataId) {
final List<AnnotationMetadataBuilder> indexMethodAnnotations = new ArrayList<AnnotationMetadataBuilder>();
indexMethodAnnotations.add(new AnnotationMetadataBuilder(REQUEST_MAPPING, new ArrayList<AnnotationAttributeValue<?>>()));
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return \"" + folderName + "/index\";");
final MethodMetadataBuilder indexMethodBuilder = new MethodMetadataBuilder(declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName("index"), JavaType.STRING, new ArrayList<AnnotatedJavaType>(), new ArrayList<JavaSymbolName>(), bodyBuilder);
indexMethodBuilder.setAnnotations(indexMethodAnnotations);
return indexMethodBuilder;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class LinkFactoryMetadata method getToUriMethod.
/**
* Generates a `toUri` method which generates URI's for the *Collection*
* controller methods which are called from views.
*
* @param finderName
* @param serviceFinderMethod
* @return
*/
private MethodMetadata getToUriMethod() {
// Define methodName
final JavaSymbolName toUriMethodName = TO_URI_METHOD_NAME;
// Define method argument types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(stringArgument);
parameterTypes.add(objectArrayArgument);
parameterTypes.add(mapStringObjectArgument);
// Return method if already exists
MethodMetadata existingMethod = getGovernorMethod(toUriMethodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Define method argument names
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(METHOD_NAME_ARGUMENT_NAME);
parameterNames.add(PARAMETERS_ARGUMENT_NAME);
parameterNames.add(PATH_VARIABLES_ARGUMENT_NAME);
// Generate body
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Include a conditional for every method
for (MethodMetadata method : this.controllerMethods) {
// Getting methodName
String methodName = method.getMethodName().getSymbolName();
// Getting methodParams
List<String> methodParamsToNull = new ArrayList<String>();
for (AnnotatedJavaType paramType : method.getParameterTypes()) {
JavaType javaType = paramType.getJavaType();
if (javaType.isPrimitive() && !javaType.isArray()) {
if (JavaType.BOOLEAN_PRIMITIVE.equals(javaType)) {
methodParamsToNull.add("false");
} else if (JavaType.INT_PRIMITIVE.equals(javaType)) {
methodParamsToNull.add("0");
} else if (JavaType.LONG_PRIMITIVE.equals(javaType)) {
methodParamsToNull.add("0l");
} else if (JavaType.FLOAT_PRIMITIVE.equals(javaType)) {
methodParamsToNull.add("0.0f");
} else if (JavaType.DOUBLE_PRIMITIVE.equals(javaType)) {
methodParamsToNull.add("0.0");
}
} else {
// Include a null declaration for every parameter
methodParamsToNull.add("null");
}
}
// if (METHOD_NAME_ARGUMENT_NAME.equals(methodNameConstant)) {
bodyBuilder.appendFormalLine("if (%s.equals(%s)) {", METHOD_NAME_ARGUMENT_NAME, getConstantForMethodName(methodName).getFieldName());
bodyBuilder.indent();
// return MvcUriComponentsBuilder.fromMethodCall(MvcUriComponentsBuilder.on(getControllerClass()).list(null)).build();
bodyBuilder.appendFormalLine("return %1$s.fromMethodCall(%1$s.on(%2$s()).%3$s(%4$s)).buildAndExpand(%5$s);", getNameOfJavaType(SpringletsJavaType.SPRINGLETS_MVC_URI_COMPONENTS_BUILDER), this.getControllerClassMethod.getMethodName(), methodName, StringUtils.join(methodParamsToNull, ", "), PATH_VARIABLES_ARGUMENT_NAME);
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
}
// throw new IllegalArgumentException("Invalid method name: " + METHOD_NAME_ARGUMENT_NAME);
bodyBuilder.appendFormalLine("throw new IllegalArgumentException(\"Invalid method name: \" + %s);", METHOD_NAME_ARGUMENT_NAME);
// Build method builder
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, toUriMethodName, SpringJavaType.URI_COMPONENTS, parameterTypes, parameterNames, bodyBuilder);
return methodBuilder.build();
}
Aggregations