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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations