Examples of DTOClassBuilder


Examples of org.jboss.forge.addon.javaee.rest.generator.dto.DTOClassBuilder

         return dtoCollection.getDTOFor(entity, topLevel);
      }

      Property<?> idProperty = parseIdPropertyForJPAEntity(entity);

      DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel, templateFactory,
               resourceFactory)
               .setPackage(dtoPackage)
               .setEmbeddedType(isEmbeddedType);

      for (Property<?> property : entity.getProperties())
      {
         Field<?> field = property.getField();
         Method<?, ?> accessor = property.getAccessor();
         if (field != null)
         {
            if (field.isTransient() || field.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }
         else
         {
            if (accessor.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }

         String qualifiedPropertyType = property.getType().getQualifiedName();
         // Get the JavaClass for the field's type so that we can inspect it later for annotations and such
         // and recursively generate a DTO for it as well.
         JavaClass<?> propertyClass = tryGetJavaClass(project, qualifiedPropertyType);

         boolean isReadable = property.isAccessible();
         boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
         Type<?> propertyTypeInspector = property.getType();
         boolean parameterized = propertyTypeInspector.isParameterized();
         boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
         boolean isEmbedded = property.hasAnnotation(Embedded.class)
                  || (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));

         if (!isReadable)
         {
            // Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
            continue;
         }

         if (isCollection && parameterized)
         {
            if (!topLevel)
            {
               // Do not expand collections beyond the root
               continue;
            }

            // Create a DTO having the PK-field of the parameterized type of multi-valued collections,
            // if it does not exist
            Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
            String qualifiedParameterizedType = type.getQualifiedName();
            JavaClass<?> parameterizedClass = tryGetJavaClass(project, qualifiedParameterizedType);
            if (parameterizedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " +
               // qualifiedParameterizedType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, parameterizedClass, dtoPackage, false,
                     false, dtoCollection);
            // Then update the DTO for the collection field
            Property<?> nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClass);
            dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
         }
         else if (hasAssociation)
         {
            if (!topLevel)
            {
               // Do not expand associations beyond the root
               continue;
            }

            // Create another DTO having the PK-field of the type of single-valued associations,
            // if it does not exist
            JavaClass<?> associatedClass = tryGetJavaClass(project, qualifiedPropertyType);
            if (associatedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedPropertyType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, associatedClass, dtoPackage, false,
                     false,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, nestedDTOClass);
         }
         else if (isEmbedded)
         {
            // Create another DTO for the @Embedded type, if it does not exist
            JavaClassSource dtoForEmbeddedType = generatedDTOGraphForEntity(project, propertyClass, dtoPackage, true,
                     true,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, dtoForEmbeddedType);
         }
         else
         {
            dtoClassBuilder.updateForSimpleProperty(property, property.getType());
         }
      }

      JavaClassSource dtoClass = dtoClassBuilder.createDTO();
      if (topLevel)
      {
         dtoCollection.addRootDTO(entity, dtoClass);
      }
      else
View Full Code Here

