use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class JpaUnitTestMetadata method getCleanMethod.
/**
* Obtains a method annotated with @After for doing the test class teardown phase
* after finishing each test.
*
* @return {@link MethodMetadataBuilder}
*/
private MethodMetadataBuilder getCleanMethod() {
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("// Clean needed after executing each test method");
bodyBuilder.appendFormalLine("// To be implemented by developer");
bodyBuilder.newLine();
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("clean"), JavaType.VOID_PRIMITIVE, bodyBuilder);
// Add @After
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(AFTER).build());
// Add comment
CommentStructure comment = new CommentStructure();
JavadocComment javaDocComment = new JavadocComment("This method will be automatically executed after each test method for freeing resources allocated with @Before annotated method.");
comment.addComment(javaDocComment, CommentLocation.BEGINNING);
methodBuilder.setCommentStructure(comment);
return methodBuilder;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class JmsOperationsImpl method createReceiverJmsService.
private void createReceiverJmsService(JavaType service, String destinationProperty) {
// Create new service class
final String serviceClassIdentifier = getPathResolver().getCanonicalPath(service.getModule(), Path.SRC_MAIN_JAVA, service);
final String mid = PhysicalTypeIdentifier.createIdentifier(service, getPathResolver().getPath(serviceClassIdentifier));
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, Modifier.PUBLIC, service, PhysicalTypeCategory.CLASS);
// Create new @Service annotation
AnnotationMetadataBuilder serviceAnnotation = new AnnotationMetadataBuilder(SpringJavaType.SERVICE);
cidBuilder.addAnnotation(serviceAnnotation);
// Add method receiveJmsMessage
// @JmsListener(destination =
// "${application.jms.queue.plaintext.jndi-name}")
// public void receiveJmsMessage(String msg) {
//
// }
// Define methodName
final JavaSymbolName methodName = new JavaSymbolName("receiveJmsMessage");
// Define parameters
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(new AnnotatedJavaType(JavaType.STRING));
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("msg"));
// Adding annotations
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Adding @JmsListener annotation
AnnotationMetadataBuilder jmsListenerAnnotation = new AnnotationMetadataBuilder(SpringJavaType.JMS_LISTENER);
jmsListenerAnnotation.addStringAttribute("destination", "${".concat(destinationProperty).concat("}"));
annotations.add(jmsListenerAnnotation);
// Generate body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.newLine();
bodyBuilder.appendFormalLine(" // To be implemented");
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(mid, Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
methodBuilder.setAnnotations(annotations);
cidBuilder.addMethod(methodBuilder);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class EntityDeserializerMetadata method getConstructor.
public static ConstructorMetadata getConstructor(String declaredByMetadataId, FieldMetadata serviceField, FieldMetadata conversionServiceField) {
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Generating constructor
ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(declaredByMetadataId);
constructor.setModifier(Modifier.PUBLIC);
constructor.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
// add Service to constructor
String serviceFieldName = serviceField.getFieldName().getSymbolName();
AnnotatedJavaType serviceParameter = new AnnotatedJavaType(serviceField.getFieldType(), new AnnotationMetadataBuilder(SpringJavaType.LAZY).build());
constructor.addParameterName(serviceField.getFieldName());
constructor.addParameterType(serviceParameter);
// Generating body
bodyBuilder.appendFormalLine("this.%1$s = %1$s;", serviceFieldName);
// add Conversion service to constructor
String conversionServiceFieldName = conversionServiceField.getFieldName().getSymbolName();
constructor.addParameter(conversionServiceFieldName, conversionServiceField.getFieldType());
// Generating body
bodyBuilder.appendFormalLine("this.%1$s = %1$s;", conversionServiceFieldName);
// Adding body
constructor.setBodyBuilder(bodyBuilder);
return constructor.build();
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class SeiImplMetadata method getEndpointMethodFromSEIMethod.
/**
* This method obtains an Endpoint method from a provided SEI method.
*
* This method caches the generated methods
*
* @param seiMethod defined in a SEI interface
* @param serviceMethod where this enpoint should delegate
*
* @return MethodMetadataBuilder that contains all the information about the new Endpoint method.
*/
private MethodMetadataBuilder getEndpointMethodFromSEIMethod(MethodMetadata seiMethod, MethodMetadata serviceMethod) {
// Check if already exists the method
if (endpointMethodsFromSeiMethods.get(seiMethod) != null) {
return endpointMethodsFromSeiMethods.get(seiMethod);
}
// If not exists, generate it and cache it.
// First of all, obtain the SEI method parameters and remove the @WebParam annotation from them.
// Is not necessary in the endpoint because is already defined in the SEI
List<JavaType> parameters = new ArrayList<JavaType>();
for (AnnotatedJavaType type : seiMethod.getParameterTypes()) {
parameters.add(type.getJavaType());
}
// Create the new endpoint method wind the updated information
MethodMetadataBuilder endpointMethod = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, seiMethod.getMethodName(), seiMethod.getReturnType(), AnnotatedJavaType.convertFromJavaTypes(parameters), seiMethod.getParameterNames(), null);
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Getting parameters
String parametersList = "";
for (JavaSymbolName param : seiMethod.getParameterNames()) {
parametersList = parametersList.concat(param.getSymbolName()).concat(", ");
}
if (StringUtils.isNotBlank(parametersList)) {
parametersList = parametersList.substring(0, parametersList.length() - 2);
}
bodyBuilder.appendFormalLine("%s%s().%s(%s);", seiMethod.getReturnType() != JavaType.VOID_PRIMITIVE ? "return " : "", getAccessorMethod(getServiceField()).getMethodName(), serviceMethod.getMethodName().getSymbolName(), parametersList);
endpointMethod.setBodyBuilder(bodyBuilder);
endpointMethodsFromSeiMethods.put(seiMethod, endpointMethod);
endpointMethods.add(endpointMethod.build());
return endpointMethod;
}
use of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder in project spring-roo by spring-projects.
the class WsClientsMetadata method getEndpointMethod.
/**
* This method provides the related method for the provided endPoint
*
* @param endPoint to obtain the related method
*
* @return MethodMetadataBuilder that contains all information about the method
*/
public MethodMetadataBuilder getEndpointMethod(WsClientEndpoint endPoint) {
// prevent to generate it again
if (endPointMethods.get(endPoint.getName()) != null) {
return endPointMethods.get(endPoint.getName());
}
// If not, obtain necessary info about the provided enpoint
String targetNameSpace = endPoint.getTargetNameSpace();
Validate.notEmpty(targetNameSpace, "ERROR: Provided endpoint has not been registered inside @RooWsClients annotation");
// Creating valid endpoint JavaType
JavaType endPointType = new JavaType(String.format("%s.%s", getPackageNameFromTargetNameSpace(targetNameSpace), StringUtils.capitalize(endPoint.getName())));
// Getting method name
JavaSymbolName methodName = new JavaSymbolName(StringUtils.uncapitalize(endPoint.getName()));
// Generating method body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
bodyBuilder.appendFormalLine("%s jaxWsFactory = new JaxWsProxyFactoryBean();", getNameOfJavaType(new JavaType("org.apache.cxf.jaxws.JaxWsProxyFactoryBean")));
// jaxWsFactory.setServiceClass(ENDPOINT.class);
bodyBuilder.appendFormalLine("jaxWsFactory.setServiceClass(%s.class);", getNameOfJavaType(endPointType));
// jaxWsFactory.setAddress(this.ENDPOINTFIELD);
bodyBuilder.appendFormalLine("jaxWsFactory.setAddress(this.%s);", getEndPointField(endPoint).getFieldName());
// Check bindingType. If is SOAP 1.2, is necessary to generate some extra code
if (endPoint.getBindingType().getField().getSymbolName().equals(SoapBindingType.SOAP12.name())) {
// jaxWsFactory.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);
bodyBuilder.appendFormalLine("jaxWsFactory.setBindingId(%s.SOAP12HTTP_BINDING);", getNameOfJavaType(new JavaType("javax.xml.ws.soap.SOAPBinding")));
// jaxWsFactory.setTransportId(SoapTransportFactory.SOAP_12_HTTP_BINDING);
bodyBuilder.appendFormalLine("jaxWsFactory.setTransportId(%s.SOAP_12_HTTP_BINDING);", getNameOfJavaType(new JavaType("org.apache.cxf.binding.soap.SoapTransportFactory")));
}
// jaxWsFactory.setFeatures(Arrays.asList(new TraceeCxfFeature(), new LoggingFeature()));
bodyBuilder.appendFormalLine("jaxWsFactory.setFeatures(%s.asList(new %s(), new %s()));", getNameOfJavaType(JavaType.ARRAYS), getNameOfJavaType(new JavaType("io.tracee.binding.cxf.TraceeCxfFeature")), getNameOfJavaType(new JavaType("org.apache.cxf.feature.LoggingFeature")));
// LOGGER.info("Web Service client ENDPOINTFIELD has been created. URL: '{}'", this.ENDPOINTFIELD);
bodyBuilder.appendFormalLine("%s.info(\"Web Service client %s has been created. URL: '{}'\", this.%s);", getLoggerField().getFieldName(), getEndPointField(endPoint).getFieldName().getSymbolNameCapitalisedFirstLetter(), getEndPointField(endPoint).getFieldName());
// return (ENDPOINT) jaxWsFactory.create();
bodyBuilder.appendFormalLine("return (%s) jaxWsFactory.create();", getNameOfJavaType(endPointType));
// Generate new method related with the provided endpoint
MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, endPointType, bodyBuilder);
method.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
// Cache generated methods
endPointMethods.put(endPoint.getName(), method);
return method;
}
Aggregations