Search in sources :

Example 6 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue 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 7 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue 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)

Example 8 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue in project spring-roo by spring-projects.

the class JspOperationsImpl method createManualController.

/**
 * Creates a new Spring MVC controller.
 * <p>
 * Request mappings assigned by this method will always commence with "/"
 * and end with "/**". You may present this prefix and/or this suffix if you
 * wish, although it will automatically be added should it not be provided.
 *
 * @param controller the controller class to create (required)
 * @param preferredMapping the mapping this controller should adopt
 *            (optional; if unspecified it will be based on the controller
 *            name)
 */
public void createManualController(final JavaType controller, final String preferredMapping, final LogicalPath webappPath) {
    Validate.notNull(controller, "Controller Java Type required");
    // Create annotation @RequestMapping("/myobject/**")
    final ImmutablePair<String, String> folderAndMapping = getFolderAndMapping(preferredMapping, controller);
    final String folderName = folderAndMapping.getKey();
    final String resourceIdentifier = getPathResolver().getFocusedCanonicalPath(Path.SRC_MAIN_JAVA, controller);
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(controller, getProjectOperations().getPathResolver().getPath(resourceIdentifier));
    final List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
    // Add HTTP post method
    methods.add(getHttpPostMethod(declaredByMetadataId));
    // Add index method
    methods.add(getIndexMethod(folderName, declaredByMetadataId));
    // Create Type definition
    final List<AnnotationMetadataBuilder> typeAnnotations = new ArrayList<AnnotationMetadataBuilder>();
    final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    requestMappingAttributes.add(new StringAttributeValue(new JavaSymbolName("value"), folderAndMapping.getValue()));
    final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(REQUEST_MAPPING, requestMappingAttributes);
    typeAnnotations.add(requestMapping);
    // Create annotation @Controller
    final List<AnnotationAttributeValue<?>> controllerAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    final AnnotationMetadataBuilder controllerAnnotation = new AnnotationMetadataBuilder(CONTROLLER, controllerAttributes);
    typeAnnotations.add(controllerAnnotation);
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, controller, PhysicalTypeCategory.CLASS);
    cidBuilder.setAnnotations(typeAnnotations);
    cidBuilder.setDeclaredMethods(methods);
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
    installView(folderName, "/index", new JavaSymbolName(controller.getSimpleTypeName()).getReadableSymbolName() + " View", "Controller", null, false, webappPath);
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 9 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue in project spring-roo by spring-projects.

the class ControllerOperationsImpl method getRooControllerAnnotation.

/**
 * Method that returns @RooController annotation
 *
 * @param entity
 *            Entity over which create the controller
 * @param pathPrefix
 *            Prefix to use in RequestMapping
 * @param controllerType
 *            Indicates the controller type
 * @return
 */
