Search in sources :

Example 71 with JavaType

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;
}
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 72 with JavaType

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

Example 73 with JavaType

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;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails)

Example 74 with JavaType

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\";"));
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) File(java.io.File) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) Test(org.junit.Test)

Example 75 with JavaType

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;"));
}
Also used : JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) SetField(org.springframework.roo.classpath.operations.jsr303.SetField) File(java.io.File) ReferenceField(org.springframework.roo.classpath.operations.jsr303.ReferenceField) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) Test(org.junit.Test)

Aggregations

JavaType (org.springframework.roo.model.JavaType)411 RooJavaType (org.springframework.roo.model.RooJavaType)212 ArrayList (java.util.ArrayList)142 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)133 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)129 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)114 JdkJavaType (org.springframework.roo.model.JdkJavaType)110 SpringJavaType (org.springframework.roo.model.SpringJavaType)101 JpaJavaType (org.springframework.roo.model.JpaJavaType)83 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)78 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)76 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)72 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)70 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)65 LogicalPath (org.springframework.roo.project.LogicalPath)62 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)60 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)59 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)38 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)35 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)30