Search in sources :

Example 46 with JavaSymbolName

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

Example 47 with JavaSymbolName

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

Example 48 with JavaSymbolName

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

Example 49 with JavaSymbolName

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

Example 50 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName 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;
}
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

JavaSymbolName (org.springframework.roo.model.JavaSymbolName)317 ArrayList (java.util.ArrayList)186 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)155 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)143 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)142 JavaType (org.springframework.roo.model.JavaType)133 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)121 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)119 SpringJavaType (org.springframework.roo.model.SpringJavaType)61 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)59 JdkJavaType (org.springframework.roo.model.JdkJavaType)59 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)48 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)47 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)45 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)39 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)36 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)29 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)29 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)27 EnumDetails (org.springframework.roo.model.EnumDetails)25