Search in sources :

Example 41 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class SeiImplMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Getting annotated class details
    ClassOrInterfaceTypeDetails endpoint = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
    AnnotationMetadata seiImplAnnotation = endpoint.getAnnotation(ROO_SEI_IMPL);
    AnnotationAttributeValue<?> seiAttr = seiImplAnnotation.getAttribute(new JavaSymbolName("sei"));
    Validate.notNull(seiAttr, "ERROR: You must provide a valid SEI to be able to generate a Endpoint.");
    // Getting SEI from annotation
    JavaType seiType = (JavaType) seiAttr.getValue();
    // Getting SEI details
    ClassOrInterfaceTypeDetails seiTypeDetails = getTypeLocationService().getTypeDetails(seiType);
    // Getting SEI Metadata
    final String seiMetadataId = SeiMetadata.createIdentifier(seiTypeDetails.getType(), PhysicalTypeIdentifier.getPath(seiTypeDetails.getDeclaredByMetadataId()));
    final SeiMetadata seiMetadata = (SeiMetadata) getMetadataService().get(seiMetadataId);
    // Getting SEI methods from service and save it
    Map<MethodMetadata, MethodMetadata> seiMethods = seiMetadata.getSeiMethods();
    // Registering dependency between SeiMetadata and this one, to be able to
    // update Endpoint if SEI changes
    final String seiMetadataKey = SeiMetadata.createIdentifier(seiTypeDetails);
    registerDependency(seiMetadataKey, metadataIdentificationString);
    return new SeiImplMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, getProjectOperations().getTopLevelPackage(""), endpoint, seiType, seiMetadata.getService(), seiMethods);
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata)

Example 42 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class SeiMetadata method getSEIMethodFromServiceMethod.

/**
 * This method obtains a SEI method from a provided service method.
 *
 * This method caches the generated methods
 *
 * @param serviceMethod defined in a service interface
 *
 * @return MethodMetadataBuilder that contains all the information about the new SEI method.
 */