private AnnotationMetadataBuilder getRooControllerAnnotation(final JavaType entity, final String pathPrefix, final ControllerType controllerType) {
    final List<AnnotationAttributeValue<?>> rooControllerAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    rooControllerAttributes.add(new ClassAttributeValue(new JavaSymbolName("entity"), entity));
    if (StringUtils.isNotEmpty(pathPrefix)) {
        rooControllerAttributes.add(new StringAttributeValue(new JavaSymbolName("pathPrefix"), pathPrefix));
    }
    rooControllerAttributes.add(new EnumAttributeValue(new JavaSymbolName("type"), new EnumDetails(RooJavaType.ROO_ENUM_CONTROLLER_TYPE, new JavaSymbolName(controllerType.name()))));
    return new AnnotationMetadataBuilder(RooJavaType.ROO_CONTROLLER, rooControllerAttributes);
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassAttributeValue(org.springframework.roo.classpath.details.annotations.ClassAttributeValue) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 10 with AnnotationAttributeValue

use of org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue in project spring-roo by spring-projects.

the class DbreMetadata method getManyToManyOwningSideField.

private FieldMetadataBuilder getManyToManyOwningSideField(final JavaSymbolName fieldName, final Table joinTable, final Table inverseSideTable, final CascadeAction onUpdate, final CascadeAction onDelete) {
    final JavaType element = DbreTypeUtils.findTypeForTable(managedEntities, inverseSideTable);
    Validate.notNull(element, "Attempted to create many-to-many owning-side field '%s' in '%s' %s", fieldName, destination.getFullyQualifiedTypeName(), getErrorMsg(inverseSideTable.getFullyQualifiedTableName()));
    final List<JavaType> params = Arrays.asList(element);
    final JavaType fieldType = new JavaType(SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, params);
    // Add annotations to field
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Add @ManyToMany annotation
    final AnnotationMetadataBuilder manyToManyBuilder = new AnnotationMetadataBuilder(MANY_TO_MANY);
    annotations.add(manyToManyBuilder);
    // Add @JoinTable annotation
    final AnnotationMetadataBuilder joinTableBuilder = new AnnotationMetadataBuilder(JOIN_TABLE);
    final List<AnnotationAttributeValue<?>> joinTableAnnotationAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    joinTableAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName(NAME), joinTable.getName()));
    final Iterator<ForeignKey> iter = joinTable.getImportedKeys().iterator();
    // Add "joinColumns" attribute containing nested @JoinColumn annotations
    final List<NestedAnnotationAttributeValue> joinColumnArrayValues = new ArrayList<NestedAnnotationAttributeValue>();
    final Set<Reference> firstKeyReferences = iter.next().getReferences();
    for (final Reference reference : firstKeyReferences) {
        final AnnotationMetadataBuilder joinColumnBuilder = getJoinColumnAnnotation(reference, firstKeyReferences.size() > 1);
        joinColumnArrayValues.add(new NestedAnnotationAttributeValue(new JavaSymbolName(VALUE), joinColumnBuilder.build()));
    }
    joinTableAnnotationAttributes.add(new ArrayAttributeValue<NestedAnnotationAttributeValue>(new JavaSymbolName("joinColumns"), joinColumnArrayValues));
    // Add "inverseJoinColumns" attribute containing nested @JoinColumn
    // annotations
    final List<NestedAnnotationAttributeValue> inverseJoinColumnArrayValues = new ArrayList<NestedAnnotationAttributeValue>();
    final Set<Reference> lastKeyReferences = iter.next().getReferences();
    for (final Reference reference : lastKeyReferences) {
        final AnnotationMetadataBuilder joinColumnBuilder = getJoinColumnAnnotation(reference, lastKeyReferences.size() > 1);
        inverseJoinColumnArrayValues.add(new NestedAnnotationAttributeValue(new JavaSymbolName(VALUE), joinColumnBuilder.build()));
    }
    joinTableAnnotationAttributes.add(new ArrayAttributeValue<NestedAnnotationAttributeValue>(new JavaSymbolName("inverseJoinColumns"), inverseJoinColumnArrayValues));
    // Add attributes to a @JoinTable annotation builder
    joinTableBuilder.setAttributes(joinTableAnnotationAttributes);
    annotations.add(joinTableBuilder);
    return new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations, fieldName, fieldType);
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) Reference(org.springframework.roo.addon.dbre.addon.model.Reference) ArrayList(java.util.ArrayList) ForeignKey(org.springframework.roo.addon.dbre.addon.model.ForeignKey) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)

Aggregations

AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)41 ArrayList (java.util.ArrayList)36 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)36 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)31 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)23 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)22 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)17 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)16 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)13 JavaType (org.springframework.roo.model.JavaType)13 List (java.util.List)12 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)11 EnumDetails (org.springframework.roo.model.EnumDetails)11 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)8 IntegerAttributeValue (org.springframework.roo.classpath.details.annotations.IntegerAttributeValue)7 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)6 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)4 LongAttributeValue (org.springframework.roo.classpath.details.annotations.LongAttributeValue)4 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)4