Search in sources :

Example 86 with MethodMetadataBuilder

use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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());
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 87 with MethodMetadataBuilder

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

the class JavaParserMethodMetadataBuilder method build.

@Override
public MethodMetadata build() {
    final MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder(declaredByMetadataId);
    methodMetadataBuilder.setMethodName(methodName);
    methodMetadataBuilder.setReturnType(returnType);
    methodMetadataBuilder.setAnnotations(annotations);
    methodMetadataBuilder.setBodyBuilder(InvocableMemberBodyBuilder.getInstance().append(body));
    methodMetadataBuilder.setModifier(modifier);
    methodMetadataBuilder.setParameterNames(parameterNames);
    methodMetadataBuilder.setParameterTypes(parameterTypes);
    methodMetadataBuilder.setThrowsTypes(throwsTypes);
    return methodMetadataBuilder.build();
}
Also used : MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder)

Example 88 with MethodMetadataBuilder

use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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;
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 89 with MethodMetadataBuilder

use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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;
}
Also used : SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 90 with MethodMetadataBuilder

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

the class WsEndpointsMetadata method getEndpointMethod.

/**
 * This method obtains the method that will be used to registered the endpoint
 *
 * @param endpoint JavaType with the information about the related endpoint to
 * be registered
 *
 * @return MethodMetadata with the necessary information about the new method
 */
private MethodMetadata getEndpointMethod(JavaType endpoint) {
    // Check if already exists
    if (endpointMethods.get(endpoint) != null) {
        return endpointMethods.get(endpoint);
    }
    // Generating method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // EndpointImpl endpoint = new EndpointImpl(this.bus, new ENDPOINT(this.SERVICENAME));
    bodyBuilder.appendFormalLine("%s endpoint = new EndpointImpl(%s(), new %s(%s()));", getNameOfJavaType(new JavaType("org.apache.cxf.jaxws.EndpointImpl")), getAccessorMethod(getBusField()).getMethodName(), getNameOfJavaType(endpoint), getAccessorMethod(getServiceField(getServiceFromEndpoint(endpoint))).getMethodName());
    // endpoint.setFeatures(Arrays.asList(new TraceeCxfFeature(), new LoggingFeature()));
    bodyBuilder.appendFormalLine("endpoint.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")));
    // endpoint.publish("/SEI");
    bodyBuilder.appendFormalLine("endpoint.publish(\"/%s\");", getSeiFromEndpoint(endpoint).getSimpleTypeName());
    // return endpoint;
    bodyBuilder.appendFormalLine("return endpoint;");
    MethodMetadataBuilder endpointMethod = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName(StringUtils.uncapitalize(endpoint.getSimpleTypeName())), JavaType.ENDPOINT, bodyBuilder);
    endpointMethod.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
    endpointMethods.put(endpoint, endpointMethod.build());
    return endpointMethod.build();
}
Also used : SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)155 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)143 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)120 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)117 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)115 ArrayList (java.util.ArrayList)110 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)87 JavaType (org.springframework.roo.model.JavaType)65 SpringJavaType (org.springframework.roo.model.SpringJavaType)48 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)43 JdkJavaType (org.springframework.roo.model.JdkJavaType)34 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)30 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)27 ServiceMetadata (org.springframework.roo.addon.layers.service.addon.ServiceMetadata)15 CommentStructure (org.springframework.roo.classpath.details.comments.CommentStructure)14 JavadocComment (org.springframework.roo.classpath.details.comments.JavadocComment)14 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)12 RelationInfoExtended (org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended)11 JpaJavaType (org.springframework.roo.model.JpaJavaType)9 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)7