private MethodMetadata getSEIMethodFromServiceMethod(MethodMetadata serviceMethod) {
    // Check if already exists the method
    if (seiMethodsFromServiceMethods.get(serviceMethod) != null) {
        return seiMethodsFromServiceMethods.get(serviceMethod);
    }
    // If not exists, generate it and cache it.
    // Obtain the necessary elements from service method
    JavaSymbolName methodName = serviceMethod.getMethodName();
    JavaType returnType = serviceMethod.getReturnType();
    List<AnnotatedJavaType> parameterTypes = serviceMethod.getParameterTypes();
    List<JavaSymbolName> parameterNames = serviceMethod.getParameterNames();
    // Obtain parameterList
    // Is necessary to change the method name to prevent errors
    String paramList = "";
    for (AnnotatedJavaType param : parameterTypes) {
        paramList = paramList.concat(StringUtils.capitalize(param.getJavaType().getSimpleTypeName())).concat("And");
    }
    if (StringUtils.isNotBlank(paramList)) {
        // Before to update, check if is a finder
        if (methodName.toString().startsWith("findBy")) {
            methodName = new JavaSymbolName("find");
        } else if (methodName.toString().startsWith("countBy")) {
            methodName = new JavaSymbolName("count");
        }
        paramList = paramList.substring(0, paramList.length() - "And".length());
        methodName = new JavaSymbolName(methodName.toString().concat("By").concat(paramList));
    }
    // Annotate parameter types with @WebParam and @XmlJavaTypeAdapter if needed
    List<AnnotatedJavaType> annotatedParameterTypes = new ArrayList<AnnotatedJavaType>();
    for (int i = 0; i < parameterTypes.size(); i++) {
        List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
        // Getting parameter type and parameter name
        AnnotatedJavaType paramType = parameterTypes.get(i);
        JavaSymbolName paramName = parameterNames.get(i);
        // Creating @WebParam annotation
        AnnotationMetadataBuilder webParamAnnotation = new AnnotationMetadataBuilder(JavaType.WEB_PARAM);
        webParamAnnotation.addStringAttribute("name", paramName.toString());
        webParamAnnotation.addStringAttribute("targetNamespace", "");
        annotations.add(webParamAnnotation.build());
        // Creating @XmlJavaTypeAdapter annotation
        AnnotationMetadataBuilder javaTypeAdapter = new AnnotationMetadataBuilder(JavaType.XML_JAVATYPE_ADAPTER);
        if (paramType.getJavaType().getFullyQualifiedTypeName().equals(JavaType.ITERABLE.getFullyQualifiedTypeName())) {
            javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_ITERABLE_ADAPTER);
            annotations.add(javaTypeAdapter.build());
        } else if (paramType.getJavaType().getFullyQualifiedTypeName().equals(SpringJavaType.PAGE.getFullyQualifiedTypeName())) {
            javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_PAGE_ADAPTER);
            annotations.add(javaTypeAdapter.build());
        } else if (paramType.getJavaType().equals(SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH)) {
            javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH_ADAPTER);
            annotations.add(javaTypeAdapter.build());
        } else if (paramType.getJavaType().equals(SpringJavaType.PAGEABLE)) {
            javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_PAGEABLE_ADAPTER);
            annotations.add(javaTypeAdapter.build());
        }
        // Creating new parameter type annotated with @WebParam
        AnnotatedJavaType annotatedParam = new AnnotatedJavaType(paramType.getJavaType(), annotations);
        annotatedParameterTypes.add(annotatedParam);
    }
    MethodMetadataBuilder seiMethod = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, returnType, annotatedParameterTypes, parameterNames, null);
    // Include @XmlJavaTypeAdapter annotation if needed
    AnnotationMetadataBuilder javaTypeAdapter = new AnnotationMetadataBuilder(JavaType.XML_JAVATYPE_ADAPTER);
    if (returnType.getFullyQualifiedTypeName().equals(JavaType.ITERABLE.getFullyQualifiedTypeName())) {
        javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_ITERABLE_ADAPTER);
        seiMethod.addAnnotation(javaTypeAdapter);
    } else if (returnType.getFullyQualifiedTypeName().equals(SpringJavaType.PAGE.getFullyQualifiedTypeName())) {
        javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_PAGE_ADAPTER);
        seiMethod.addAnnotation(javaTypeAdapter);
    } else if (returnType.equals(SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH)) {
        javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_GLOBAL_SEARCH_ADAPTER);
        seiMethod.addAnnotation(javaTypeAdapter);
    } else if (returnType.equals(SpringJavaType.PAGEABLE)) {
        javaTypeAdapter.addClassAttribute("value", SpringletsJavaType.SPRINGLETS_PAGEABLE_ADAPTER);
        seiMethod.addAnnotation(javaTypeAdapter);
    }
    // Include @RequestWrapper annotation
    AnnotationMetadataBuilder requestWrapperAnnotation = new AnnotationMetadataBuilder(JavaType.REQUEST_WRAPPER);
    requestWrapperAnnotation.addStringAttribute("className", String.format("%s.%sRequest", sei.getType().getPackage(), seiMethod.getMethodName().getSymbolNameCapitalisedFirstLetter()));
    requestWrapperAnnotation.addStringAttribute("localName", String.format("%sRequest", seiMethod.getMethodName().getSymbolNameCapitalisedFirstLetter()));
    requestWrapperAnnotation.addStringAttribute("targetNamespace", String.format("http://ws.%s/", StringUtils.reverseDelimited(projectTopLevelPackage.getFullyQualifiedPackageName(), '.')));
    seiMethod.addAnnotation(requestWrapperAnnotation);
    // Include @ResponseWrapper annotation
    AnnotationMetadataBuilder responseWrapperAnnotation = new AnnotationMetadataBuilder(JavaType.RESPONSE_WRAPPER);
    responseWrapperAnnotation.addStringAttribute("className", String.format("%s.%sResponse", sei.getType().getPackage(), seiMethod.getMethodName().getSymbolNameCapitalisedFirstLetter()));
    responseWrapperAnnotation.addStringAttribute("localName", String.format("%sResponse", seiMethod.getMethodName().getSymbolNameCapitalisedFirstLetter()));
    responseWrapperAnnotation.addStringAttribute("targetNamespace", String.format("http://ws.%s/", StringUtils.reverseDelimited(projectTopLevelPackage.getFullyQualifiedPackageName(), '.')));
    seiMethod.addAnnotation(responseWrapperAnnotation);
    // Include @WebMethod annotation
    AnnotationMetadataBuilder webMethodAnnotation = new AnnotationMetadataBuilder(JavaType.WEB_METHOD);
    webMethodAnnotation.addStringAttribute("action", String.format("urn:%s", seiMethod.getMethodName().getSymbolNameCapitalisedFirstLetter()));
    seiMethod.addAnnotation(webMethodAnnotation);
    // Include @WebResult annotation
    AnnotationMetadataBuilder webResultAnnotation = new AnnotationMetadataBuilder(JavaType.WEB_RESULT);
    webResultAnnotation.addStringAttribute("name", returnType.getBaseType().getSimpleTypeName().toLowerCase());
    webResultAnnotation.addStringAttribute("targetNamespace", "");
    seiMethod.addAnnotation(webResultAnnotation);
    // Include @WSDLDocumentationCollection annotation
    AnnotationMetadataBuilder wsdlDocumentationCollectionAnnotation = new AnnotationMetadataBuilder(new JavaType("org.apache.cxf.annotations.WSDLDocumentationCollection"));
    // Create @WSDLDocumentation annotation
    List<AnnotationAttributeValue<?>> documentations = new ArrayList<AnnotationAttributeValue<?>>();
    AnnotationMetadataBuilder documentationAnnotation1 = new AnnotationMetadataBuilder(wsdlDocumentationType);
    documentationAnnotation1.addStringAttribute("value", String.format("TODO Auto-generated documentation for %s", sei.getType().getSimpleTypeName()));
    documentationAnnotation1.addEnumAttribute("placement", wsdlDocumentationType, new JavaSymbolName("Placement.DEFAULT"));
    NestedAnnotationAttributeValue newDocumentation1 = new NestedAnnotationAttributeValue(new JavaSymbolName("value"), documentationAnnotation1.build());
    documentations.add(newDocumentation1);
    AnnotationMetadataBuilder documentationAnnotation2 = new AnnotationMetadataBuilder(wsdlDocumentationType);
    documentationAnnotation2.addStringAttribute("value", String.format("TODO Auto-generated documentation for %s", sei.getType().getSimpleTypeName()));
    documentationAnnotation2.addEnumAttribute("placement", wsdlDocumentationType, new JavaSymbolName("Placement.PORT_TYPE_OPERATION_OUTPUT"));
    NestedAnnotationAttributeValue newDocumentation2 = new NestedAnnotationAttributeValue(new JavaSymbolName("value"), documentationAnnotation2.build());
    documentations.add(newDocumentation2);
    ArrayAttributeValue<AnnotationAttributeValue<?>> newDocumentations = new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("value"), documentations);
    wsdlDocumentationCollectionAnnotation.addAttribute(newDocumentations);
    seiMethod.addAnnotation(wsdlDocumentationCollectionAnnotation);
    seiMethodsFromServiceMethods.put(serviceMethod, seiMethod.build());
    seiMethods.put(seiMethod.build(), serviceMethod);
    return seiMethod.build();
}
Also used : ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JavaType(org.springframework.roo.model.JavaType) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)