Examples of org.jboss.forge.addon.javaee.rest.generator.dto.DTOClassBuilder

         return dtoCollection.getDTOFor(entity, topLevel);
      }

      Property<?> idProperty = parseIdPropertyForJPAEntity(entity);

      DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel, templateFactory,
               resourceFactory)
               .setPackage(dtoPackage)
               .setEmbeddedType(isEmbeddedType);

      for (Property<?> property : entity.getProperties())
      {
         Field<?> field = property.getField();
         Method<?, ?> accessor = property.getAccessor();
         if (field != null)
         {
            if (field.isTransient() || field.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }
         else
         {
            if (accessor.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }

         String qualifiedPropertyType = property.getType().getQualifiedName();
         // Get the JavaClass for the field's type so that we can inspect it later for annotations and such
         // and recursively generate a DTO for it as well.
         JavaClass<?> propertyClass = tryGetJavaClass(project, qualifiedPropertyType);

         boolean isReadable = property.isAccessible();
         boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
         Type<?> propertyTypeInspector = property.getType();
         boolean parameterized = propertyTypeInspector.isParameterized();
         boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
         boolean isEmbedded = property.hasAnnotation(Embedded.class)
                  || (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));

         if (!isReadable)
         {
            // Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
            continue;
         }

         if (isCollection && parameterized)
         {
            if (!topLevel)
            {
               // Do not expand collections beyond the root
               continue;
            }

            // Create a DTO having the PK-field of the parameterized type of multi-valued collections,
            // if it does not exist
            Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
            String qualifiedParameterizedType = type.getQualifiedName();
            JavaClass<?> parameterizedClass = tryGetJavaClass(project, qualifiedParameterizedType);
            if (parameterizedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " +
               // qualifiedParameterizedType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, parameterizedClass, dtoPackage, false,
                     false, dtoCollection);
            // Then update the DTO for the collection field
            Property<?> nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClass);
            dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
         }
         else if (hasAssociation)
         {
            if (!topLevel)
            {
               // Do not expand associations beyond the root
               continue;
            }

            // Create another DTO having the PK-field of the type of single-valued associations,
            // if it does not exist
            JavaClass<?> associatedClass = tryGetJavaClass(project, qualifiedPropertyType);
            if (associatedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedPropertyType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, associatedClass, dtoPackage, false,
                     false,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, nestedDTOClass);
         }
         else if (isEmbedded)
         {
            // Create another DTO for the @Embedded type, if it does not exist
            JavaClassSource dtoForEmbeddedType = generatedDTOGraphForEntity(project, propertyClass, dtoPackage, true,
                     true,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, dtoForEmbeddedType);
         }
         else
         {
            dtoClassBuilder.updateForSimpleProperty(property, property.getType());
         }
      }

      JavaClassSource dtoClass = dtoClassBuilder.createDTO();
      if (topLevel)
      {
         dtoCollection.addRootDTO(entity, dtoClass);
      }
      else
View Full Code Here

Examples of org.jboss.forge.addon.javaee.rest.generator.dto.DTOClassBuilder

      Property idProperty = null;
      JavaClassIntrospector bean = new JavaClassIntrospector(entity);
      idProperty = parseIdPropertyForJPAEntity(bean);

      DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel, processorFactory,
               resourceFactory)
               .setPackage(dtoPackage)
               .setEmbeddedType(isEmbeddedType);

      for (Property property : bean.getProperties())
      {
         if (property.isTransient() || property.hasAnnotation(Transient.class))
         {
            // No known reason for transient fields to be present in DTOs.
            // Revisit this if necessary for @Transient
            continue;
         }

         String qualifiedPropertyType = property.getQualifiedType();
         // Get the JavaClass for the field's type so that we can inspect it later for annotations and such
         // and recursively generate a DTO for it as well.
         JavaClass propertyClass = tryGetJavaClass(project, qualifiedPropertyType);

         boolean isReadable = property.isReadable();
         boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
         Type<?> propertyTypeInspector = property.getType();
         boolean parameterized = propertyTypeInspector.isParameterized();
         boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
         boolean isEmbedded = property.hasAnnotation(Embedded.class)
                  || (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));

         if (!isReadable)
         {
            // Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
            continue;
         }

         if (isCollection && parameterized)
         {
            if (!topLevel)
            {
               // Do not expand collections beyond the root
               continue;
            }

            // Create a DTO having the PK-field of the parameterized type of multi-valued collections,
            // if it does not exist
            Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
            String qualifiedParameterizedType = type.getQualifiedName();
            JavaClass parameterizedClass = tryGetJavaClass(project, qualifiedParameterizedType);
            if (parameterizedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " +
               // qualifiedParameterizedType
               // + " due to missing source.");
               continue;
            }

            JavaClass nestedDTOClass = generatedDTOGraphForEntity(project, parameterizedClass, dtoPackage, false,
                     false, dtoCollection);
            // Then update the DTO for the collection field
            JavaClassIntrospector parameterizedClassBean = new JavaClassIntrospector(parameterizedClass);
            Property nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClassBean);
            dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
         }
         else if (hasAssociation)
         {
            if (!topLevel)
            {
               // Do not expand associations beyond the root
               continue;
            }

            // Create another DTO having the PK-field of the type of single-valued associations,
            // if it does not exist
            JavaClass associatedClass = tryGetJavaClass(project, qualifiedPropertyType);
            if (associatedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedPropertyType
               // + " due to missing source.");
               continue;
            }

            JavaClass nestedDTOClass = generatedDTOGraphForEntity(project, associatedClass, dtoPackage, false, false,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, nestedDTOClass);
         }
         else if (isEmbedded)
         {
            // Create another DTO for the @Embedded type, if it does not exist
            JavaClass dtoForEmbeddedType = generatedDTOGraphForEntity(project, propertyClass, dtoPackage, true, true,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, dtoForEmbeddedType);
         }
         else
         {
            dtoClassBuilder.updateForSimpleProperty(property, property.getType());
         }
      }

      JavaClass dtoClass = dtoClassBuilder.createDTO();
      if (topLevel)
      {
         dtoCollection.addRootDTO(entity, dtoClass);
      }
      else
