use of org.springframework.roo.model.JavaType 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.model.JavaType in project spring-roo by spring-projects.
the class WsEndpointsMetadata method getBusField.
/**
* This method obtains the bus field that will be used in some different methods
*
* @return FieldMetadata that contains all the necessary information
* about the bus field
*/
private FieldMetadata getBusField() {
// Check if already exists
if (this.busField != null) {
return this.busField;
}
// Create the field
FieldMetadataBuilder bus = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, new JavaSymbolName("bus"), new JavaType("org.apache.cxf.Bus"), null);
bus.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
busField = bus.build();
return busField;
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class WsEndpointsMetadataProviderImpl method getLocalMidToRequest.
@Override
protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
// Determine the governor for this ITD, and whether any metadata is even
// hoping to hear about changes to that JavaType and its ITDs
final JavaType governor = itdTypeDetails.getName();
final String localMid = domainTypeToServiceMidMap.get(governor);
if (localMid != null) {
return localMid;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = getTypeLocationService().getTypeDetails(governor);
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = domainTypeToServiceMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
return null;
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class UpdateCompilationUnitTest method testSimpleClassAddField.
@Test
public void testSimpleClassAddField() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID, SIMPLE_CLASS_TYPE);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(SIMPLE_CLASS_DECLARED_BY_MID, Modifier.PRIVATE, new JavaSymbolName("newFieldAddedByCode"), new JavaType(String.class), "\"Create by code\"");
final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addField(simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService.getCompilationUnitContents(newSimpleInterfaceDetails);
// save to file for debug
saveResult(file, result, "-addedField");
checkSimpleClass(result);
assertTrue(result.contains("private String newFieldAddedByCode = \"Create by code\";"));
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class UpdateCompilationUnitTest method testSimpleClass3AddField.
@Test
public void testSimpleClass3AddField() throws Exception {
// Set up
final File file = getResource(SIMPLE_CLASS3_FILE_PATH);
final String fileContents = getResourceContents(file);
final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService.getTypeFromString(fileContents, SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS3_TYPE);
final SetField fieldDetails = new SetField(SIMPLE_CLASS3_DECLARED_BY_MID, new JavaType(SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(SIMPLE_CLASS3_TYPE)), new JavaSymbolName("children"), SIMPLE_CLASS3_TYPE, Cardinality.ONE_TO_MANY, new Cascade[] { Cascade.REMOVE }, false);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails.getPhysicalTypeIdentifier(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), fieldDetails.getFieldName(), fieldDetails.getFieldType());
fieldBuilder.setFieldInitializer("new HashSet<SimpleClass3>()");
final ClassOrInterfaceTypeDetails newClassDetails = addField(simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService.getCompilationUnitContents(newClassDetails);
saveResult(file, result, "-addField");
checkSimple3Class(result);
assertTrue(result.contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));
// Add another
final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService.getTypeFromString(result, SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS3_TYPE);
final ReferenceField fieldDetails2 = new ReferenceField(SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS2_TYPE, new JavaSymbolName("referenceField"), Cardinality.MANY_TO_ONE, new Cascade[] { Cascade.REFRESH });
final FieldMetadataBuilder fieldBuilder2 = new FieldMetadataBuilder(fieldDetails2.getPhysicalTypeIdentifier(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), fieldDetails2.getFieldName(), fieldDetails2.getFieldType());
final ClassOrInterfaceTypeDetails newClassDetails2 = addField(simpleInterfaceDetails2, fieldBuilder2.build());
// Invoke
final String result2 = typeParsingService.getCompilationUnitContents(newClassDetails2);
// Save to file for debug
saveResult(file, result2, "-addField2");
checkSimple3Class(result2);
assertTrue(result.contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));
assertTrue(result2.contains("private SimpleClass2 referenceField;"));
}
Aggregations