Example 43 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class JavaParserUtils method getJavaType.

/**
 * Resolves the effective {@link JavaType} a
 * {@link ClassOrInterfaceDeclaration} represents, including any type
 * parameters.
 *
 * @param compilationUnitServices for package management (required)
 * @param typeDeclaration the type declaration to resolve (required)
 * @return the effective Java type (never null)
 */
public static JavaType getJavaType(final CompilationUnitServices compilationUnitServices, final TypeDeclaration typeDeclaration) {
    Validate.notNull(compilationUnitServices, "Compilation unit services required");
    Validate.notNull(typeDeclaration, "Type declaration required");
    // Convert the ClassOrInterfaceDeclaration name into a JavaType
    final NameExpr nameExpr = getNameExpr(typeDeclaration.getName());
    final JavaType effectiveType = getJavaType(compilationUnitServices, nameExpr, null);
    final List<JavaType> parameterTypes = new ArrayList<JavaType>();
    if (typeDeclaration instanceof ClassOrInterfaceDeclaration) {
        final ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) typeDeclaration;
        // Populate JavaType with type parameters
        final List<TypeParameter> typeParameters = clazz.getTypeParameters();
        if (typeParameters != null) {
            final Set<JavaSymbolName> locatedTypeParameters = new HashSet<JavaSymbolName>();
            for (final TypeParameter candidate : typeParameters) {
                final JavaSymbolName currentTypeParam = new JavaSymbolName(candidate.getName());
                locatedTypeParameters.add(currentTypeParam);
                JavaType javaType = null;
                if (candidate.getTypeBound() == null) {
                    javaType = new JavaType(OBJECT.getFullyQualifiedTypeName(), 0, DataType.TYPE, currentTypeParam, null);
                } else {
                    final ClassOrInterfaceType cit = candidate.getTypeBound().get(0);
                    javaType = JavaParserUtils.getJavaTypeNow(compilationUnitServices, cit, locatedTypeParameters);
                    javaType = new JavaType(javaType.getFullyQualifiedTypeName(), javaType.getArray(), javaType.getDataType(), currentTypeParam, javaType.getParameters());
                }
                parameterTypes.add(javaType);
            }
        }
    }
    return new JavaType(effectiveType.getFullyQualifiedTypeName(), effectiveType.getArray(), effectiveType.getDataType(), null, parameterTypes);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) TypeParameter(com.github.antlrjavaparser.api.TypeParameter) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceDeclaration(com.github.antlrjavaparser.api.body.ClassOrInterfaceDeclaration) NameExpr(com.github.antlrjavaparser.api.expr.NameExpr) QualifiedNameExpr(com.github.antlrjavaparser.api.expr.QualifiedNameExpr) ArrayList(java.util.ArrayList) ClassOrInterfaceType(com.github.antlrjavaparser.api.type.ClassOrInterfaceType) HashSet(java.util.HashSet)