View Full Code Here

Examples of org.jboss.forge.addon.javaee.rest.generator.dto.DTOClassBuilder

      Property idProperty = null;
      JavaClassIntrospector bean = new JavaClassIntrospector(entity);
      idProperty = parseIdPropertyForJPAEntity(bean);

      DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel, processorFactory,
               resourceFactory)
               .setPackage(dtoPackage)
               .setEmbeddedType(isEmbeddedType);

      for (Property property : bean.getProperties())
      {
         if (property.isTransient() || property.hasAnnotation(Transient.class))
         {
            // No known reason for transient fields to be present in DTOs.
            // Revisit this if necessary for @Transient
            continue;
         }

         String qualifiedPropertyType = property.getQualifiedType();
         // Get the JavaClass for the field's type so that we can inspect it later for annotations and such
         // and recursively generate a DTO for it as well.
         JavaClass propertyClass = tryGetJavaClass(project, qualifiedPropertyType);

         boolean isReadable = property.isReadable();
         boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
         Type<?> propertyTypeInspector = property.getType();
         boolean parameterized = propertyTypeInspector.isParameterized();
         boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
         boolean isEmbedded = property.hasAnnotation(Embedded.class)
                  || (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));

         if (!isReadable)
         {
            // Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
            continue;
         }

         if (isCollection && parameterized)
         {
            if (!topLevel)
            {
               // Do not expand collections beyond the root
               continue;
            }

            // Create a DTO having the PK-field of the parameterized type of multi-valued collections,
            // if it does not exist
            Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
            String qualifiedParameterizedType = type.getQualifiedName();
            JavaClass parameterizedClass = tryGetJavaClass(project, qualifiedParameterizedType);
            if (parameterizedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " +
               // qualifiedParameterizedType
               // + " due to missing source.");
               continue;
            }

            JavaClass nestedDTOClass = generatedDTOGraphForEntity(project, parameterizedClass, dtoPackage, false,
                     false, dtoCollection);
            // Then update the DTO for the collection field
            JavaClassIntrospector parameterizedClassBean = new JavaClassIntrospector(parameterizedClass);
            Property nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClassBean);
            dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
         }
         else if (hasAssociation)
         {
            if (!topLevel)
            {
               // Do not expand associations beyond the root
               continue;
            }

            // Create another DTO having the PK-field of the type of single-valued associations,
            // if it does not exist
            JavaClass associatedClass = tryGetJavaClass(project, qualifiedPropertyType);
            if (associatedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedPropertyType
               // + " due to missing source.");
               continue;
            }

            JavaClass nestedDTOClass = generatedDTOGraphForEntity(project, associatedClass, dtoPackage, false, false,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, nestedDTOClass);
         }
         else if (isEmbedded)
         {
            // Create another DTO for the @Embedded type, if it does not exist
            JavaClass dtoForEmbeddedType = generatedDTOGraphForEntity(project, propertyClass, dtoPackage, true, true,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, dtoForEmbeddedType);
         }
         else
         {
            dtoClassBuilder.updateForSimpleProperty(property, property.getType());
         }
      }

      JavaClass dtoClass = dtoClassBuilder.createDTO();
      if (topLevel)
      {
         dtoCollection.addRootDTO(entity, dtoClass);
      }
      else