Example 44 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class WsOperationsImpl method getWsClientAnnotation.

/**
 * This method provides @RooWsClient annotation with all the necessary attributes
 *
 * @param endpoint
 * @param targetNamespace
 * @param bindingType
 * @return
 */
private AnnotationMetadataBuilder getWsClientAnnotation(final String endpoint, final String targetNamespace, final EnumDetails bindingType) {
    final List<AnnotationAttributeValue<?>> wsClientAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    wsClientAttributes.add(new StringAttributeValue(new JavaSymbolName("endpoint"), endpoint));
    wsClientAttributes.add(new StringAttributeValue(new JavaSymbolName("targetNamespace"), targetNamespace));
    wsClientAttributes.add(new EnumAttributeValue(new JavaSymbolName("binding"), bindingType));
    return new AnnotationMetadataBuilder(RooJavaType.ROO_WS_CLIENT, wsClientAttributes);
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 45 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class WsOperationsImpl method addSEI.

@Override
public void addSEI(JavaType service, JavaType sei, JavaType endpointClass, JavaType configClass, String profile, boolean force) {
    Validate.notNull(service, "ERROR: Provide a valid service");
    Validate.notNull(sei, "ERROR: Provide a valid sei");
    // Check if provided service exists
    ClassOrInterfaceTypeDetails serviceTypeDetails = getTypeLocationService().getTypeDetails(service);
    Validate.notNull(serviceTypeDetails, "ERROR: Provide an existing service");
    // Check if provided service is annotated with @RooService
    AnnotationMetadata serviceAnnotation = serviceTypeDetails.getAnnotation(RooJavaType.ROO_SERVICE);
    Validate.notNull(serviceAnnotation, "ERROR: Provide a valid service annotated with @RooService");
    // Check if provided service has a related entity
    AnnotationAttributeValue<JavaType> entityAttr = serviceAnnotation.getAttribute("entity");
    Validate.notNull(entityAttr, "ERROR: The provided service is annotated with @RooService but doesn't " + "contains the 'entity' attribute");
    JavaType relatedEntity = entityAttr.getValue();
    Validate.notNull(relatedEntity, "ERROR: The provided service is annotated with @RooService but doesn't " + "contains a valid entity in the 'entity' attribute");
    // Check if provided SEI is located in an application module
    if (!isLocatedInApplicationModule(sei) && !force) {
        LOGGER.log(Level.INFO, "ERROR: The provided SEI is not located in an application module.");
        return;
    }
    // Check if the configClass is located in an application module
    if (configClass != null && !isLocatedInApplicationModule(configClass) && !force) {
        LOGGER.log(Level.INFO, "ERROR: The provided config class is not located in an application module.");
        return;
    }
    // new one inside the provided SEI module using the provided SEI name and 'Endpoint' suffix.
    if (endpointClass == null) {
        endpointClass = new JavaType(String.format("%sEndpoint", sei.getFullyQualifiedTypeName()), sei.getModule());
    }
    // new one inside the provided SEI module using the provided SEI name and 'Configuration' suffix
    if (configClass == null) {
        configClass = new JavaType(String.format("%sConfiguration", sei.getFullyQualifiedTypeName()), sei.getModule());
    }
    // Check if provided configClass exists or should be generated
    boolean isNewConfigClass = false;
    ClassOrInterfaceTypeDetails configClassDetails = getTypeLocationService().getTypeDetails(configClass);
    if (configClassDetails == null) {
        isNewConfigClass = true;
    }
    // If it have it, it should match with the provided one the provided one
    if (!isNewConfigClass) {
        MemberDetails configClassMemberDetails = getMemberDetailsScanner().getMemberDetails(getClass().getName(), configClassDetails);
        AnnotationMetadata configurationAnnotation = configClassMemberDetails.getAnnotation(SpringJavaType.CONFIGURATION);
        if (configurationAnnotation == null) {
            LOGGER.log(Level.INFO, "ERROR: The provided class is not annotated with @Configuration so is not possible to include Web Service client configuration on it." + "Specify other configuration class that contains @Configuration annotation or specify a not existing class to generate it.");
            return;
        }
        if (StringUtils.isNotEmpty(profile)) {
            AnnotationMetadata profileAnnotation = configClassMemberDetails.getAnnotation(SpringJavaType.PROFILE);
            if (profileAnnotation != null) {
                String profiles = (String) profileAnnotation.getAttribute("value").getValue();
                String[] definedProfiles = profiles.split(",");
                boolean profileExists = false;
                for (String definedProfile : definedProfiles) {
                    if (definedProfile.equals(profile)) {
                        profileExists = true;
                    }
                }
                if (!profileExists) {
                    LOGGER.log(Level.INFO, "ERROR: The provided configuration class doesn't work in the provided profile. " + "Use a different configuration class or use a different profile.");
                    return;
                }
            }
        }
    }
    // Check if some the provided classes that should be generated already exists
    if (getTypeLocationService().getTypeDetails(sei) != null) {
        LOGGER.log(Level.INFO, "ERROR: The provided SEI already exists. Specify a different one using" + " --sei parameter.");
        return;
    }
    if (getTypeLocationService().getTypeDetails(endpointClass) != null) {
        LOGGER.log(Level.INFO, "ERROR: The provided Endpoint class already exists. Specify a different one using" + " --class parameter.");
        return;
    }
    // Include necessary dependencies
    includeDependenciesAndPluginsForSei(sei.getModule());
    // Include the necessary properties using the provided profile
    getApplicationConfigService().addProperty(sei.getModule(), "cxf.path", "/services", profile, true);
    getApplicationConfigService().addProperty(sei.getModule(), "cxf.servlet.load-on-startup", "-1", profile, true);
    // Generate the new SEI
    final String seiIdentifier = getPathResolver().getCanonicalPath(sei.getModule(), Path.SRC_MAIN_JAVA, sei);
    final String midSEI = PhysicalTypeIdentifier.createIdentifier(sei, getPathResolver().getPath(seiIdentifier));
    ClassOrInterfaceTypeDetailsBuilder cidBuilderSEI = new ClassOrInterfaceTypeDetailsBuilder(midSEI, Modifier.PUBLIC, sei, PhysicalTypeCategory.INTERFACE);
    // Create new @RooWsEndpoint annotation
    AnnotationMetadataBuilder seiAnnotation = new AnnotationMetadataBuilder(new JavaType(RooSei.class));
    // Including service parameter to @RooSei annotation
    seiAnnotation.addClassAttribute("service", service);
    // Include new @RooSei annotation
    cidBuilderSEI.addAnnotation(seiAnnotation);
    // Write SEI class on disk
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderSEI.build());
    // Generate the new Endpoint
    final String endpointIdentifier = getPathResolver().getCanonicalPath(endpointClass.getModule(), Path.SRC_MAIN_JAVA, endpointClass);
    final String midEndpoint = PhysicalTypeIdentifier.createIdentifier(endpointClass, getPathResolver().getPath(endpointIdentifier));
    ClassOrInterfaceTypeDetailsBuilder cidBuilderEndpoint = new ClassOrInterfaceTypeDetailsBuilder(midEndpoint, Modifier.PUBLIC, endpointClass, PhysicalTypeCategory.CLASS);
    // Create new @RooSeiImpl annotation
    AnnotationMetadataBuilder endpointAnnotation = new AnnotationMetadataBuilder(new JavaType(RooSeiImpl.class));
    // Include sei parameter to @RooSeiImpl annotation
    endpointAnnotation.addClassAttribute("sei", sei);
    // Include new @RooSeiImpl annotation
    cidBuilderEndpoint.addAnnotation(endpointAnnotation);
    // Include implements
    cidBuilderEndpoint.addImplementsType(sei);
    // Write endpoint class on disk
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderEndpoint.build());
    // If configuration class exists, check if is already annotated and update it.
    // If not exists, create a new one
    ClassOrInterfaceTypeDetailsBuilder cidBuilderConfig = null;
    if (!isNewConfigClass) {
        // Obtain builder from the existing class
        cidBuilderConfig = new ClassOrInterfaceTypeDetailsBuilder(configClassDetails);
        // Check if already have @RooWsEndpoints annotation
        AnnotationMetadataBuilder wsEndpointsAnnotation = cidBuilderConfig.getDeclaredTypeAnnotation(RooJavaType.ROO_WS_ENDPOINTS);
        if (wsEndpointsAnnotation != null) {
            // Update the existing one
            AnnotationAttributeValue<?> existingEndPoints = wsEndpointsAnnotation.build().getAttribute("endpoints");
            List<?> values = (List<?>) existingEndPoints.getValue();
            if (values != null) {
                // Check if the provided endpoint exists yet in this config class
                Iterator<?> it = values.iterator();
                boolean alreadyManaged = false;
                while (it.hasNext()) {
                    ClassAttributeValue existingEndPointAttr = (ClassAttributeValue) it.next();
                    JavaType existingEndPoint = existingEndPointAttr.getValue();
                    if (existingEndPoint.getFullyQualifiedTypeName().equals(endpointClass.getFullyQualifiedTypeName())) {
                        alreadyManaged = true;
                    }
                }
                // If endpoint already exists, show an error indicating that this endpoint is already managed
                if (alreadyManaged) {
                    LOGGER.log(Level.INFO, "ERROR: The provided endpoint is already defined in the provided configuration class. " + "Specify some different configuration class.");
                    return;
                } else {
                    // Update existing annotation with the new endPoint
                    Iterator<?> iterator = values.iterator();
                    List<AnnotationAttributeValue<?>> endpoints = new ArrayList<AnnotationAttributeValue<?>>();
                    while (iterator.hasNext()) {
                        ClassAttributeValue existingEndPoint = (ClassAttributeValue) iterator.next();
                        endpoints.add(existingEndPoint);
                    }
                    // Create @RooWsEndpoints annotation
                    ClassAttributeValue newEndpoint = new ClassAttributeValue(new JavaSymbolName("value"), endpointClass);
                    endpoints.add(newEndpoint);
                    ArrayAttributeValue<AnnotationAttributeValue<?>> newEndpoints = new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("endpoints"), endpoints);
                    wsEndpointsAnnotation.addAttribute(newEndpoints);
                }
            }
        } else {
            // If not exists, add it with the new elements
            wsEndpointsAnnotation = new AnnotationMetadataBuilder(new JavaType(RooWsEndpoints.class));
            // Generate new list of endpoints
            List<AnnotationAttributeValue<?>> endpoints = new ArrayList<AnnotationAttributeValue<?>>();
            ClassAttributeValue newEndpoint = new ClassAttributeValue(new JavaSymbolName("value"), endpointClass);
            endpoints.add(newEndpoint);
            ArrayAttributeValue<AnnotationAttributeValue<?>> newEndpoints = new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("endpoints"), endpoints);
            wsEndpointsAnnotation.addAttribute(newEndpoints);
            // Check if is necessary to include profile attribute
            if (StringUtils.isNotEmpty(profile)) {
                wsEndpointsAnnotation.addStringAttribute("profile", profile);
            }
            // Include new @RooWsEndpoints annotation
            cidBuilderConfig.addAnnotation(wsEndpointsAnnotation);
        }
    } else {
        // Create the specified configuration class and annotate it with necessary information
        final String configClassIdentifier = getPathResolver().getCanonicalPath(configClass.getModule(), Path.SRC_MAIN_JAVA, configClass);
        final String mid = PhysicalTypeIdentifier.createIdentifier(configClass, getPathResolver().getPath(configClassIdentifier));
        cidBuilderConfig = new ClassOrInterfaceTypeDetailsBuilder(mid, Modifier.PUBLIC, configClass, PhysicalTypeCategory.CLASS);
        // Create new @RooWsEndpoints annotation and include the new endpoint
        // as endpoints attribute
        List<AnnotationAttributeValue<?>> endpoints = new ArrayList<AnnotationAttributeValue<?>>();
        ClassAttributeValue endPointAttributeValue = new ClassAttributeValue(new JavaSymbolName("value"), endpointClass);
        endpoints.add(endPointAttributeValue);
        ArrayAttributeValue<AnnotationAttributeValue<?>> newEndpoints = new ArrayAttributeValue<AnnotationAttributeValue<?>>(new JavaSymbolName("endpoints"), endpoints);
        AnnotationMetadataBuilder wsEndpointsAnnotation = new AnnotationMetadataBuilder(new JavaType(RooWsEndpoints.class));
        wsEndpointsAnnotation.addAttribute(newEndpoints);
        // Include new @RooWsEndpoints annotation
        cidBuilderConfig.addAnnotation(wsEndpointsAnnotation);
        // doesn't exists yet, because we're generating a new @Configuration class
        if (StringUtils.isNotEmpty(profile)) {
            wsEndpointsAnnotation.addStringAttribute("profile", profile);
        }
    }
    // Write config class on disk
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderConfig.build());
    // After create the SEI and the Endpoint, is necessary to annotate related entity with
    // some JAX-B annotations if has not been annotated before
    /*ClassOrInterfaceTypeDetails entityDetails =
        getTypeLocationService().getTypeDetails(relatedEntity);
    if (entityDetails != null) {
      // Annotate the entity with @RooJaxbEntity. If this entity has a super class or that 
      // super class has another super class, etc. is necessary to annotate it too.
      annotateClassIfNeeded(entityDetails);
      // Also, is necessary to annotate @OneToMany, @ManyToOne and @ManyToMany fields detected in 
      // this class and in the super classes.
      annotateRelatedFieldsIfNeeded(entityDetails);
    }*/
    // Provisional changes to annotate all entities
    Set<ClassOrInterfaceTypeDetails> allEntities = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY);
    for (ClassOrInterfaceTypeDetails entity : allEntities) {
        // Annotate the entity with @RooJaxbEntity. If this entity has a super class or that
        // super class has another super class, etc. is necessary to annotate it too.
        annotateClassIfNeeded(entity);
        // Also, is necessary to annotate @OneToMany, @ManyToOne and @ManyToMany fields detected in
        // this class and in the super classes.
        annotateRelatedFieldsIfNeeded(entity);
    }
}
Also used : ClassAttributeValue(org.springframework.roo.classpath.details.annotations.ClassAttributeValue) ArrayList(java.util.ArrayList) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) RooWsEndpoints(org.springframework.roo.addon.ws.annotations.RooWsEndpoints) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayAttributeValue(org.springframework.roo.classpath.details.annotations.ArrayAttributeValue) AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) RooSei(org.springframework.roo.addon.ws.annotations.RooSei) RooSeiImpl(org.springframework.roo.addon.ws.annotations.RooSeiImpl) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) 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