View Full Code Here

Examples of org.jboss.forge.addon.javaee.rest.generator.dto.DTOClassBuilder

         return dtoCollection.getDTOFor(entity, topLevel);
      }

      Property<?> idProperty = parseIdPropertyForJPAEntity(entity);

      DTOClassBuilder dtoClassBuilder = new DTOClassBuilder(entity, idProperty, topLevel, templateFactory,
               resourceFactory)
               .setPackage(dtoPackage)
               .setEmbeddedType(isEmbeddedType);

      for (Property<?> property : entity.getProperties())
      {
         Field<?> field = property.getField();
         Method<?, ?> accessor = property.getAccessor();
         if (field != null)
         {
            if (field.isTransient() || field.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }
         else
         {
            if (accessor.hasAnnotation(Transient.class))
            {
               // No known reason for transient fields to be present in DTOs.
               // Revisit this if necessary for @Transient
               continue;
            }
         }

         String qualifiedPropertyType = property.getType().getQualifiedName();
         // Get the JavaClass for the field's type so that we can inspect it later for annotations and such
         // and recursively generate a DTO for it as well.
         JavaClass<?> propertyClass = tryGetJavaClass(project, qualifiedPropertyType);

         boolean isReadable = property.isAccessible();
         boolean isCollection = property.hasAnnotation(OneToMany.class) || property.hasAnnotation(ManyToMany.class);
         Type<?> propertyTypeInspector = property.getType();
         boolean parameterized = propertyTypeInspector.isParameterized();
         boolean hasAssociation = property.hasAnnotation(OneToOne.class) || property.hasAnnotation(ManyToOne.class);
         boolean isEmbedded = property.hasAnnotation(Embedded.class)
                  || (propertyClass != null && propertyClass.hasAnnotation(Embeddable.class));

         if (!isReadable)
         {
            // Skip the field if it lacks a getter. It is obviously not permitted to be read by other classes
            continue;
         }

         if (isCollection && parameterized)
         {
            if (!topLevel)
            {
               // Do not expand collections beyond the root
               continue;
            }

            // Create a DTO having the PK-field of the parameterized type of multi-valued collections,
            // if it does not exist
            Type<?> type = propertyTypeInspector.getTypeArguments().get(0);
            String qualifiedParameterizedType = type.getQualifiedName();
            JavaClass<?> parameterizedClass = tryGetJavaClass(project, qualifiedParameterizedType);
            if (parameterizedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " +
               // qualifiedParameterizedType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, parameterizedClass, dtoPackage, false,
                     false, dtoCollection);
            // Then update the DTO for the collection field
            Property<?> nestedDtoId = parseIdPropertyForJPAEntity(parameterizedClass);
            dtoClassBuilder.updateForCollectionProperty(property, nestedDTOClass, type, nestedDtoId);
         }
         else if (hasAssociation)
         {
            if (!topLevel)
            {
               // Do not expand associations beyond the root
               continue;
            }

            // Create another DTO having the PK-field of the type of single-valued associations,
            // if it does not exist
            JavaClass<?> associatedClass = tryGetJavaClass(project, qualifiedPropertyType);
            if (associatedClass == null)
            {
               // ShellMessages.warn(writer, "Omitting creation of fields and DTO for type " + qualifiedPropertyType
               // + " due to missing source.");
               continue;
            }

            JavaClassSource nestedDTOClass = generatedDTOGraphForEntity(project, associatedClass, dtoPackage, false,
                     false,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, nestedDTOClass);
         }
         else if (isEmbedded)
         {
            // Create another DTO for the @Embedded type, if it does not exist
            JavaClassSource dtoForEmbeddedType = generatedDTOGraphForEntity(project, propertyClass, dtoPackage, true,
                     true,
                     dtoCollection);
            dtoClassBuilder.updateForReferencedProperty(property, dtoForEmbeddedType);
         }
         else
         {
            dtoClassBuilder.updateForSimpleProperty(property, property.getType());
         }
      }

      JavaClassSource dtoClass = dtoClassBuilder.createDTO();
      if (topLevel)
      {
         dtoCollection.addRootDTO(entity, dtoClass);
      }
      else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.